There were a few issues with the Map component in PDF
The map marker from leaflet has role=button and would therefore get hidden in the PDF. This was solved by overriding styling in the MapComponentSummary
The map fades in from opacity 0 on load, meaning that when app-frontend thinks everything is loaded the Map is not 100% visible yet. This was also fixed by overriding styling in MapComponentSummary, setting tiles to always have opacity 1.
The waiting-for-images-to-load part of ReadyForPrint turned out to not be very robust, as in most cases none of the map tiles had time to load before print happened. One problem seems to be that it first looks for all of the image elements, and adds promises for the ones that have not loaded yet. But most of the time it would not find any image elements at that time, and therefore add no promises, and so it would be completely unpredictable whether the images are actually loaded or not.
Adding this simple check revealed that when using a Map component, most of the images were not in fact finished loading by the time ReadyForPrint was rendered past the assetsLoaded check. At least when doing a hard refresh (Ctrl+Shift+R), when allowing the browser to use its cache it would often load them all in time.
To resolve the last issue I added the waitForImages function, which will wait for a couple of animation frames before checking for new image elements, then awaiting those promises, and repeating, until there are no more images that are not loaded.
I have not added any tests for this, not sure exactly how I would detect this in cypress, but I have tested manually and it has never failed me so far
Related Issue(s)
closes #2044
Verification/QA
Manual functionality testing
[x] I have tested these changes manually
[ ] Creator of the original issue (or service owner) has been contacted for manual testing (or will be contacted when released in alpha)
[ ] No testing done/necessary
Automated tests
[ ] Unit test(s) have been added/updated
[ ] Cypress E2E test(s) have been added/updated
[ ] No automatic tests are needed here (no functional changes/additions)
Description
There were a few issues with the Map component in PDF
role=button
and would therefore get hidden in the PDF. This was solved by overriding styling in theMapComponentSummary
MapComponentSummary
, setting tiles to always have opacity 1.ReadyForPrint
turned out to not be very robust, as in most cases none of the map tiles had time to load before print happened. One problem seems to be that it first looks for all of the image elements, and adds promises for the ones that have not loaded yet. But most of the time it would not find any image elements at that time, and therefore add no promises, and so it would be completely unpredictable whether the images are actually loaded or not.Adding this simple check revealed that when using a Map component, most of the images were not in fact finished loading by the time
ReadyForPrint
was rendered past theassetsLoaded
check. At least when doing a hard refresh (Ctrl+Shift+R), when allowing the browser to use its cache it would often load them all in time.To resolve the last issue I added the
waitForImages
function, which will wait for a couple of animation frames before checking for new image elements, then awaiting those promises, and repeating, until there are no more images that are not loaded.I have not added any tests for this, not sure exactly how I would detect this in cypress, but I have tested manually and it has never failed me so far
Related Issue(s)
Verification/QA
kind/*
label to this PR for proper release notes grouping