I am struggling to clear all polylines from my map, i only clear the newest.
var polylines;
// add map polylines
function addPolyline(polyArray, colour) {
polylines = L.polyline(polyArray, {color: colour});
polylines.addTo(map);
}
// clear polylines
function clearPolylines() {
map.removeLayer(polylines);
}
where addPolylines is called multiple times and clear Polylines is called once. How can i clear all polylines on the map?
You can add the polyline to a layerGroup and easily add/remove it to/from the map. Something like this:
pLineGroup = L.layerGroup()
var latlngs = [
[45.51, -122.68],
[37.77, -122.43],
[34.04, -118.2]
];
this.pLineGroup.addLayer(L.polyline(latlngs, {color: 'red'}))
pLineGroup.addTo(map)
pLineGroup.removeFrom(map)
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