Leaflet / Leaflet.VectorGrid

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

Dissolve polygons at tile boundary by ID #120

Closed yellowcap closed 6 years ago

yellowcap commented 6 years ago

I am rendering polygons from pbf tiles in a web application. The tiles render fine and custom styling is successful, but the tile boundaries are visible within the geometries, they are not "dissolved".

I am passing and "id" property on the geometry and am returning that value in the getFeatureId function.

Is this expected behavior? I could not figure why the polygons are shown like this.

I posted a screenshot of the behavior here: https://gis.stackexchange.com/questions/255545/

IvanSanchez commented 6 years ago

Your vector tiles do not have any margin, and the polygons are cut exactly at the tile boundary. Research the buffer option in geojson-vt, as well as this paragraph from the vector tiles spec:

A layer MUST contain an extent that describes the width and height of the tile in integer coordinates. The geometries within the Vector Tile MAY extend past the bounds of the tile's area as defined by the extent. Geometries that extend past the tile's area as defined by extent are often used as a buffer for rendering features that overlap multiple adjacent tiles.

You don't want to dissolve anything. You want your polygons to be clipped in such a way that the coordinates in each tile are slightly outside of the tile.

This is a case of GIGO, and not a bug in vectorgrid.

yellowcap commented 6 years ago

Thanks for pointing me in the right direction, @IvanSanchez . You were right, clipping the geometries against a tile with margin solved the problem. I am new to vector tiles and did not understand that this was how the tiles are rendered. I assumed they were dissolved by id on the front-end. But this is quite elegant and efficient!