0

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

1 回答 1

0

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

// because the individual feature is GeoJSON, it has an id, along with properties and geometry
districtLayer.resetStyle(e.layer.feature.id);
于 2018-07-05T15:21:44.157 回答