Reputation: 383
mapStyle?.addSource(
GeoJsonSource.Builder(SELECTED_ROUTE_MAP_LAYER)
.featureCollection(pushingFeatureCollection).build()
)
mapStyle?.addLayer(createLineLayer(SELECTED_ROUTE_MAP_LAYER))
mapStyle?.removeLayer(SELECTED_ROUTE_MAP_LAYER)
How do I go about removing a layer I added to my mapstyle? I'm using mapbox v10 and removeLayer
does not appear to be an option anymore (Unresolved reference: removeLayer
). I am trying to figure out what the recommened approach is, since the functionallity for adding a layer is the same as previous versions, yet the removal feature appears to be scraped.
Here are the versions I am using:
// MapBox
implementation 'com.mapbox.maps:android:10.15.0'
implementation "com.mapbox.search:mapbox-search-android-ui:1.0.0-rc.6"
Upvotes: 0
Views: 71
Reputation: 383
I never found a way to remove a layer once it was added, so instead I am using this workaround:
val layerSource =
mapView.getMapboxMap().getStyle()?.getSourceAs<GeoJsonSource>(SELECTED_ROUTE_MAP_LAYER)
if (layerSource == null) {
mapStyle?.addSource(
GeoJsonSource.Builder(SELECTED_ROUTE_MAP_LAYER)
.featureCollection(pushingFeatureCollection).build()
)
// Add layer above rendered routes
mapStyle?.let { addLayerBasedOnMapType(this, it, SELECTED_ROUTE_MAP_LAYER) }
} else {
layerSource.featureCollection(pushingFeatureCollection)
}
fun hideCurrentRouteLayer(mapboxMap: MapboxMap) {
val emptyFeatureCollection = FeatureCollection.fromFeatures(emptyList())
val source = mapboxMap.getStyle()?.getSourceAs<GeoJsonSource>(SELECTED_ROUTE_MAP_LAYER)
source?.featureCollection(emptyFeatureCollection)
}
Upvotes: 0