Reputation: 1362
I'm trying to build my own vector tile server using Mapnik. Now I've created a XML style using Tilemill and exported this to include in the Mapnik node server.
Below the code of the server to render te .mvt
tiles.
app.get('/tiles/:z/:x/:y.mvt', (req, res, next) => {
var projection = '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs';
var map = new mapnik.Map(256, 256, projection);
map.load('./mapgather-style/mapgather.xml', {strict: false}, function(err, map) {
if(err) {
console.log(err);
}
let vtile = new mapnik.VectorTile(parseFloat(req.params.z), parseFloat(req.params.x), parseFloat(req.params.y));
map.render(vtile, {}, function(err, response) {
if (err) { console.log(err) }
res.setHeader('Content-Encoding', 'deflate');
res.setHeader('Content-Type', 'application/vnd.vector-tile');
zlib.deflate(response.getData(), (err, mvt) => {
if(err) { console.log(err) }
res.send(mvt);
});
})
})
})
I've also created a Leaflet map with the leaflet.vectorgrid
plugin for rendering the vector tiles. The http://localhost:8080/tiles/{z}/{x}/{y}.mvt
request returns the tiles, but without any styes.. Only blue lines as you can see on the screenshot below.
I've figured out that I can style the tiles using the Vector grid plugin. But I'm wondering if it is possible to pre-render the style from the server. In Tilemill I've created a style, but it seems that Mapnik doesn't include this style in the .mvt
response.
Is it possible at all to pre-render the map styles? Hope someone can help!
Upvotes: 1
Views: 596