I created geoJson object as below:

var geoJson= L.geoJson(groupingLevelType.type, {
                style: style,
                onEachFeature: onEachFeature

    function onEachFeature(feature, layer) {
                    mouseover: highlightFeature,
                    mouseout: resetHighlight

    function resetHighlight(e) {

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?

3 Answers 3


It is another solution where you get the GeoJSON reference from the event

const resetHighlight = e => {
const foo = e.sourceTarget._eventParents;

Thanks to JavaScript scoping, you should be able to use your geoJson variable within your onEachFeature function without the need to "pass [it] as parameter".

Note that you may have a typo: geojson.resetStyle(e.target); should be geoJson… (note the capital J) to match your variable name.

Once this typo is corrected, your code looks to work: http://jsfiddle.net/ve2huzxw/180/

  • Thanks for your answer.This is true but in my case it is not solve my problem.I shared the solution I have found.
    – user66311
    Mar 3, 2016 at 12:25

I just found a solution like that for my problem,I separated code in different classes and I want to a code more readable.So I do not want to rely on scope of javascript,I set layer style again in resetHighlight method:

function resetHighlight(e) {
   var layer = e.target;
            color: '',
            fillOpacity: 0.7

and in this way I do not have to pass geoJson as parameter. Hope this helps another user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.