从地图框中删除地图上的多段线

Remove Polylines on a map from mapbox

本文关键字:地图 段线 删除      更新时间:2023-09-26

有人知道我如何删除地图上的多段线吗。我已经尝试了很多方法来消除它所画的线。但它不会消失。这是我用来划线的代码:

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

存储添加内容对变量的引用。然后使用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-填充方法