I created geoJson object as below:
var geoJson= L.geoJson(groupingLevelType.type, {
style: style,
onEachFeature: onEachFeature
});
function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight
});
function resetHighlight(e) {
geojson.resetStyle(e.target);
}
In resetHighlight
method I want to reset style of geoJson
.How I can pass geoJson
as parameter to onEachFeature
method.Or there there is any other way separate onEachFeature
from creation of geoJson
to be able to reset style?
Best Answer
Thanks to JavaScript scoping, you should be able to use your
geoJson
variable within youronEachFeature
function without the need to "pass [it] as parameter".Note that you may have a typo:
geojson.resetStyle(e.target);
should begeoJsonā¦
(note the capitalJ
) to match your variable name.Once this typo is corrected, your code looks to work: http://jsfiddle.net/ve2huzxw/180/