Igor-Vladyka / leaflet.browser.print

A leaflet plugin which allows users to print the map directly from the browser
https://igor-vladyka.github.io/leaflet.browser.print/
MIT License
154 stars 76 forks source link

Print dialogue does not open when fully zoomed in #113

Closed petersteele111 closed 1 year ago

petersteele111 commented 2 years ago

Describe the bug So we noticed that when zoomed all the way in, on anything other than street view with Google and even in the official demo, selecting an area will cause the selection to be all gray and the feature hangs up and will not open the print dialogue. Custom icons and other layers appear, but the print dialogue does not open and the tiles behind the scene for the map itself are just gray and seems to cause the plugin to stop working unless the page is reloaded.

To Reproduce Steps to reproduce the behavior:

  1. Zoom all the way into the map
  2. Select an area manually or by auto
  3. You will get an all gray preview screen for the map tiles and only see your markers, lines, and polygons and the print dialogue never opens up.

Expected behavior The expected behavior is that it would capture the area selected and open the print dialogue with the map tiles visible. Markers, lines, and poly's do appear, but the map tiles are greyed out and the print dialogue never opens up.

Screenshots 1.) Zoomed all the way in Pic 1 2.) Select an area Select Area 3.) Following Screen Gray Map, no print Dialogue 4.) Console warning on Demo Site Console Warning

Desktop (please complete the following information):

Additional context This happens regardless if you manually select an area or just let it auto select. We have been using this plugin for some time but have only just now noticed this issue. Backing off one or 2 zoom levels, it works as intended. I have used the official demo site for these screenshots just to show it is not a limitation in our implementation or usage.

I did notice that the printLayer was null in the third screenshot and wonder if it has something to do with the fact that a full map tile is not being captured and that's causing issues?

Igor-Vladyka commented 2 years ago

Hey Peter.

This is an interesting catch. I will check it out and let you know.

petersteele111 commented 2 years ago

Hey Peter.

This is an interesting catch. I will check it out and let you know.

Thanks, so we noticed that, at least with Google and presumably OpenStreetMaps, it doesn't load tiles for satellite and hybrid view past zoom level 20. For roadmap or streetview as its called, its level 22. At level 20, it starts scaling the tiles that are loaded, but when rebuilding the map to print, it is unable to load the tiles at the specified zoom level beyond 20. I am assuming the openstreet maps has a similar limitation since it was doing the same thing in your demo. For now, our workaround was to manually set the newMapOption.maxZoom variable to 20. This allows us to still allow a higher level of zoom for our users on the map, but when they go to print, it will default to level 20 for printing purposes, if their native zoom is higher than 20, so those satellite tiles will actually get loaded in.

Temporary fix

As you can see, around line 510 is where we had to set this hard coded instead of using the this._map.getMaxZoom so that the tiles would actually get loaded.

It would ne nice, if we could load the tiles to level 20 so they actually get loaded, and then scale it to the higher zoom to simulate what the user sees on the map if possible. If not, it may just be a limitation of the tile provider that can't be worked around. We thought about just taking a screenshot as well and printing that for the higher zoom levels. So that may be an option to get around this limitation.

I know this might be an edge case regarding printing, but we do GIS stuff with the map, and clients really want to be able to print as close as possible to show their assets hence how we came across this bug. We've been using this plugin for some time, and really appreciate the hard work you put into creating it. It's awesome and I'm surprised we are only just now noticing this.

Igor-Vladyka commented 2 years ago

Hey Peter.

I'm not sure about your actual tiles providers that you are using (each tile server has it's own zoom levels, based on need and infrastracture to support it) therefore not sure what is your best approach to go here.

Right now I have fixed the problem, now maxZoom will be taken from the printLayer or from the map itself. At least it fixed the use case that can be reproduced in my demo.

You can check it out, and If it's not sufficient for you, please share your demo(jsbin or something else) with reproducible issue so I can take a look.

petersteele111 commented 2 years ago

Thanks, I haven't had a chance to mess with this yet. We are still using our fix right now of just setting the max zoom to 20 and it is working fine for us. I will take a look at it soon though and see if it fixes the issue for us by default. Thanks again for the speedy response and I will let you know how it goes!