mapnik / mapnik-support

Use the issues queue here to ask questions and offer help on using Mapnik (maybe if this works well we can retire the mailing list at http://mapnik.org/contact/?)
6 stars 6 forks source link

Incorrect tiles from a shapefile are generated by mapnik #135

Open dozzes opened 4 years ago

dozzes commented 4 years ago

I used mapnik_node_tile_server to generate tiles from a shapefile created by gdal_contour. The tile generation function is:

function fetchTile(layer, z, x, y, callback) {
  var map = new mapnik.Map(TILE_SIZE, TILE_SIZE); // TILE_SIZE = 256
  var layerPath = util.format('%s/layers/%s.xml', __dirname, layer);
  var tileFilePath = util.format('%s/tiles/%s/%d/%d/%d.png', __dirname, layer, z, x, y)
  var cachedTile = getCachedTile(tileFilePath);
  if (cachedTile) {
    callback(cachedTile);
  } else {
    var filePath = util.format('%s/tiles/%s/%d/%d/', __dirname, layer, z, x);
    mkdirp.sync(filePath);
    map.loadSync(layerPath);
    map.zoomToBox(mercator.bbox(x, y, z, false, '900913'));
    var im = new mapnik.Image(TILE_SIZE, TILE_SIZE);
    map.render(im, function(err, im) {
      if (err) console.log('error', err);
      file = im.saveSync(tileFilePath, 'png');
      callback(fs.readFileSync(tileFilePath));
    });
  }
}

Most of contour lines are not rendered in the tiles and transparent areas are not created correctly. Here is the shapefile drawn in QGIS and generated tiles in CesiumJS respectively.

QGIS_shapefile Cesiumjs_contours

dozzes commented 4 years ago

The reason was in mapnik style xml, I forgot tor remove this line <PolygonSymbolizer fill="white" />