Remove all markers from mapbox or reinitialize map

I use the code below to add markers to a mapbox map.

var marker = L.marker([latitude, longitude],
                        {
                            icon: L.divIcon({
                                html: 'myhtml',
                                iconSize: [40, 40]
                            })
                        });
marker.addto(map);

I added tokens using the loop using the code above. Now I want to remove the marker to update the map. Can I remove all markers and polylines from the map. Or, if there is any way, I can reload the mapbox.

+4
source share
1 answer

You can use map.removeLayer (marker); delete marker (ILayer object).

In addition, addto (map) must be addTo;)

+10
source

Source: https://habr.com/ru/post/1535726/


All Articles