Jackson K
Jackson K

Reputation: 21

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. 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

Answers (1)

langsmith
langsmith

Reputation: 2546

This should work for you

GeoJsonSource source = style.getSourceAs(ROUTE_SOURCE_ID);

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

Upvotes: 3

Related Questions