Leaflet / Leaflet.VectorGrid

Display gridded vector data (sliced GeoJSON or protobuf vector tiles) in Leaflet 1.0.0
598 stars 194 forks source link

Stop click propagation on first returned feature #93

Closed ka7eh closed 7 years ago

ka7eh commented 7 years ago

I have a vector layer of parcels in a city and there's a click event attached to the layer returning AIN (Assessor Identification Number) of the clicked parcel. The problem is when I click at a dense area, the click event is called multiple times, as in going through bunch of parcels that fall within a buffered area around the clicked point.

Here's a fiddle you can try: https://jsfiddle.net/kaveh/dv4xv1ec/6/

At a default zoom level, click on a dense area and you'll see in the console that multiple AINs are returned.

What I want to do is stopping the event after one parcel is found and not bubbling/propagating/iterating to/over the rest of the features.

As you can see in the fiddle, I've tried all the following in the click listener with no success:

e.originalEvent.stopPropagation()
e.originalEvent.stopImmediatePropagation()
e.originalEvent.preventDefault()

Is there any built-in work around for this?

perliedman commented 7 years ago

Hm, what version are you using? SVG or canvas? I might be mistaken, but I think latest master should not behave like you describe. Ideally, could you provide a running example illustrating the issue (on jsfiddle or Leaflet playground)?

ka7eh commented 7 years ago

I'm using version 1.2.0 with Canvas. There's a working example in the fiddle in the original comment.

perliedman commented 7 years ago

Sorry, obviously it's too late friday night for me to be able to read properly. Will check the fiddle.

perliedman commented 7 years ago

I'm pretty certain you need bd2008143cdf6f26c724965c14bec7b3a4d6596a, which is in master but was added after 1.2.0. In particular, this includes a fix where only a single layer will fire clicks, instead of every layer within the click tolerance.

Would it possible for you to try latest master?

ka7eh commented 7 years ago

Sure, I'll try it and send an update.

ka7eh commented 7 years ago

Thanks @perliedman. I tried the latest version with the commit you mentioned and it worked fine. Is there any plan for a new official release soon with this fix in it? I had lots of trouble with rollup and building the stuff from source.