簡體   English   中英

ESRI單張地圖,重置樣式無效

[英]ESRI leaflet map, reset style not working

我正在制作我的第一張傳單地圖,並且嘗試重置onMouseOut樣式時遇到問題。 它可以在鼠標懸停時正確地更改樣式,但是在鼠標懸停時,我一直在獲取:對象不支持屬性或方法“ resetStyle”

這就是我所嘗試的:

var MAP_ID = 'DISTRICT_MAP';
var map = L.map(MAP_ID).setView([37.71, -99.88], 4);

function showMap() {
    var layerConfig = {
        ....
        onEachFeature: onEachFeature,
        style: style
    };
    var districtLayer;

    //Add base map layer
    L.esri.basemapLayer('Gray').addTo(map);

    //Add the District layer
    districtLayer = L.esri.featureLayer(layerConfig);
    map.addLayer(districtLayer);
}

function highlightFeature(e) {
    var layer = e.target;
    layer.setStyle({
        weight: 5,
        color: '#666',
        dashArray: '',
        fillOpacity: 0.7,
    });
    if (!L.Browser.ie && !L.Browser.opera12 && L.Browser.edge) {
        layer.bringToFront();
    }
}

// Can't get this to work!
function resetHighlight(e) {
    //L.esri.featureLayer.resetStyle(e.target);
    //e.target.resetStyle(e.target);
    //e.layer.resetStyle();
}
function onEachFeature(feature, layer) {
    layer.on("mouseover", function (e) {
         highlightFeature(e);
    });
    layer.on("mouseout", function (e) {
        if (e.target && e.target.feature && e.target.feature.properties) {
            resetHighlight(e);
        }
    });
    layer.on("click", function (e) {
        ....
        }
    });
}

function style(feature, layer) {
    ...
}

根據API參考 ,這是FeatureLayer本身的方法,希望您傳遞特定功能的id

// because the individual feature is GeoJSON, it has an id, along with properties and geometry
districtLayer.resetStyle(e.layer.feature.id);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM