Reputation: 21
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. I'm using the MapboxDirections builder to generate a route called currentroute, and then using this code to display it on the 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? If not, is there another way I can display a linestring that will let me delete it eventually?
Upvotes: 2
Views: 616
Reputation: 2546
This should work for you
GeoJsonSource source = style.getSourceAs(ROUTE_SOURCE_ID);
if (source != null) {
source.setGeoJson(FeatureCollection.fromJson(""));
}
Upvotes: 3