简体   繁体   English

如何从 Android 上的地图框 map 中删除线串

[英]How to remove a Linestring from a mapbox map on Android

I'm using mapbox for android (java) and I'm not sure how to remove a linestring after I've set it to a geojson source.我正在为 android (java) 使用 mapbox,我不确定如何在将线串设置为 geojson 源后删除它。 I'm using the MapboxDirections builder to generate a route called currentroute, and then using this code to display it on the map:我正在使用 MapboxDirections 构建器生成名为 currentroute 的路线,然后使用此代码将其显示在 map 上:

GeoJsonSource source = style.getSourceAs(ROUTE_SOURCE_ID);
LineString drawnRoute = LineString.fromPolyline(currentRoute.geometry(), PRECISION_6);
source.setGeoJson(drawnRoute);

And I add the source to my style earlier on with我之前将源代码添加到我的风格中

loadedMapStyle.addSource(new GeoJsonSource(ROUTE_SOURCE_ID));

I've looked around the documentation, and it seems they had some.remove methods for polylines in the past, but it's since been depricated and is unusable.我查看了文档,似乎他们过去有一些用于折线的方法,但它已经被贬低并且无法使用。 Is there any way to remove my linestring from showing on my map?有什么办法可以让我的线串不再显示在我的 map 上? If not, is there another way I can display a linestring that will let me delete it eventually?如果没有,有没有另一种方法可以显示一个线串,让我最终删除它?

This should work for you这应该适合你

GeoJsonSource source = style.getSourceAs(ROUTE_SOURCE_ID);

if (source != null) {
   source.setGeoJson(FeatureCollection.fromJson(""));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM