Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
map.render(vtile_global,{},function(err, vtile_global) {
if (err) throw err;
// ensure the vtile contains one layer named 'global'
assert.deepEqual(vtile_global.names(),['global']);
// now load a vector tile for some deeper zoom level
// in this case we grab a tile for japan from the tests
var japan_vtile = new mapnik.VectorTile(5,28,12);
japan_vtile.setData(fs.readFileSync("./test/data/vector_tile/tile3.vector.pbf"));
// ensure the vtile contains one layer named 'world'
assert.deepEqual(japan_vtile.names(),['world']);
// now load up a raster image to composite into the final rendered image
// 128 is used here just for testing purposed - you will want to stick to 256 px images
var raster = new mapnik.Image(128,128);
// semi transparent blue
raster.background = new mapnik.Color('rgba(0,0,255,.5)');
// image has alpha so it needs to be premultiplied before passing into renderer
raster.premultiply();
// okay, sweet, now render these various sources into a new image
// NOTE: order of sources does not matter, what matters is the order
// of the layers in the mapnik.Map (which must match sources by name)
// EXCEPT if multiple sources provide data for the same layer name - in this
map.fromString(xml, {}, (err, res) => {
if (err) {
console.error('style error', err)
}
let vt = new mapnik.VectorTile(z, x, y);
map.render(vt, (err, vt) => {
if (err) {
console.error('render error', err);
}
ctx.set('Content-Type', 'application/x-protobuf');
ctx.response.status = 200;
vt.getData((err, data) => {
if (err) {
console.log('err', err);
}
ctx.body = data;
resolve();
});
});
});
})
Tile.prototype.renderToVector = function (project, map, cb) {
this.setupBounds();
map.zoomToBox(this.projection.forward([this.minX, this.minY, this.maxX, this.maxY]));
var surface = new mapnik.VectorTile(this.z, this.x, this.y);
map.render(surface, {buffer_size: this.buffer_size}, cb);
};
if (err) {
callback( err, null );
mapnik.pools[ mapKey ].release( map );
} else {
im.encode( 'png', function( err, buffer ) {
fs.writeFile( file, buffer, function( err ) {
mapnik.pools[ mapKey ].release( map );
callback( null, file );
});
});
}
});
} else if ( params.format == 'pbf' ){
var vtile = new mapnik.VectorTile( parseInt(params.z), parseInt(params.x), parseInt(params.y) );
map.render( vtile, {}, function( err, vtile ) {
if (err) {
callback( err, null );
mapnik.pools[ mapKey ].release( map );
} else {
fs.writeFile( file, vtile.getData(), function(){
mapnik.pools[ mapKey ].release( map );
callback( null, file );
});
}
});
}
});
VectorTile.prototype.render = function (project, map, cb) {
this.setupBounds();
map.zoomToBox(this.projection.forward([this.minX, this.minY, this.maxX, this.maxY]));
var surface = new mapnik.VectorTile(this.z, this.x, this.y);
return map.render(surface, {buffer_size: 0}, cb);
};
function migrate(tile, callback) {
var vtile;
try {
vtile = new mapnik.VectorTile(tile.z, tile.x, tile.y);
} catch (err) {
if (err && err.message.indexOf('required parameter y is out of range') != -1 || err && err.message.indexOf('required parameter x is out of range') != -1) {
err.code = 'EINVALID';
err.message = `Tile ${tile.z}/${tile.x}/${tile.y} is an invalid ZXY range.`;
}
return callback(err);
}
vtile.setData(tile.buffer, {upgrade:true}, function(err) {
if (err) {
err.code = 'EINVALID';
return callback(err);
}
vtile.getData({compression:'gzip'},function(err, data) {
if (err) return callback(err);
tile.buffer = data;