以下代码中是否有明显缺失的内容?我没有为渲染到矢量图块的地图图层添加样式,因为我认为矢量图块实际上并未在服务器上“渲染”,这是问题吗?谢谢你的回答,
pgMapRouter.get('/:z/:x/:y.pbf', function(req, res) {
var bbox = mercator.bbox(
+req.params.x,
+req.params.y,
+req.params.z,
false,
'4326'
);
var map = new mapnik.Map(256, 256);
map.extent = bbox;
var layer = new mapnik.Layer('fixture_layer');
layer.datasource = new mapnik.Datasource({
type: 'postgis',
dbname: 'citydb',
table: 'test2',
user: 'postgres',
password: 'postgres',
host: 'localhost',
port:5432,
geometry_field: 'wkb_geometry',
srid:4326,
extent: bbox
});
map.add_layer(layer);
var vtile = new mapnik.VectorTile(+req.params.z, +req.params.x, +req.params.y);
map.render(vtile, function (err, vtile) {
if (err) console.log(err);
res.setHeader('Content-Encoding', 'deflate');
res.setHeader('Content-Type', 'application/x-protobuf');
zlib.deflate(vtile.getData(), function(err, pbf) {
console.log(mapnik.VectorTile.info(pbf))
res.send(pbf);
});
});
});