从传单地图中删除指定的图层

时间:2019-10-15 09:46:59

标签: javascript leaflet

我有多个geojson图层,只需要从地图中删除一些指定的图层即可。



 dropdownlayers["12"] = {
  name:"Road Network",
  layer:L.geoJson(0,{style:style_road}),
  url:"http://localhost:8020/geoserver/burgula/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=burgula:burgul_roads&maxFeatures=3500&outputFormat=application%2Fjson"
}

dropdownlayers["13"] = {
  name:"Cadastral Map",
  layer:L.geoJson(0,{style:style_cadastral_map,onEachFeature:label_cm}),

  url:"http://localhost:8020/geoserver/burgula/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=burgula:burgula_cadastral_boundary&maxFeatures=3500&outputFormat=application%2Fjson"
}



    function load_layer(dropdownchoice) {
      $.ajax({
        type: "GET",
         dataType: "json",
          jsonpCallback: 'getJson',
         async: true,
         url: dropdownchoice.url,
        success: function(data) {
          var layer = dropdownchoice.layer;
         //this function remove all geojson layers but i want only specified layers remove//
         map.eachLayer(function(layer){
          if(layer instanceof L.Layer)

            map.removeLayer(layer)

         });
         layer.addTo(map)
          $(data.features).each(function(key, data) {
            layer.addData(data);
          })
          layerControl.addOverlay(layer, dropdownchoice.name);
          map.fitBounds(layer.getBounds());
        }
      }).error(function() {});
    }

 

0 个答案:

没有答案