从地图框中删除地图上的折线

时间:2014-10-29 16:33:32

标签: javascript mapbox geojson

有人知道我如何删除地图上的折线。我已经尝试了很多东西来删除这些线条。但它不会消失。这是我用来画线的代码:

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

1 个答案:

答案 0 :(得分:3)

将添加的内容的引用存储到变量中。然后使用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