You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Only the standard layer can be exported as an image, but it cannot be either #433
The Share panel’s Image option does not work when any layer is selected.
Problem
The Image option is only enabled if you have OpenStreetMap’s Standard layer selected. Otherwise, if you use another layer such as the Historical layer, this message appears:
Only the standard layer can be exported as an image
But if you switch to the Standard layer and try to share it, it fails with a server error:
Missing or invalid token
Diagnosis
In openstreetmap-website, the image sharing feature is limited to the Standard style because openstreetmap.org is only set up to run Mapnik locally against the openstreetmap-carto style; the other styles are hotlinked from other servers: openstreetmap/openstreetmap-website#1141.
ohm-website doesn’t have the openstreetmap-carto style to work with, so the option should be disabled for the Standard layer. On the other hand, the Historical and Woodblock style are rendered on the client side from vector tiles, so in principle it should be possible for site JavaScript to “export” an image without contacting the server. When setting up GL JS, we can set the preserveDrawingBuffer option and get the map canvas as PNG data when sharing. The option is disabled by default for performance reasons, but maybe we could reinitialize the map when sharing.
The mapbox-gl-export plugin claims to support JPEG, SVG, and PDF in addition to PNG. However, it doesn’t support runtime styling: watergis/maplibre-gl-export#16 (comment). leaflet-ohm-timeslider-v2 relies on runtime styling to filter the tiles by date, so we might need to forego these formats in favor of getting the PNG to look right. But it might be possible to cobble together an animated GIF or APNG that runs through the times specified by the time slider. A timelapse image would really differentiate OHM from OSM.
Impact
Enabling this feature for the Historical and Woodblock styles would make it much easier for a user to share their contributions on social media or tease OpenHistoricalMap’s potential when reaching out to a local historical society by e-mail.
leaflet-ohm-timeslider-v2 relies on runtime styling to filter the tiles by date, so we might need to forego these formats in favor of getting the PNG to look right.
So we think that PNG format will include runtime styling but other formats would not, is that correct?
Sound right based on this from the GL docs:
If true , the map's canvas can be exported to a PNG using map.getCanvas().toDataURL() . This is false by default as a performance optimization.
This issue is about a static image export, rather than an interactive embed, which is #485. As things stand, the only image format that would definitely include the filtering we need is PNG, because GL JS can serve up PNG natively. I haven’t played with maplibre-gl-export yet, so I’m simply unsure about the other formats that plugin can export.
Currently, clicking the Download button submits the form to the /export/finish API endpoint. But for these layers, we should intercept and cancel the form submission.
I don’t have a development environment set up for ohm-website, but I was able to get the mechanism above working in my browser locally:
Simulate step (1) above:
Set a breakpoint in application-11d5e4a2cbe139b2c49b6f9456bb8b2c0c65a337f52c14b73c2d025c13b6b83b.js line 199, within the baselayerchange event handler. (It’s easier to get there if you search the debugger for all files containing baselayerchange.)
Switch to another vector layer, then run this in the console and continue:
But it might be possible to cobble together an animated GIF or APNG that runs through the times specified by the time slider. A timelapse image would really differentiate OHM from OSM.
I think a timelapse animation would be icing on top, not strictly required for fixing this issue, so I split it out as #569.
Activity
danrademacher commentedon Nov 15, 2022
Based on this part:
So we think that PNG format will include runtime styling but other formats would not, is that correct?
Sound right based on this from the GL docs:
That file is here:
https://github.com/OpenHistoricalMap/ohm-website/blob/staging/app/views/export/embed.html.erb
I wonder if just implementing some of the same JS we have on the main page map would provide what we want here.
1ec5 commentedon Nov 15, 2022
This issue is about a static image export, rather than an interactive embed, which is #485. As things stand, the only image format that would definitely include the filtering we need is PNG, because GL JS can serve up PNG natively. I haven’t played with maplibre-gl-export yet, so I’m simply unsure about the other formats that plugin can export.
danrademacher commentedon Jul 12, 2023
Pulling over from internal Slack convo -- a fix require only a few lines of code, but I'm not sure what those would be yet.
Since we last touched this issue, we did some work on updating the embed.html, and js to include the OHM default layer and timeslider, but we never merged and deployed due to #495
But that's the only view I see here:
https://github.com/OpenHistoricalMap/ohm-website/tree/staging/app/views/export
I wonder if the image export uses that same embed view, in which case maybe we can enable
preserveDrawingBufferthere and the export would work?1ec5 commentedon Jul 12, 2023
I had been thinking it would be more straightforward to hook up the existing image export functionality to GL JS:
MapboxGLobject, we should setpreserveDrawingBuffertotrue./export/finishAPI endpoint. But for these layers, we should intercept and cancel the form submission.<canvas>element by querying the selector.mapboxgl-canvas, then take a screenshot of it by converting its 2D context to a PNG-formatted data: URI.Redirecting to an embed page and then screenshotting might be an alternative, but I was thinking it would be kind of awkward to orchestrate all that.
/ref watergis/maplibre-gl-export#16 (comment)
1ec5 commentedon Jul 12, 2023
I don’t have a development environment set up for ohm-website, but I was able to get the mechanism above working in my browser locally:
baselayerchangeevent handler. (It’s easier to get there if you search the debugger for all files containingbaselayerchange.)1ec5 commentedon Jul 12, 2023
I think a timelapse animation would be icing on top, not strictly required for fixing this issue, so I split it out as #569.