Skip to content

Support WMS layer style in legend URL generation#52

Merged
ronitjadhav merged 3 commits intomainfrom
legend-style-support
Mar 5, 2026
Merged

Support WMS layer style in legend URL generation#52
ronitjadhav merged 3 commits intomainfrom
legend-style-support

Conversation

@ronitjadhav
Copy link
Copy Markdown
Member

Problem

WMS supports multiple named styles for a layer. When switching the style of a WMS layer (e.g. via the style property on MapContextLayerWms), the map renders the correct style — but the legend always showed the default style's legend graphic.

This happened because createWmsLegendUrl was not including the STYLE= parameter in the GetLegendGraphic request. Without it, the WMS server always returns the legend for the default style.

Solution

  • Added "STYLE" to the removeSearchParams list to strip any existing STYLE param from the input URL
  • When layer.style is set, include STYLE=<value> in the GetLegendGraphic URL

Example

  • Added a legend example in the demo app (Example-Legend.vue) that shows a WMS layer with style switching — the legend updates when the style changes

@ronitjadhav ronitjadhav requested a review from jahow March 3, 2026 08:29
Copy link
Copy Markdown
Member

@jahow jahow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you! please remember that the examples need to be as concise as possible for them to be useful!

@ronitjadhav
Copy link
Copy Markdown
Member Author

Thanks for the review. I've made the changes as suggested.

Copy link
Copy Markdown
Member

@jahow jahow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! just a small suggestion on the example code

- Use updateLayerInContext util for style switching
- Use DEFAULT_CONTEXT for base map setup
- Derive view from WMS layer using createViewFromLayer
- Fetch styles dynamically from WMS GetCapabilities
- Check style !== undefined instead of truthy
@ronitjadhav ronitjadhav force-pushed the legend-style-support branch from 6dbb651 to 99fb3d9 Compare March 5, 2026 11:25
@ronitjadhav ronitjadhav merged commit f826933 into main Mar 5, 2026
1 check passed
@ronitjadhav ronitjadhav deleted the legend-style-support branch March 5, 2026 11:39
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.

2 participants