-
Notifications
You must be signed in to change notification settings - Fork 41
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
Layer legends #303
Layer legends #303
Conversation
… (default enabled).
… of list items got confused, when new items were removed or added dynamically.
…hen the layer item displaying the legend is not expanded.
} | ||
} | ||
}; | ||
</script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add newline at end of file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved in 5e2e02d
@@ -0,0 +1,62 @@ | |||
<template> | |||
<!-- Remarks: | |||
As we need none of the responsive functionality of v-img, use a simple |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we need none of the responsive functionality of v-img, use a simple | |
As we need none of the responsive functionality of v-img, we use a simple |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved in 5e2e02d
fine for me.
I do not have a strong opinion here. The pattern |
Thanks @fschmenger for this useful feature, I like it! Code quality is great like always 👍 My custom config: {
"type": "IMAGEWMS",
"lid": "mgsm-places",
"ratio": 1.5,
"format": "image/png",
"layers": "mgsm-world:ne_10m_populated_places",
"url": "https://services.meggsimum.de/geoserver/mgsm-world/wms?",
"transparent": true,
"projection": "EPSG:3857",
"isBaseLayer": false,
"visible": true,
"displayInLayerList": true,
"legend": true
}, Maybe the the layer from ahocevar was only temporarily disabled. If not, could you add a working example to the config(s), ideally also for a custom image? Do I understand correctly that you designed src/components/layerlist/LayerListItem.vue to be used in custom modules as well? |
Hi Jakob, thanks a lot for the review! Regarding the ahocevar layers: For a custom URL I could put a static image into static/icons (maybe even 2 to demonstrate the legend localization feature), however that would increase the package size. But I`m not sure which layer should be suitable to do this for?! Regarding the Meanwhile I finished the unit tests and documentation. I will now address the formatting issues and finalize it. |
OK, I updated the docs, unit tests and fixed the formatting. Regarding the placeholders wegue/test/unit/specs/components/layerlist/LayerLegendImage.spec.js Lines 104 to 113 in 5e2e02d
{{VAR_NAME}} is very specific to vue templates but definitely a possibility. Another option would be to use {VAR_NAME} (which is more common for positional placeholders) or %VAR_NAME% like e.g. in SQL.Sooner or later we might have to introduce more placeholders in the configuration, so this should be future proof. Therefore opinions on this are strongly appreciated (@chrismayer). |
…te the unit tests and docs accordingly.
we can just add a dummy image as static legend, maybe to the shop layer (OSM). But this is not that important. Otherwise we can include a image from a site like https://dummyimage.com/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it and it works well, code looks also fine. Can be merged.
A non-blocking question:
When I run the tests locally I get the errors below. It is strange that only the new tests fail. But obviously in the CI they are running. Do you have an idea why it could be like this?
I use Node version 16.
HeadlessChrome 105.0.5195 (Linux 0.0.0): Executed 274 of 274 (5 FAILED) (3.14 secs / 2.41 secs)
TOTAL: 5 FAILED, 269 SUCCESS
1) has correct previewURL for static layer image
bglayerswitcher/LayerPreviewImage.vue computed properties
AssertionError: expected 'https://b.tile.openstreetmap.org/2/2/…' to equal 'http://my-image.png'
at Context.<anonymous> (webpack:///test/unit/specs/components/bglayerswitcher/LayerPreviewImage.spec.js:93:32 <- index.js:201147:32)
2) has correct legendURL for static legend URL
layerlist/LayerLegendImage.vue computed properties
AssertionError: expected undefined to equal 'http://my-image.png'
at Context.<anonymous> (webpack:///test/unit/specs/components/layerlist/LayerLegendImage.spec.js:100:31 <- index.js:201804:31)
3) has correct legendURL for legend format URL
layerlist/LayerLegendImage.vue computed properties
AssertionError: expected undefined to equal 'http://my-image.png?transparent=true&…'
at Context.<anonymous> (webpack:///test/unit/specs/components/layerlist/LayerLegendImage.spec.js:113:31 <- index.js:201818:31)
4) has correct legendURL for WMS
layerlist/LayerLegendImage.vue computed properties
AssertionError: expected undefined to equal 'https://ahocevar.com/geoserver/wms?SE…'
at Context.<anonymous> (webpack:///test/unit/specs/components/layerlist/LayerLegendImage.spec.js:118:31 <- index.js:201824:31)
5) legendURL supports localization and scale
layerlist/LayerLegendImage.vue computed properties
AssertionError: expected undefined to equal 'https://ahocevar.com/geoserver/wms?SE…'
at Context.<anonymous> (webpack:///test/unit/specs/components/layerlist/LayerLegendImage.spec.js:125:31 <- index.js:201830:31)
Hi @JakobMiksch, I suggest we provide an example with a static legend URL in a separate PR. Do you have a meaningful image, that we could use for the shop layer? Maybe 2 images with localized texts, so we can demonstrate the placeholder with a Regarding the unit tests: It's not only the new tests failing but also an older test regarding
Possibly you could try to make those tests asynchronous and wrap the assertion by a vm.$nextTick ? Anyway, thanks a lot for the review, will merge now! |
This pull request implements layer legends and builds on previous works by @JakobMiksch (closes #259). After some discussion with my fellow colleagues we decided to choose the layer list module as an anchor for the legend images such that legends can be shown by toggling an expansion button.
Basics:
To activate legends, set the new boolean configuration attribute
legend
for your map layer totrue
. This should work out of the box for (image and tile) WMS layers by utilizing the WMS GetLegendGraphic request.Legend Params:
For request options, Wegue internally manages the
SCALE
andLANGUAGE
parameter.If you want to specify additional request params, you can configure the map layer attribute
legendOptions
. This is an object containing the params passed into the getLegendUrl function, e.g.I also introduced the possibility to specify legend params on an application wide scope: You can configure the top level configuration property
legend
, describing the same type of object aslegendOptions
. This can be useful to supply default params like fonts, font-sizes and other stuff common to all legends, e.g.The legend params of the individual layers are then merged with the application wide option, while the layer option takes precedence.
Custom URLs:
In order to support custom legend URLs (e.g. for non WMS layers, static layer images etc.), the map layer configuration supports a 3rd parameter
legendUrl
. This is an argument of type string, which may contain format placeholders for the variouslegendOptions
. Placeholders may appear anywhere in the URL. Those are typically useful to support a localized or scale dependent custom legend, but work for every other of your supplied options e.g.Disabling legends in layer list
Since anchoring the legends in the layer list is probably an opinionated decision I added a boolean attribute
showLegends
to the layer list module configuration (defaults totrue
).If you want to provide your custom legend implementation, this can now be done much easier by reusing the
wgu-layerlegendimage
template. It should be straightforward to configure and already takes care of implementing all the configuration options described above.Example configurations
For the app-starters I enabled legends for the
ahocevar-wms
layer.