Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple click handler not working for Geojson layer on Leaflet 1.0.0-rc.3 #4852

Closed
ttback opened this issue Aug 26, 2016 · 4 comments
Closed

Comments

@ttback
Copy link

ttback commented Aug 26, 2016

I am doing something similar to http://jsfiddle.net/tator/em9cLfk4/4/

This isn't related to layer click bubbled up to map click handler however. It's about the layer click simply doesn't get triggered with code that is working properly for 0.7.7.

I reduced my code to just base tile layer + one overlay layer to make sure there isn't any layer order zindex issues.

The map.on("click") still fires properly but not for the GeoJson layer.

function onEachFeatureHandler(feature, layer){
            layer.on('click', function(e){
                     alert("click");
           });
}

overlay = L.geoJson(GeoJSON, {
       onEachFeature: onEachFeatureHandler
});

I also tried two different ways to do the layer.on("click"), either click as a string, or add a {"click": handlerFuncName}. It doesn't make a difference as expected.

I tried adding the base tile layer before/after the overlay, and nothing changed. I also removed the click handler on map to avoid an event conflict. So I end up with a map with just tile + overlay, and one click event handler, but still, nothing will fire. The mouse cursor indicates that the layer is not clickable at all.

I also modified the colors of overlay to make sure it was properly added to the map object. It is on top of the tilelayer.

This is happening in latest Chrome v52 and Safari 9 on the Mac.

After trying almost 4 hours on this...I suspect it might be something dumb in my code or there are some API changes I miss out on the changelog. I'd appreciate if you can offer some tips on what I might have been doing wrong. Any insight would be appreciated.

@mourner
Copy link
Member

mourner commented Aug 26, 2016

Can you set up an exact minimal test case on JSFiddle or Leaflet Playground reproducing the issue?

@ttback
Copy link
Author

ttback commented Aug 26, 2016

@mourner I will try a playground with some simple Geojson and see what happens. I haven't had the click handler code broken in very isolated examples. I even debugged to the layer object in debugger...the click handler is definitely added. A click event is triggered on the tile <img> when I click on the layers.

I can't think of any other factors impacting this.

@ttback
Copy link
Author

ttback commented Aug 26, 2016

@mourner just tried it with rc3 on playground, raw geojson layer still works as intended...

@ttback
Copy link
Author

ttback commented Aug 27, 2016

@mourner After some thinking, I realize I didn't update the css to latest. It may have contributed to the zIndex level not being correct, or disallowed some click event. Now everything seems to be normal just by updating the css to latest. Closing the issue.

@ttback ttback closed this as completed Aug 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants