Rothamsted-Ecoinformatics / farm_rothamsted

Custom farmOS features for Rothamsted Research.
GNU General Public License v2.0
6 stars 1 forks source link

Mapping: Print maps from viewer #669

Open aislinnpearson opened 5 months ago

aislinnpearson commented 5 months ago

I was talking with one of the farm staff today who wanted to print a map directly from the map viewer (we had to screenshot it and then print it).

It would be great if we could print directly to PDF from the map viewer, if that is possible.

image

paul121 commented 4 months ago

https://openlayers.org/en/latest/examples/export-pdf.html

paul121 commented 4 months ago

Hey @aislinnpearson we looked into this a bit more today during the monthly call and learned some nice tid-bits... its looking like this won't be too hard! cc @mstenta

Basically the browser itself has some nice features which help us to generate and download images of the map in multiple formats png, jpeg, webp. But then there are few options on how we get to a PDF format... the complexity with generating a PDF is that we need to choose additional PDF settings like paper/page size, orientation, etc. I'll try to lay out the options (all will work with the dashboard or full-screen map):

The simplest option is to just download a simple image file. We can make it easy to generate this image and not need a screenshot or print screen. You should be able to open it in the image viewer on your computer and "Print to PDF" (or even print directly) with configured paper/page settings - likely with better support/features than we could provide generating the PDF ourselves!

Alternatively, I've found a kind of middle-ground solution for this with the printjs library. This library does some tricks and allows us to open the browser's "Print" dialog for any image on the current page, including the generated image from the map. From this print dialog you can "Print to PDF" (if your computer supports it). This will limit some of the PDF settings but still lets you change things before printing. It seems like this should work well!

  1. Image file download (easiest) map-normal

  2. Helper to print image file, with option to print as PDF (medium) printjs-example

  3. Generate a PDF in browser (like the example above, most complex) Screenshot from 2024-07-10 16-15-40

aislinnpearson commented 4 months ago

Hi @paul121,

I think the important thing here is to be able to print the map - the file format isn't as important to us.

All three of those options would work and be an improvement on the current process, but when I spoke to Helen and Tim they said their preference would be for option 2 because (1) it's intuitive (that's pretty much how you print from Google maps or a web page at the moment) and (2) it's easy enough to change the layout settings on the computer. Again, probably actually more intuitive to do it that way, given it's what people are used to.

If anything, option 3 seems to me to be a bit over-engineered, but it is great to know it exists should we find more user requests for that kind of thing in the future,

The one other thing they suggested is that it would be nice to visualize the asset names, but I feel like we have discussed this before and it needs to be a completely separate issue?

paul121 commented 4 months ago

I've got a PR that adds approach #2 - working quite well I think! :D farmos/farmos-map/pull/202

Screenshot from 2024-07-12 13-35-07