Reputation: 53
Does anybody know how I can remove Polylines that I have on a map. I hve tried many things to remove the lines taht is drawn up. But it will not dissapear. This is the code I used to draw the lines :
var geojson = [
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[10.39799, 63.43074],
[10.3987, 63.431]
]
},
"properties": {
"stroke": "#fc4353",
"stroke-width": 5
}
},{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[10.397958755, 63.431],
[10.39868, 63.43073]
]
},
"properties": {
"stroke": "#fc4353",
"stroke-width": 5
}
}
];
L.geoJson(geojson, { style: L.mapbox.simplestyle.style }).addTo(map);
Upvotes: 1
Views: 2886
Reputation: 15417
Store reference of the added thing to a variable. Then use map.removeLayer
.
var layer = L.geoJson(geojson, { style: L.mapbox.simplestyle.style }).addTo(map);
map.removeLayer(layer);
https://www.mapbox.com/mapbox.js/api/v2.1.4/l-map-class/#map-stuff-methods
Upvotes: 3