我使用PostGIS从自定义动态node-mapnik磁贴服务器成功渲染和提供美国县级.pbf磁贴,但现在我还想渲染并提供topojson和/或geojson磁贴服务器。有没有办法扩展下面的代码示例(gist中的完整示例)以geojson或甚至更好的topojson格式返回切片?
https://gist.github.com/nautilytics/75cbbb2d854de608e81c
map.render(new mapnik.VectorTile(+params.z, +params.x, +params.y), opts, function (err, image) {
if (err || !image) {
res.removeHeader('Content-Encoding');
res.writeHead(500, {
'Content-Type': 'application/x-protobuf'
});
res.end();
return;
}
// Fake empty RGBA
image.isSolid(function (err, solid, key) {
if (err) {
res.writeHead(500, {
'Content-Type': 'text/plain'
});
res.end(err.message);
return;
}
// Solid handling.
var done = function (err, buffer) {
if (err) {
res.writeHead(500, {
'Content-Type': 'text/plain'
});
res.end(err.message);
return;
}
if (solid === false) {
res.send(buffer); // return response
return;
}
// Empty tiles are equivalent to no tile.
if (!key) {
res.removeHeader('Content-Encoding');
res.writeHead(404, {
'Content-Type': 'application/octet-stream'
});
res.end(); //new Buffer('Tile is blank or does not exist', "utf-8")
return;
}
// Fake a hex code by md5ing the key.
var mockrgb = crypto.createHash('md5').update(buffer).digest('hex').substr(0, 6);
buffer.solid = [parseInt(mockrgb.substr(0, 2), 16), parseInt(mockrgb.substr(2, 2), 16), parseInt(mockrgb.substr(4, 2), 16), 1].join(',');
res.send(buffer);
};
//Compress
res.setHeader('content-encoding', 'gzip');
zlib.gzip(image.getData(), done);
});
});