I am using below code to add markers to mapbox map.
var marker = L.marker([latitude, longitude],
{
icon: L.divIcon({
html: 'myhtml',
iconSize: [40, 40]
})
});
marker.addto(map);
I have added markers using for loop using above code. Now I want to remove marker to refresh the map. Is there any was I can remove all markers and polylines from map. Or if there is any way I can reload the mapbox map.
Click the buttons to hide or delete all of those markers. Read the documentation. // In the following example, markers appear when the user clicks on the map. // The markers are stored in an array. // The user can then click an option to hide, show or delete the markers.
Finally, take a look at how to toggle layers in Mapbox.js. You can help users sift through your markers by adding filters to let them turn layers on and off. In this example, the script automatically creates a toggle option for each transit line and will only add a new layer to the toggle list if its line is declared in the GeoJSON.
Consider thar var currentMarkers contains all markers, you can do this with sometning like : oneMarker= new mapboxgl.Marker (currentMarkerDiv) .setLngLat (marker.geometry.coordinates) .addTo (mapboxMap); currentMarkers.push (oneMarker);
Mapbox.js is no longer in active development. To learn more about our newer mapping tools see Add custom markers in Mapbox GL JS. In this guide, we’ll show how to add markers, customize them, and make them interactive with Mapbox.js.
You can use map.removeLayer(marker); to remove the marker (an ILayer object).
Also, addto(map) should be addTo ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With