Leaflet.VectorGrid icon indicating copy to clipboard operation
Leaflet.VectorGrid copied to clipboard

Add a hook to be notified when point features are added

Open albanm opened this issue 8 years ago • 10 comments

This solves https://github.com/Leaflet/Leaflet.VectorGrid/issues/67

The demo is very explicit I think. The user can define a function for each vt layer to be called when a point feature is added. This function will receive the feature's properties, the tile coordinates and a point. Enough information to draw a marker on the map for example.

The demo also includes a cache to clear markers when the tiles are unloaded. It is a bit verbose. Maybe VectorGrid could implement this cache of user defined layers (the return of the hook function for example) for a smoother integration.

I didn't write the documentation yet, I wanted to get some feedback before. I suppose that it should include a warning about performance because many vector tiles layers are too dense for this feature to be a good idea.

albanm avatar Feb 01 '17 21:02 albanm

Hi, and thanks for looking into this! I added a review with some suggested changes that I think would improve this functionality and make it a bit more general.

Other than that, I agree with your comments - docs would be great, and I agree a comment about performance implications would be good.

perliedman avatar Feb 02 '17 08:02 perliedman

Hi, I just answered to your comments defending my initial commit :)

But actually I see your point, a simple single callback that does not clutter the API would be nice. But it would require to reduce processing as much as possible, so no transformation of tile coords into map coords. Maybe just resolve the discrepancy of having different geometry notations from geojson-vt and from pbf. Less work in the API, a little more work on the client side.

albanm avatar Feb 02 '17 10:02 albanm

Another version in the last commit.

There is a single onEachFeature callback. But it has extra parameters compared to L.GeoJSON to give all relevant info to the user.

Also I wrote some little util functions to switch from tile geometry to a point or a latlng. Otherwise I feel the client code is overly complicated. Note that the code could be slightly refactored so that these functions are used internally as well.

albanm avatar Feb 02 '17 11:02 albanm

The last commit is just an idea to make user's code much more readable and straightforward. You may consider it outside the scope of VectorGrid. Actually it could be a GridLayer functionality, binding manually created layers to part of the grid and clean them implicitly seems useful.

albanm avatar Feb 02 '17 11:02 albanm

@albanm hi, sorry for dropping out here for a while.

While I understand the use for the extra functions in the last commit, I think it's better to leave this out and keep VectorGrid focused. As long as we make sure to offer the right extension points, users can add this or similar functionality themselves.

perliedman avatar Feb 15 '17 09:02 perliedman

I'd love to see progress on this. I'll have a look myself, but if anyone with more expertise felt inclined to look again, that would be great.

tomchadwin avatar Nov 25 '17 18:11 tomchadwin

Having tweaked this to work with current master (or at least my fork), it seems to do what is required. Thanks, @albanm!

tomchadwin avatar Nov 27 '17 14:11 tomchadwin

@albanm In the demo (and when I've tried to implement this), I seem to be getting duplicate labels for each feature. How is that happening, and how could we fix it?

tomchadwin avatar Nov 29 '17 11:11 tomchadwin

Honestly I had totally forgotten this PR. And I don't have the time to look into it again soon. Sorry about that.

albanm avatar Nov 29 '17 12:11 albanm

Any ideas if this will be implemented?

Parrryy avatar Oct 04 '23 11:10 Parrryy