Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to print or export vector graphics #1141

Open
1ec5 opened this issue Jul 25, 2024 · 0 comments
Open

Add option to print or export vector graphics #1141

1ec5 opened this issue Jul 25, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@1ec5
Copy link
Member

1ec5 commented Jul 25, 2024

Occasionally we get requests to be able to print out OSM Americana or export the map as vector graphics for post-production prior to printing. By default, the MapLibre GL JS map doesn’t support either print or vector output because it blits directly to a WebGL canvas.

Implementation

We can easily enable printing by setting the preserveDrawingBuffer option when creating the map:

https://github.com/ZeLonewolf/openstreetmap-americana/blob/0d51830b14a4abe962d345aeb4cd7ff3edd118ec/src/americana.js#L35-L43

However, this option defaults to false for performance reasons, so we’d only want to enable it based on a URL query parameter. Or perhaps we could listen for the beforeprint event and respond by recreating the map with that option enabled. There’s plenty of ornamentation around the map that doesn’t make sense outside the context of the application, which would need to be removed at the same time.

Even with these optimizations, the map can only be printed as is, limited by the resolution supported by WebGL, the window size, and the customization options in the style specification. For more flexibility, we should install the maplibre-gl-export plugin, which lets the user choose a specific bbox and DPI and export the map as either PDF or SVG. I think this would solve the use cases for printing and also give non-programmers more agency to derive cool projects from the map.

Workaround

As a workaround, QGIS effectively features an alternative renderer implementation of the style specification, by translating a stylesheet such as our style.json into QGIS layers. Unfortunately, the translation is very lossy at the moment, particularly because of qgis/QGIS#57989 and also because we apply shields and other important features at runtime.

/ref #1139

@1ec5 1ec5 added the enhancement New feature or request label Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant