简体   繁体   English

ESRI单张地图,重置样式无效

[英]ESRI leaflet map, reset style not working

I am working on my first leaflet map and am running into an issue when trying to reset the style onMouseOut. 我正在制作我的第一张传单地图,并且尝试重置onMouseOut样式时遇到问题。 it correctly changes style on mouse over but on mouse out, i keep getting: Object doesn't support property or method 'resetStyle' 它可以在鼠标悬停时正确地更改样式,但是在鼠标悬停时,我一直在获取:对象不支持属性或方法“ resetStyle”

This is what i have and what I have tried: 这就是我所尝试的:

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) {
    ...
}

as per the API reference , that is a method on FeatureLayer itself, and expects you to pass the id of a specific feature. 根据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