Leaflet / Leaflet.VectorGrid

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

Add mouse interactions #22

Closed perliedman closed 7 years ago

perliedman commented 7 years ago

This is my work in progress to address #3. This is far from ready to merge at this point

I'm a little disappointed so far in that this feels a bit clumsy and intrusive, especially since I have to duplicate L.Canvas's _onClick method etc. in L.Canvas.Tile, since Leaflet's implementation assumes the canvas origin is the same as the map's pixel origin, which it isn't when we're using them as tiles.

Haven't event touched SVG so far, so that most likely doesn't work.

@IvanSanchez if you have any comments or suggestions, that would be very welcome. I'll continue working on this since it at least seems doable.

perliedman commented 7 years ago

This should now support all the standard mouse interactions for both SVG and Canvas.

I've hit one snag, though... when the map wraps, the canvas logic gets confused about the tiles pixel offset (relative map's pixel origin), since there isn't a 1:1 mapping from tile coordinate to pixel offset. It feels like this problem is probably solved somewhere in the Leaflet codebase already, but I haven't found it.

manuamador commented 7 years ago

Thanks! Will be very useful. Testing it next Monday.

perliedman commented 7 years ago

Except for maybe a couple of bug fixes, I think I'm pretty much done with this now.

The last commit (https://github.com/Leaflet/Leaflet.VectorGrid/pull/22/commits/bb6c5ede6f3d05be8434402fc1ba3a34c7201fd1) changes quite a lot of things, so it could be reverted, but at least in my use case (~200k features), it gives a measurable performance boost - my guess is that the real classes are easier to optimize for the JavaScript engine.

IvanSanchez commented 7 years ago

@perliedman I'll need some time to review this and have an idea of what you've done :-D

IvanSanchez commented 7 years ago

@perliedman I'll just merge and worry about the bugs later :-)