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

protobuf: features not available after loading/rendering

Open ghost opened this issue 7 years ago • 7 comments

Hi, in the geojson-vt variant I'm able to access tile features after the map is rendered, e.g. in a click event handler. I have a scenario where interacting with the map is important, clicking single polygons or selecting groups of polygons in a drawn rectangle or circle. To implement that I need to access the feature geometries and tags contained in the tile. In the protobuf variant all feature info is thrown away after the tile is rendered and I'm not able to access the polygon geometry any more. Would it be possible to cache the features just as the slicer does? Memory constraints won't be any different than with the slicer, would they? -Thomas

ghost avatar Sep 20 '16 09:09 ghost

Would it be possible to cache the features just as the slicer does?

No, because protobuf tiles don't have features, they only have already sliced & cropped features. Thus, accessing a "feature" in a protobuf vector tile will only return that feature with a partial geometry (the piece that intersects the tile bounds plus the margin buffer).

Implementing some kind of feature-under-pointer feature should be possible, by delegating pointer events from the gridlayer to the tile renderers. That's simply not implemented yet, so feel free to hack away and propose a PR.

IvanSanchez avatar Sep 20 '16 09:09 IvanSanchez

Sliced and cropped is fine. I implemented a pick logic that uses the sliced features from geojson-vt tiles. I added runtime info to the feature.tags and called the drawing function again so I can change the styling at runtime without rendering the complete map. Calling the protobuf renderers invokes the fetch process again, doesn't it?

t-sch avatar Sep 20 '16 10:09 t-sch

Calling the protobuf renderers invokes the fetch process again, doesn't it?

No, as the tile is an existing instance of L.Renderer and has internal references to the geometries drawn in it.

IvanSanchez avatar Sep 20 '16 10:09 IvanSanchez

How would I access the renderer for a tile with the address {x,y,z} ?

t-sch avatar Sep 20 '16 10:09 t-sch

You'll need to modify the code from src/Leaflet.VectorGrid.js and store the renderers themselves somewhere. Right now only their containers are stored as the grid tiles (see core leaflet's src/layer/tile/GridLayer.js). Storing the renderers should be possible to be done in a similar fashion, with a key-indexed dictionary, and taking special care to remove references to renderers when tiles are pruned.

IvanSanchez avatar Sep 20 '16 10:09 IvanSanchez

Referencing #217

StefanBrand avatar Sep 27 '19 10:09 StefanBrand

@IvanSanchez You think subbing out the Renderer, you could use something like this? https://github.com/triedeti/Leaflet.streetlabels

Was looking into getting text-label on a vector (ie roads)

ssontag55 avatar Apr 04 '20 18:04 ssontag55