Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legend for print map #1408

Merged
merged 15 commits into from
Feb 14, 2022
Merged

Conversation

sweco-semvtw
Copy link
Contributor

Proposes to fix #1382

Adds a legend to the print maps top left corner that displays legends for all selected layers. Styles from index.json will be considered first. If a style is not found in index.json and layer is not of an AGS type then a call to getLegendGraphic will be made to the layer's source.

The legend can be hidden with the control menu.

Tested using:
WMS, WFS, GeoServer, ArcGIS

Screenshot 2021-12-22 at 11-23-16 Origo exempel

@steff-o
Copy link
Contributor

steff-o commented Jan 18, 2022

I have tested against WMS and WFS using Geoserver and it works like a charm. But I have some observations:

  1. There are some unnecessary calls to console.log()
  2. This PR does not use the high resolution prints from Printing in higher and lower resolution #1407, and that PR does not include the legend. So my suggestion is to wait until that has been merged and update this PR.
  3. As with Printing in higher and lower resolution #1407, if a layer lacks style it crashes.

I noticed that onRender is now async. Nothing wrong with that, I'm a huge fan of async myself and something has to be a promise when calling the server. But as there is no await, all errors except those swallowed when the remote call is performed, will end up as uncaught (in promise). Maybe that is not a problem as previously I assume all errors would have ended up as uncaught anyway as the way I understand it, the code that calls onRender did not catch anything. But it could be worth contemplating if it affects anything else.

@jokd
Copy link
Contributor

jokd commented Jan 27, 2022

Works well for me

@Grammostola
Copy link
Contributor

Grammostola commented Jan 28, 2022

It doesn't crash if a feature layer lacks a style property in index.json, instead a wfs layer will be present and without an icon, an AGS_FEATURE layer will not be present (in the legend). It does seem to crash if a WMS layer does not have a style when Save image is employed.

@Grammostola
Copy link
Contributor

Correction: it does seem to crash if a WMS layer does not have a style property in index json and its source is local but defined in absolute terms, was getting 'tainted canvas' on toBlob() https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image . I tried a WMS service from another place (from a source defined in absolute terms) and it worked without a style (no legend icon but present in the legend). The local source expressed as a relative path also worked.

The legend icons do seem to match the rest of the print, resolutionwise (and less console.log after the last commit) so I think it works well enough. We may choose to merge the other print PR before this one.

@jokd
Copy link
Contributor

jokd commented Feb 9, 2022

@Grammostola Is this good to merge before 2.5? If so please resolve the conflicts.

@Grammostola
Copy link
Contributor

From what I've seen yes, it's mergable. The legend is optional in the printing pane and onRender being async hasn't produced anything unforseen while testing.

@Grammostola Grammostola merged commit 11c5987 into origo-map:master Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prints should be able to include a legend
5 participants