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

Is there a way to optimize rendering the same tile in multiple resolutions? #123

Open zdila opened 5 years ago

zdila commented 5 years ago

We render tiles in multiple scales (resolutions): 1x, 2x and 3x. For every scale we render it separately using node-mapnik like this:

await Promise.all([
  renderSingleScale(1),
  renderSingleScale(2),
  renderSingleScale(3),
]);

async function renderSingleScale(scale) {
  const im = new mapnik.Image(256 * scale, 256 * scale);
  const map = ... // get mapnik.Map from pool
  map.resize(256 * scale, 256 * scale);
  map.zoomToBox(...);
  await map.renderAsync(im, { buffer_size: 256, scale });
  // release map from pool...
  const buffer = await im.encodeAsync('png');
  // write buffer to file...
}

This is like rendering 3 tiles separately proably without any special resource sharing.

One idea was to render only the largest scale and then rescale the image but it worses the quality as for example POI icons are no more pixel aligned.

So, is there a way to optimize it?

Thanks in advance!

zdila commented 4 years ago

Probably what we need is something like sharing selected data (eg. from PostGIS) between multiple renders.