When removing a Source that's being currently processed by a Layer we are failing silently and printing a log.
We should improve the experience during this unusual condition by maybe printing a higher level log, and on the Android side updating docs and returning null instead of the Source object in the MapboxMap#removeSource when it fails.
Example that will fail:
mapView.getMapAsync(mapboxMap -> {
GeoJsonSource source = new GeoJsonSource("source", Point.fromLngLat(0, 0));
mapboxMap.addSource(source);
mapboxMap.addLayer(new CircleLayer("layer", "source"));
mapboxMap.removeSource("source");
});
How's @mapbox/maps-ios handling this scenario?
Whoops, obviously we first need to remove a Layer to be able to remove a Source... That said, we still can improve the returned values and logs.
My idea was to patch this up as part of https://github.com/mapbox/mapbox-gl-native/issues/10947
How's @mapbox/maps-ios handling this scenario?
MGLStyle doesn鈥檛 explicitly document the fact that the developer shouldn鈥檛 remove sources or images that are currently being used by layers. If they try to do that, mbgl logs a warning to the console and fails silently (or gracefully, depending on your point of view).
Since we subsequently nil out the source鈥檚 map view backpointer and pending source pointer, we鈥檙e unable to prevent the developer from adding the same source to a different map view鈥檚 style:
https://github.com/mapbox/mapbox-gl-native/blob/60cbedc344eff10df0069a9d243a555dc59992ee/platform/darwin/src/MGLSource.mm#L62-L63
https://github.com/mapbox/mapbox-gl-native/blob/60cbedc344eff10df0069a9d243a555dc59992ee/platform/darwin/src/MGLSource.mm#L51-L53
Can we move forward in 10947 as @tobrun suggests?
android equivalent of https://github.com/mapbox/mapbox-gl-native/issues/9692
Most helpful comment
Whoops, obviously we first need to remove a
Layerto be able to remove aSource... That said, we still can improve the returned values and logs.