removeMarker method
Removes a marker marker from the map.
Implementation
Future<void> removeMarker(String markerId) async {
// Remove marker points and close the location stream.
try {
markerPoints.remove(markerId);
_locationStreamControllers[markerId]?.close();
_locationStreamControllers.remove(markerId);
// Remove the marker layer and source from the map.
if (markerLayerIds[markerId] != null) {
String layerId = 'layer-$markerId';
String sourceId = 'source-$markerId';
mapboxMap.style.removeStyleLayer(layerId);
mapboxMap.style.removeStyleSource(sourceId);
markerLayerIds.remove(markerId);
// Update the last layer ID if necessary.
if (_lastLayerId == layerId) {
_lastLayerId = markerLayerIds.values.isNotEmpty ? markerLayerIds.values.last : null;
}
}
} on Exception catch (_) {
rethrow;
}
}