0

I am working on my first leaflet map and am running into an issue when trying to reset the style onMouseOut. it correctly changes style on mouse over but on mouse out, i keep getting: Object doesn't support property or method '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) {
    ...
}

1 Answer 1

0

as per the API reference, that is a method on FeatureLayer itself, and expects you to pass the id of a specific feature.

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.