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

Don't require "preferCanvas" #2

Open
nrenner opened this issue Jul 5, 2022 · 2 comments
Open

Don't require "preferCanvas" #2

nrenner opened this issue Jul 5, 2022 · 2 comments

Comments

@nrenner
Copy link

nrenner commented Jul 5, 2022

The readme says:
var map = L.map("map", {preferCanvas: true}); // IMPORTANT: preferCanvas must be true!

This is a bit of a no-go for me. I tried that before and reverted because moving vectors was laggy. It can also have unintended side effects for other plugins.

What is preferCanvas needed for?

leaflet-image doesn't really require that:

For Leaflet >= 1.0.0: You must set renderer: L.canvas() for any layer that you want included in the generated image.

@hersle
Copy link
Owner

hersle commented Jul 8, 2022

Thank you, I see that it isn't really needed to configure the whole map with preferCanvas. What is needed, however, is that at the end of the day, each element that is to be included in the print must somehow be rendered with Leaflet's Canvas renderer, but it is sufficient to configure this on a per-element basis rather than all-element basis. For now I will remove the requirement from the readme, and rather simply pass on leaflet-image's requirement of using the Canvas renderer to the users of the library.

Ideally, though, I would like the library to function in a WYSIWYG-manner and relieve the user of thinking about such technical requirements. I suppose the only way to achieve this would be to clone a general map (rendered with a mix of SVG and Canvas renderers) to a seemingly identical map in which all layers are recreated and rendered with the Canvas renderer. But my instincts tell me that this is not the right way to go about things, would be inefficient and inelegant, and perhaps is not even possible.

A middleway and straightforward approach could be to clone only the polyline of the route that is to be printed, but then details such as line color, line thickness and other elements such as markers would not be included, in general.

Do you have any ideas on handling this, either from the "internal" perspective of the library, or the "external" point of view of its users?

@nrenner
Copy link
Author

nrenner commented Jul 12, 2022

[...] rather simply pass on leaflet-image's requirement of using the Canvas renderer to the users of the library.

Yes, that's fine.

A middleway and straightforward approach could be to clone only the polyline of the route that is to be printed,

I actually thought you were doing that, but passing the route (routePrinter.setRoute(line);) is probably just to determine the pages.

Do you have any ideas on handling this, either from the "internal" perspective of the library, or the "external" point of view of its users?

My first thought was, that client-side printing should be using a vector tile renderer, which already renders everything in a WebGL canvas and would allow to render sharp images at exactly 300 dpi.

We just recently included MapLibre GL JS with MapLibre GL Leaflet and use dynamic import() to lazy load only when needed.

The problem is, that there are no free vector tile providers and that there is only a limited number of styles available, which also lack the detail of raster styles like openstreetmap-carto.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants