recogito / geotagger

Recogito Geotagging Plugin
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Map download #5

Open eltonteb opened 5 months ago

eltonteb commented 5 months ago

Facility to be able to get a PDF of a map of the annotations in a document

rsimon commented 5 months ago

A full solution for this will remain out of reach for the foreseeable future, I'm afraid. It would require a bigger investment. Both in terms of development time, as well as with regard to maintaining it as a production setup (see below).

A smaller, limited solution, however, is possible: I managed to get halfway decent results with the html2canvas JavaScript library. With some limitations, html2canvas allows you to create programmatic screenshots in the browser. See, for example this actual screenshot...

Bildschirmfoto 2024-04-03 um 16 00 52

...and the programmatic rendering, a PNG file generated with html2canvas for just the map element.

filename (5)

I think this is a reasonable workaround for now. But keep in mind that html2canvas is limited to generating an image exactly as things appear in the browser. That includes properties such as same aspect ratio and (more or less) resolution. I believe enhancements would be possible. (Such as opening another much larger Leaflet map in an offscreen page element, and then letting html2canvas render a "screenshot" of this element instead.) But this would take more work & experimentation.

Notes on a server-side solution: a full solution for producing a print-quality image, with user-configurable size/aspect ratio would likely involve a server-based solution. The server would have to run something like headless Chrome, which could then generate large raster images, based on a set of input parameters (map base-layer, map bounds, GeoJSON data overlay, etc.) After rendering the high-res raster image, exporting it to different formats (JPG, PDF, etc.) would be the easy part.

Overall, development effort for such a solution would be much more significant, and deployment & maintenance of the combined system would become more complex.

rsimon commented 5 months ago

P.S.: the PNG screenshot feature is now available on the test instance.

rsimon commented 5 months ago

Update: html2canvas will only work if map tiles are fetched with a specific HTTP setting. This setting is now enabled in the geotagger plugin.

However, with this setting enabled, map tiles are only displayed if, in turn, the tile server explicitly allows cross-domain requests (by setting the appropriate HTTP header in their responses: Access-Control-Allow-Origin: *). This is typically the case for open tile servers (OpenStreetMap, Digital Atlas of the Roman Empire, etc.)

The CAWM tile server, however, does not have this setting enabled. This means their map tiles now show blank in the Recogito user interface. I have therefore removed CAWM from the list of pre-set basemap choices.

@eltonteb: do you have any active contacts at the CAWM? If so, we could ask them if they can enable the Access-Control-Allow-Origin: * HTTP response header on their end.