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

时间:2018-07-04 21:08:27

标签: javascript leaflet esri-leaflet

我正在制作我的第一个传单地图,并且尝试重置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) {
    ...
}

1 个答案:

答案 0 :(得分:0)

根据API reference,这是FeatureLayer本身的一种方法,希望您传递特定功能的id

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