Provides an API to render Alvar Carto map posters.
This service depends on Mapnik server (https://github.com/gravitystorm/openstreetmap-carto/blob/master/INSTALL.md). It's non-trivial to install, so it has been automated in this repository.
To get started:
npm run bash
to enter bash inside docker.npm install
- Exit back to host
docker-compose up
Warning: posters are built into posters/dist, and the final poster images contain absolute system paths to referenced png images!
- Render a map with a resolution which will result to a 300DPI print
- Apply label overlay (SVG) on top of the rendered map
These SVG canvases should match the rendered map images pixel perfect.
The labels in SVGs are following a certain ID convention so they can be dynamically replaced with a DOM parser/modifier.
- Save the combined huge image
The render service supports different output formats. They are rendered differently based on the format.
-
Render the given map as png image with Mapnik. (or tile renderer)
-
Render the poster style SVG as png image. (transparency is needed until this point)
We use the
-server.svg
version here to use the properly dithered pre-made gradient to avoid gradient banding when printing. See this issue for more: lovell/sharp#867 -
Combine these images and possible re-encode to JPG
-
Render map as SVG with Mapnik.
-
Take the poster style SVG string and inject map SVG into the lowest layer of the SVG (under the overlay).
We use the
-client.svg
version here. Beware of gradient banding when printing. -
If render was done without labels, add a white padding on top of the map.
Correct fonts are required for the viewer. Maybe embed fonts as base64?
- Render the poster as PNG exactly as mentioned in PNG / JPG method.
- Wrap the poster into a PDF file, crafted so that the image will be 300dpi when printed.
- Render the map as PDF with Mapnik.
- Render the poster style SVG as PDF vector graphic (with automatic svg to pdf conversion).
- Combine the two PDFs so that map layer is under the overlay.
- If render was done without labels, add a white padding on top of the map.
Fonts need to be embedded in the PDF.
- SVG doesn't embed fonts
- https://www.npmjs.com/package/text-to-svg
- Font rendering in vector PDF to support texts which has glyphs from different fonts (this works with other render methods)