简体   繁体   中英

Remove Polylines on a map from mapbox

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);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM