vector Tile To Geo Json
vectorTileToGeoJson generates a GeoJSON FeatureCollection from a Mapbox Vector Tile.
Parameters
is the x coordinate of the tile
is the y coordinate of the tile
is the Tile which has been decoded from the protobuf on its way into the application
is a flag to indicate whether or not crop points to be within the tile
defaults to ZOOM_LEVEL but can be forced to 15 to run unit tests even when the backend is not configured to be protomaps.
There are really two parts of this function:
Iterating over the features in each layers and turning their tags and geometries into GeoJSON. This is done by 'simply' following the MVT specification.
Adding some locally calculated metadata e.g. the location of intersections, and adding the ability to knit together lines that cross tile boundaries.
The input tile geometries are all tile relative and using tileX
and tileY
we turn those into latitudes and longitudes for the GeoJSON. Although the locally calculated metadata could be done as a second pass after the initial parsing has been done, it's much more efficient to do them in a single pass. By doing that the geometries are still tile relative and much easier to handle than latitudes and longitudes.
The vector tiles come from a protomaps server which is hosting a map file that we generate using planetiler
. A stock running of planetiler
is missing some data that we need, so we disable simplification at the maximum zoom level (which is what we're using here) and we also force the addition of a Feature id on all Features within the transportation layer. This allows us to more easily identify roads and paths for intersection handling. We also add a name tag to every feature in the transportation layer. This ensures that we always have an OSM id and a name where there's one available. The transportation_name
layer is left unused and so its merging of lines to improve the graphical UI is untouched. Note that these changes are only in our builds and won't be in upstream planetiler
. None of these changes should affect the graphical rendering of the tiles which is important as we're using the tiles for that too.
This means that we only look at 2 layers which are defined here https://openmaptiles.org/schema/:
transportation
contains all footways/roads etc. including named and unnamed and so is a superset oftransportation_name
. We use the lines from this and along with the names which we added in our custom map.poi
contains points of interest.