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
155 stars 76 forks source link

Print map size follow screen size #56

Closed habibr closed 5 years ago

habibr commented 5 years ago

I need to print the map not as defined A or B sizes. Rather, the print should follow the size of the displayed map in the client's screen. Is it possible to do so?

Igor-Vladyka commented 5 years ago

Hi there.

How do you think this should work? Do your client have any other page formats on his printer?

Regards, Igor

habibr commented 5 years ago

No, sorry, I mean not printing on printer. I should rephrase my question: I need to save image of the map with sizes and orientation following the client's screen.

Igor-Vladyka commented 5 years ago

There is a way, but some adjustments needed. Please wait couple of days to be updated.

Igor-Vladyka commented 5 years ago

Best way for now for you is to use something like next: L.control.browserPrint.mode("Auto", "Export image", "EI", function(context) { return function() { // hide print control from curent map var control = document.querySelector(".leaflet-control-browser-print"); control.style.visibility = "hidden"; // actula export image logic; setTimeout(function(){ domtoimage .toPng(document.querySelector("#map"), { height: map._container.clientHeight, width: map._container.clientWidth }) // query actual print map container, or any other needed container to print .then(function (dataUrl) { var link = document.createElement('a'); link.download = map.printControl.options.documentTitle || "exportedMap" + '.png'; link.href = dataUrl; link.click(); control.style.visibility = ""; }); }, 1); }}, false),

It's additional printMode that you can use to export map as it is. Just play with a sizes.

habibr commented 5 years ago

Thank you Igor, that code worked very well for my purpose.