Leaflet / Leaflet.VectorGrid

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

protobuf: features not available after loading/rendering #13

Open ghost opened 8 years ago

ghost commented 8 years ago

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

IvanSanchez commented 8 years ago

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.

ghost commented 8 years ago

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?

IvanSanchez commented 8 years ago

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.

ghost commented 8 years ago

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

IvanSanchez commented 8 years ago

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.

StefanBrand commented 5 years ago

Referencing #217

ssontag55 commented 4 years ago

@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)