Disable onEachFeature with geoJson

751 views
Skip to first unread message

Christopher Boakes

unread,
Feb 7, 2013, 7:50:04 AM2/7/13
to leafl...@googlegroups.com
Hi guys,

I was wondering if anybody is able to help me out with the following query.

I'm trying to disable mouse events on a geoJson layer when at a certain zoom level. I'm managing the zoom level fine and I've set up the geoJson as follows:

var continents = $.getJSON(FILELOCATION);
continents.done(function(response) {
geojson = L.geoJson(response, {
style: style,
onEachFeature: onEachFeature
}).addTo(map);
});

The onEachFeature function defines simple hover and click events. My question is how do update this (or disable layer clicks). I've managed to update the layer style by simply using setStyle, is there an equivalent for onEachFeature?

Any help would be greatly appreciated.

Many thanks,

Chris

Vladimir Agafonkin

unread,
Feb 7, 2013, 10:36:34 AM2/7/13
to leafl...@googlegroups.com
You can use group.eachLayer(fn) (inherited from LayerGroup). The feature data is accessible through layer.feature property.


2013/2/7 Christopher Boakes <crbo...@gmail.com>

--
 
---
You received this message because you are subscribed to the Google Groups "Leaflet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leaflet-js+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Vladimir Agafonkin
http://agafonkin.com/en
+380 (93) 745 44 61

Christopher Boakes

unread,
Feb 7, 2013, 11:20:55 AM2/7/13
to leafl...@googlegroups.com
Thank you, this works perfectly. However it's still picking up the mouse events from the onEachFeature function that I set before. do you have any idea how I can disable this?

Many thanks,

Chris

Bryan McBride

unread,
Feb 8, 2013, 12:21:59 AM2/8/13
to leafl...@googlegroups.com
What about something like this:

geojson.eachLayer(function (layer) {
    layer.off({
        mouseover: highlightFeature,
        mouseout: resetHighlight,
        click: zoomToFeature
    });
});

Christopher Boakes

unread,
Feb 8, 2013, 11:13:31 AM2/8/13
to leafl...@googlegroups.com

Thanks for all of the help guys. The solution I used in the end was to assign a global boolean variable which triggers when the user clicks a layer. The functions (set by the onEachFeature functions) do different things based on the boolen's value.

Chris

Reply all
Reply to author
Forward
0 new messages