const mapnik = require('mapnik');
const sphericalmercator = require('@mapbox/sphericalmercator');


const TILE_HEIGHT = 256;
const TILE_WIDTH  = 256;

const SRS_MERC = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over";

const mercator = new sphericalmercator({
    size: TILE_WIDTH

var map = new mapnik.Map(TILE_WIDTH, TILE_HEIGHT, SRS_MERC);
map.background = new mapnik.Color(255, 255, 255, 0); 
var style = ` 
  <Style name="census_wards">
      <PolygonSymbolizer fill="#00ffff" fill-opacity="0.75"  />  
      <LineSymbolizer stroke="#000000" stroke-width="0.5" stroke-opacity="1.0"  />  
var postgis = { 
  'type': 'postgis',
  'dbname': 'test_db',
  'host': '',
  'user': 'test_map',
  'password': 'TestUser',
  'table': '(SELECT * FROM z4.census_wards) AS census_wards',
  'geometry_field': 'the_geom_webmercator'

var layer = new mapnik.Layer('census_wards', SRS_MERC);
layer.datasource = new mapnik.Datasource(postgis);
layer.styles = ['census_wards'];

var box = mercator.bbox(2940, 1846, 12, false, '900913');
console.log('box = ' + box);

var im = new mapnik.Image(TILE_WIDTH, TILE_HEIGHT);
map.render(im, function(err, im) {
    console.log('inside render');
    if (err) throw err;

Control never reaches the "console.log('rendering');" line. Couple of days ago something like this was working. I am assuming that I am missing a very simple but important part due to my lack of experience with node and mapnik.

Apart from the console.log output, there is no response from the program. No errors, no other output.

Any pointers on how to get this working?

1 Answer 1


The problem was with the last line


map.render is a non-blocking function call. Callback given as a parameter to that function will be invoked only when the render is complete. But, process.exit(0) is called immediately after map.render. Hence render was not completed and callback was not invoked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.