J'essaie de supprimer tous les marqueurs sur ma carte, mais le code ci-dessous seulement le dernier marqueur ajouté sera supprimé.Comment supprimer plusieurs marqueurs d'une carte Leaflet?
Existe-t-il un moyen d'obtenir une nouvelle instance de la carte que je veux dire par un clic sur un bouton est-il possible de réinitialiser la carte dans la brochure?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="https://npmcdn.com/[email protected]/dist/leaflet.css" />
</head>
<body>
<script src="https://npmcdn.com/[email protected]/dist/leaflet.js"></script>
<script src="../leaflet/lib/AnimatedMarker.js"></script>
<style>
#mapid { height: 500px; }
</style>
<div id="mapid"></div>
<script>
var mymap = L.map('mapid').setView([40.68510, -73.94136], 13);
L.tileLayer('http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', {
attribution: '© Openstreetmap France | © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(mymap);
var marker = L.marker([40.68510, -73.94136]).addTo(mymap);
var marker = L.marker([40.68576, -73.94149]).addTo(mymap);
var marker = L.marker([40.68649, -73.94165]).addTo(mymap);
mymap.removeLayer(marker);
</script>
</body>
</html>
Donnez à chaque 'marqueur' un nom de variable différent, par ex. 'marker1'' marker2' ... vous devriez alors pouvoir supprimer chacun: 'mymap.removeLayer (marker2)' –
J'ai édité le premier paragraphe. La seconde que je ne comprends pas, alors je l'ai laissée - pouvez-vous clarifier de quoi il s'agit? Cela semble sans rapport avec votre question? –
Comme astuce, n'oubliez pas de capitaliser vos I dans "Je suis" etc. –