node-mapnik-sample-code
node-mapnik-sample-code copied to clipboard
Example Code for PostGIS to VectorTile?
Could we get some example code for the right way to do PostGIS -> VectorTile? RIght now my app feeds it through the stylesheet for the datasource, but since none of the style information (color, text) it doesn't seem necessary.
Feeding in a Mapnik XML is the right way to generate vector tiles. You are correct that the style information in this case is ignored - however there is no harm to it being in the style still.
The critical thing when generating vector tiles is to avoid querying too much or unneeded data in your Mapnik XML datasource definitions. This is the same for when rendering image tiles if you care about performance, but it becomes even more critical with vector tiles since you want to avoid them being too large. Mapbox.com for example will not allow you to upload individual tiles > 500 Kb for example (at the time of this writing).
To avoid "querying too much" you want to be thoughtful about your SQL queries. And you likely want to use min/max zoom denominators. The Mapbox Studio Classic project helps you author Mapnik XML styles with <Layers> like this that restrict zoom. There are also probably other tools out there that make this easier. Take a look at https://github.com/mapbox/awesome-vector-tiles/. I noticed (when looking at that myself) that https://github.com/faradayio/tilesplash might be interesting to you.
So the reason it goes through the Mapnik XML is to pick up the datasource, correct? What if we generate the datasource via the api (mapnik.Datasource())? The only code that's in the xml stylesheet is the actual style rules for raster tiles.
As for "querying too much", I'm unclear on how to use the denominators as passing variables through the options object for map.render() does not work for either vector or raster tiles (results in a null value where the token is), or why this is a good use case. Regardless, we're doing this some already on the viewing end in leaflet by restricting min zoom.
Side issue: size in our vector tiles is a bit of an issue (I've seen ~240kb for a pbf with un-gzipped data, where same tile was ~30kb for the png version and ~90kb for a fully compressed data pbf) as we deal with weather contours and they're fairly complex. Where is the performance benefit to vectors at this point? The browser render end?
Node 7.10 Node Mapnik 3.6
/cc @ddproxy