Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
});
// See http://github.com/CartoDB/Windshaft/issues/100
var test_strictness = function(done) {
var nonStrictMapConfig = TestClient.singleLayerMapConfig(
"SELECT 1 as cartodb_id, 'SRID=3857;POINT(666 666)'::geometry as the_geom",
"#test_table{point-transform: 'scale(100)';}"
);
var testClient = new TestClient(nonStrictMapConfig);
testClient.getTile(0, 0, 0, {strict: 1}, function(err) {
assert.ok(err);
done();
});
};
var test_strict_lbl = "unused directives are not tolerated if strict";
if ( semver.satisfies(mapnik.versions.mapnik, '2.3.x') ) {
// Strictness handling changed in 2.3.x, possibly a bug:
// see http://github.com/mapnik/mapnik/issues/2301
console.warn("Strictness test skipped due to http://github.com/mapnik/mapnik/issues/2301");
it.skip(test_strict_lbl, test_strictness);
}
else {
it.skip(test_strict_lbl, test_strictness);
}
it('high cpu regression with mapnik <2.3.x', function(done) {
var sql = [
"SELECT 'my polygon name here' AS name,",
"st_envelope(st_buffer(st_transform(",
"st_setsrid(st_makepoint(-26.6592894004,49.7990296995),4326),3857),10000000)) AS the_geom",
"FROM generate_series(-6,6) x",
"UNION ALL",
it('should allow a rendering vector tiles and raster images to an image', function(done) {
// first we create a vector tile on the fly
var vtile_global = new mapnik.VectorTile(0,0,0);
var map = new mapnik.Map(256,256,'+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over');
map.extent = [-20037508.34, -20037508.34, 20037508.34, 20037508.34];
var global = new mapnik.Layer('global',map.srs)
var options = {
type: 'shape',
file: './test/data/world_merc.shp',
encoding: 'iso-8859-1'
};
global.datasource = new mapnik.Datasource(options);
map.add_layer(global);
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
it('should render semi transparent green image', function(done) {
var mask = new mapnik.Image(256,256);
var semi_green = new mapnik.Color('rgba(0,255,0,.5)');
mask.background = semi_green;
mask.premultiply();
var sources = [ {'name':'hello','image':mask } ]
var map = new mapnik.Map(256,256);
map.add_layer(new mapnik.Layer('hello'));
mapnik.render(0,0,0,map,new mapnik.Image(256,256),sources,{},function(err,im) {
if (err) throw err;
assert.ok(im instanceof mapnik.Image);
assert.equal(im.width(),256);
assert.equal(im.height(),256);
assert.equal(im.painted(),false); // true?
var view = im.view(0,0,256,256);
assert.equal(view.isSolid(),true);
assert.equal(view.getPixel(0,0).toString(),semi_green);
done();
it('should allow a rendering vector tiles and raster images to a vector tile', function(done) {
// first we create a vector tile on the fly
var vtile_global = new mapnik.VectorTile(0,0,0);
var map = new mapnik.Map(256,256,'+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over');
map.extent = [-20037508.34, -20037508.34, 20037508.34, 20037508.34];
var global = new mapnik.Layer('global',map.srs)
var options = {
type: 'shape',
file: './test/data/world_merc.shp',
encoding: 'iso-8859-1'
};
global.datasource = new mapnik.Datasource(options);
map.add_layer(global);
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"));
const im: mapnik.Image = new mapnik.Image(256, 256);
map.render(im, function xxx(err: Error, im: mapnik.Image) {
if (err) throw err;
im.encode('png', function xxxx(err: Error, buffer: Buffer) {
if (err) throw err;
fs.writeFile('map.png', buffer, function xxxxx(err: Error | null) {
if (err) throw err;
console.log('saved map image to map.png');
});
});
});
});
// new mapnik.Image.open("xxx").save("xx");
mapnik.register_datasource(path.join(mapnik.settings.paths.input_plugins, 'shape.input'));
const ds: mapnik.Datasource = new mapnik.Datasource({type: 'shape', file: 'test/data/world_merc.shp'});
const featureset: mapnik.Featureset = ds.featureset();
const geojson: any = {
type: "FeatureCollection",
features: [
]
};
let feat: mapnik.FeaturesetNext = featureset.next();
while (feat) {
geojson.features.push(JSON.parse(feat.toJSON()));
feat = featureset.next();
}
fs.writeFileSync("output.geojson", JSON.stringify(geojson, null, 2));
it('should render semi transparent green image', function(done) {
var mask = new mapnik.Image(256,256);
var semi_green = new mapnik.Color('rgba(0,255,0,.5)');
mask.background = semi_green;
mask.premultiply();
var sources = [ {'name':'hello','image':mask } ]
var map = new mapnik.Map(256,256);
map.add_layer(new mapnik.Layer('hello'));
mapnik.render(0,0,0,map,new mapnik.Image(256,256),sources,{},function(err,im) {
if (err) throw err;
assert.ok(im instanceof mapnik.Image);
assert.equal(im.width(),256);
assert.equal(im.height(),256);
assert.equal(im.painted(),false); // true?
var view = im.view(0,0,256,256);
assert.equal(view.isSolid(),true);
assert.equal(view.getPixel(0,0).toString(),semi_green);
done();
});
});
it('should render blank transparent image', function(done) {
var sources = [ {'name':'hello','image':new mapnik.Image(256,256) } ]
mapnik.render(0,0,0,new mapnik.Map(256,256),new mapnik.Image(256,256),sources,{},function(err,im) {
if (err) throw err;
assert.ok(im instanceof mapnik.Image);
assert.equal(im.width(),256);
assert.equal(im.height(),256);
assert.equal(im.painted(),false); // true?
var view = im.view(0,0,256,256);
assert.equal(view.isSolid(),true);
assert.equal(view.getPixel(0,0).toString(),new mapnik.Color(0,0,0,0).toString());
done();
});
});
it('should render semi transparent green image', function(done) {
var mask = new mapnik.Image(256,256);
var semi_green = new mapnik.Color('rgba(0,255,0,.5)');
mask.background = semi_green;
mask.premultiply();
var sources = [ {'name':'hello','image':mask } ]
var map = new mapnik.Map(256,256);
map.add_layer(new mapnik.Layer('hello'));
mapnik.render(0,0,0,map,new mapnik.Image(256,256),sources,{},function(err,im) {
if (err) throw err;
assert.ok(im instanceof mapnik.Image);
assert.equal(im.width(),256);
assert.equal(im.height(),256);
assert.equal(im.painted(),false); // true?
var view = im.view(0,0,256,256);
assert.equal(view.isSolid(),true);
assert.equal(view.getPixel(0,0).toString(),semi_green);
done();
});
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 vector tile
var sources = [vtile_global,{'name':'raster','image':raster},japan_vtile];
var opts = {scale:1.0,buffer_size:256};
var map_composite = new mapnik.Map(256,256);
map_composite.loadSync('./test/data/render-composite/composite.xml');
var z = 5;
var x = 28;
var y = 12;
mapnik.render(z,x,y,map_composite,new mapnik.VectorTile(z,x,y),sources,opts,function(err,v) {
if (err) throw err;
var actual = './test/data/render-composite/composite-actual.json';
var expected = actual.replace('actual','expected');
fs.writeFileSync(actual,JSON.stringify(v.toJSON(),null,1));
assert.equal(fs.readFileSync(actual).length,
fs.readFileSync(expected).length);
done();
});
});
});
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