0

当您放大地图时,我会添加 DynamicLayers Leaflet Esri。但是我想删除它们并且它不起作用,它没有给出任何错误但它不起作用。我试试mapConsultaView.removeLayer(layer2);

// ====================================== Styles de icones coloridos para markers ========================================= //

var blueIcon = new L.Icon({
    iconUrl: document.location.origin +'/sin/img/marker-icon-blue.png', 
    iconSize: [25, 41],
    iconAnchor: [12, 41],
    popupAnchor: [1, -34],
    shadowSize: [41, 41]
});

var redIcon = new L.Icon({
    iconUrl: document.location.origin +'/sin/img/marker-icon-red.png',
    iconSize: [25, 41],
    iconAnchor: [12, 41],
    popupAnchor: [1, -34],
    shadowSize: [41, 41]
});

var greenIcon = new L.Icon({
    iconUrl: document.location.origin +'/sin/img/marker-icon-green.png',
    iconSize: [25, 41],
    iconAnchor: [12, 41],
    popupAnchor: [1, -34],
    shadowSize: [41, 41]
});

var orangeIcon = new L.Icon({
    iconUrl: document.location.origin +'/sin/img/marker-icon-orange.png',
    iconSize: [25, 41],
    iconAnchor: [12, 41],
    popupAnchor: [1, -34],
    shadowSize: [41, 41]
});

var yellowIcon = new L.Icon({
    iconUrl: document.location.origin +'/sin/img/marker-icon-yellow.png',
    iconSize: [25, 41],
    iconAnchor: [12, 41],
    popupAnchor: [1, -34],
    shadowSize: [41, 41]
});

var violetIcon = new L.Icon({
    iconUrl: document.location.origin +'/sin/img/marker-icon-violet.png',
    iconSize: [25, 41],
    iconAnchor: [12, 41],
    popupAnchor: [1, -34],
    shadowSize: [41, 41]
});

var greyIcon = new L.Icon({
    iconUrl: document.location.origin +'/sin/img/marker-icon-grey.png',
    iconSize: [25, 41],
    iconAnchor: [12, 41],
    popupAnchor: [1, -34],
    shadowSize: [41, 41]
});

var blackIcon = new L.Icon({
    iconUrl: document.location.origin +'/sin/img/marker-icon-black.png',
    iconSize: [25, 41],
    iconAnchor: [12, 41],
    popupAnchor: [1, -34],
    shadowSize: [41, 41]
});

var markersOverlay = []; // Array que armazena todos os markers plotados

var mapConsultaView;

window.onload = function(data){
    doGeoJSon();

    var mbAttr = '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetmap</a>';   
    var osm   = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: mbAttr}),
        tm_poa_eixos  = L.esri.dynamicMapLayer({
               url: 'myurl'
        }); 

    var mapConsultaView = L.map('mapConsultaView', {
        center: [-30.038037, -51.199163],
        zoom: 14,
        layer:[osm]
    });

    var baseLayers = {
        "Open Street Map": osm
    };

    L.esri.basemapLayer('Streets').addTo(mapConsultaView);
    L.esri.dynamicMapLayer({
           url: ' myUrl',
           useCors: false
        }).addTo(mapConsultaView);

    L.esri.dynamicMapLayer({
           url: ' myUrl'           
        }).addTo(mapConsultaView);

    var layer1 = L.esri.dynamicMapLayer({
           url: ' myUrl',
           useCors: false
        });

    var layer2 = L.esri.dynamicMapLayer({
           url: ' myUrl',
           useCors: false
        });

    var layer3 = L.esri.dynamicMapLayer({
           url: ' myUrl',
           useCors: false
        });




    L.control.layers(baseLayers,{collapsed:false}).addTo(mapConsultaView);
    baseLayers["Open Street Map"].addTo(mapConsultaView);

    //Listener zoom 
    mapConsultaView.on('zoomend', function (e) {        
        if (mapConsultaView.getZoom() == 14) {
            layer1.addTo(mapConsultaView);
        }
        if (mapConsultaView.getZoom() == 16) {
            layer2.addTo(mapConsultaView);
            layer3.addTo(mapConsultaView);
        }

        //HERE test
        mapConsultaView.removeLayer(layer2);
    });
};
4

1 回答 1

1

无需L.esri.dynamicMapLayer手动添加和删除地图。maxZoom并且minZoom可用作构造函数选项,让您控制图层何时出现。

http://esri.github.io/esri-leaflet/api-reference/layers/dynamic-map-layer.html#options

于 2017-04-30T05:16:10.860 回答