MapBox 高效地添加和绘制多条折线?

MapBox Adding and Plotting Many Polylines Efficiently?

我有一个折线、标记和多边形的数据集,存储为 CSV 文件中的 lat/lon 数据,需要在 Android MapBox 中绘制。我可以使用 mapboxmap.addPolyline、addMarker 和 addpolygons 轻松完成此操作,但是在添加数百个点后滚动地图并查看 Android phone 上的数据变得非常慢。

我做错了吗?有没有更有效的方法来绘制我应该使用的许多数据点?

您使用的是哪个版本的 Maps SDK?您对 addPolyline/addMarker/等的使用。让我觉得你使用的是一个非常过时的版本。请尝试使用 8.5.0 并使用 sources/layers:https://docs.mapbox.com/android/maps/overview/data-driven-styling/

一般来说,您应该使用 CSV 文件中的 lat/lon 数据来创建 Feature 对象。使用它们创建一个 FeatureCollection,然后创建 add/style 层。

设置 LineLayer

mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
          @Override
          public void onStyleLoaded(@NonNull Style style) {

            Feature polygonFeature = Feature.fromGeometry(Polygon.fromLngLats());
            Feature lineStringFeature = Feature.fromGeometry(LineString.fromLngLats());
            Feature pointFeature = Feature.fromGeometry(Point.fromLngLat());

            FeatureCollection featureCollection = FeatureCollection.fromFeatures(new Feature[]{
                pointPolygon, pointLineString, pointFeature
            });

            GeoJsonSource geoJsonSource = new GeoJsonSource("source-id", featureCollection);

            style.addSource(geoJsonSource);

            LineLayer lineLayer = new LineLayer("line-layer-id", "source-id");
            lineLayer.setProperties(
                PropertyFactory.lineColor(Color.BLUE)
            );
            style.addLayer(lineLayer);

          }
        });