Google-Maps Android:绘制复杂 GeoJson 多边形的问题

发布于 2025-01-09 19:41:09 字数 1695 浏览 1 评论 0原文

我有一个返回 GeoJson 多边形(时区)的网络服务,我正在尝试使用 GeoJsonLayer 在地图对象上的图层中绘制它们

我已经在 geojson.io 它看起来不错(底部的图像),但是当我将它添加到地图时,它没有被填充,并且一些额外的行出现在下面南,看起来它没有正确关闭多边形,这是我用来加载文件的代码(我目前在本地原始文件夹中)

    val layer = GeoJsonLayer(mGoogleMap, R.raw.sample_timezones_response, requireContext())
    layer.addLayerToMap()

    val polygonStyle = GeoJsonPolygonStyle()
    polygonStyle.fillColor = resources.getColor(R.color.color_main_green_200, null)
    polygonStyle.zIndex = 10000f
    layer.features.forEach { it1 ->
        it1.polygonStyle = polygonStyle
    }

这是我正在尝试使用的 json 文件。

编辑:原始的json文件不遵循右手规则,我用python lib修复了它:geojson-rewind, 这个是通过https://geojsonlint.com/

我也尝试更新到该库的最新版本(18.0.2) 并将渲染器更新为较新的渲染器,但显示方式相同。

这是它在 Android 上的样子: android 屏幕截图有缺陷

带有缺陷的 android 屏幕截图 2

这就是它的外观,geojson.io 中的相同 json 文件: 正确显示在 geojson.io

I have a webservice that returns GeoJson polygons (timezones) and I'm trying to draw them in a layer over the map object using GeoJsonLayer

I already tested the GeoJson file in geojson.io and it looks fine (image at the bottom) but when I add it to the map its not being filled and some extra lines appear down south, it looks like its not closing the poly properly, this is the code I'm using to load the file (I have it locally in raw folder at the moment)

    val layer = GeoJsonLayer(mGoogleMap, R.raw.sample_timezones_response, requireContext())
    layer.addLayerToMap()

    val polygonStyle = GeoJsonPolygonStyle()
    polygonStyle.fillColor = resources.getColor(R.color.color_main_green_200, null)
    polygonStyle.zIndex = 10000f
    layer.features.forEach { it1 ->
        it1.polygonStyle = polygonStyle
    }

This is the json file I'm trying with.

EDIT: the original json file was not followinf the right-hand rule, I fixed it with python lib: geojson-rewind, this is the fixed version that passes the test in https://geojsonlint.com/

I tried also updating to the latest version of the library (18.0.2) and updating the renderer to the newer one but it displays in the same way.

This is how it looks on android:
android screenshot with defects

android screenshot with defects 2

This is how its supose to look, same json file in geojson.io:
displaying propertly on geojson.io

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

多情癖 2025-01-16 19:41:09

验证 geojson 时,出现错误:

第 1 行:多边形和多重多边形应遵循右手定则

https:/ /www.rfc-editor.org/rfc/rfc7946#section-3.1.6

线性环必须遵循右手定则
它所包围的区域,即外环是逆时针的,并且
孔是顺时针方向的。

When validating the geojson, I get the error:

Line 1: Polygons and MultiPolygons should follow the right-hand rule

https://www.rfc-editor.org/rfc/rfc7946#section-3.1.6

A linear ring MUST follow the right-hand rule with respect to the
area it bounds, i.e., exterior rings are counterclockwise, and
holes are clockwise.

音盲 2025-01-16 19:41:09
public void onMapReady(@NonNull GoogleMap map) {
        if (mMap != null) {
            return;
        }
        mMap = map;
        MarkerManager markerManager = new MarkerManager(mMap);
        GroundOverlayManager groundOverlayManager = new GroundOverlayManager(mMap);
        PolygonManager polygonManager = new PolygonManager(mMap);
        PolylineManager polylineManager = new PolylineManager(mMap);
// GeoJSON polygon
       try{
            GeoJsonLayer geoJsonPolygonLayer = new GeoJsonLayer(mMap, R.raw.your_file_name_here, this, markerManager, polygonManager, polylineManager, groundOverlayManager);
            // style your polygon here
            GeoJsonPolygonStyle geoJsonPolygonStyle = new GeoJsonPolygonStyle();
            geoJsonPolygonStyle.setFillColor(Color.RED);
            for (GeoJsonFeature f : geoJsonPolygonLayer.getFeatures()) {
                f.setPolygonStyle(geoJsonPolygonStyle);
            }
            geoJsonPolygonLayer.addLayerToMap();
            geoJsonPolygonLayer.setOnFeatureClickListener((GeoJsonLayer.GeoJsonOnFeatureClickListener) feature ->
                    Toast.makeText(MultiLayerDemoActivity.this,
                    "GeoJSON polygon clicked: " + feature.getProperty("title"),
                    Toast.LENGTH_SHORT).show());
        } catch (IOException e) {
            Log.e(TAG, "GeoJSON file could not be read");
        }
}
public void onMapReady(@NonNull GoogleMap map) {
        if (mMap != null) {
            return;
        }
        mMap = map;
        MarkerManager markerManager = new MarkerManager(mMap);
        GroundOverlayManager groundOverlayManager = new GroundOverlayManager(mMap);
        PolygonManager polygonManager = new PolygonManager(mMap);
        PolylineManager polylineManager = new PolylineManager(mMap);
// GeoJSON polygon
       try{
            GeoJsonLayer geoJsonPolygonLayer = new GeoJsonLayer(mMap, R.raw.your_file_name_here, this, markerManager, polygonManager, polylineManager, groundOverlayManager);
            // style your polygon here
            GeoJsonPolygonStyle geoJsonPolygonStyle = new GeoJsonPolygonStyle();
            geoJsonPolygonStyle.setFillColor(Color.RED);
            for (GeoJsonFeature f : geoJsonPolygonLayer.getFeatures()) {
                f.setPolygonStyle(geoJsonPolygonStyle);
            }
            geoJsonPolygonLayer.addLayerToMap();
            geoJsonPolygonLayer.setOnFeatureClickListener((GeoJsonLayer.GeoJsonOnFeatureClickListener) feature ->
                    Toast.makeText(MultiLayerDemoActivity.this,
                    "GeoJSON polygon clicked: " + feature.getProperty("title"),
                    Toast.LENGTH_SHORT).show());
        } catch (IOException e) {
            Log.e(TAG, "GeoJSON file could not be read");
        }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文