-
-
Notifications
You must be signed in to change notification settings - Fork 153
Fix #5934: Display legend for external WMS layers #6114
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
base: master
Are you sure you want to change the base?
Changes from all commits
1e8f8ba
b595cee
2e8873b
7f3807e
95f774b
848cd04
27c532c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -32,21 +32,60 @@ export async function updateLayerTreeLayersSymbology(treeLayers, method=HttpRequ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (method.toUpperCase() == HttpRequestMethods.GET) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const treeLayer of treeLayers) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const wmsParams = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LAYER: treeLayer.wmsName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| STYLES: treeLayer.wmsSelectedStyleName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Check if this is an external WMS layer using the backend flag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const layerCfg = treeLayer._mapItemState?._layerItemState?._layerTreeItemCfg?._layerCfg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const isExternalWMS = layerCfg?._externalWmsToggle === true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| || layerCfg?._externalWmsToggle === 'True'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await wms.getLegendGraphic(wmsParams).then((response) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const node of response.nodes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // If the layer has no symbology, there is no type property | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (node.hasOwnProperty('type')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| treeLayer.symbology = node; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (isExternalWMS) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // For external WMS layers, get PNG legend directly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const wmsParams = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LAYER: treeLayer.wmsName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| STYLES: treeLayer.wmsSelectedStyleName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LAYERTITLE: 'FALSE', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const pngUrl = wms.getLegendGraphicPNG(wmsParams); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Fetch the PNG and convert to base64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const response = await fetch(pngUrl); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const blob = await response.blob(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const reader = new FileReader(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await new Promise((resolve, reject) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| reader.onloadend = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const base64data = reader.result.split(',')[1]; // Remove data:image/png;base64, prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| treeLayer.symbology = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'layer', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: treeLayer.wmsName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title: treeLayer.name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| icon: base64data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| resolve(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| reader.onerror = reject; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| reader.readAsDataURL(blob); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error('Error loading external WMS legend:', error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Fallback to default icon will be handled by symbology state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+40
to
+70
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Do not request the image and simulate a child icon. I prefer to enhance the treeview component to display the legend image has a child. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }).catch((error) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error(error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Request JSON only for non external WMS |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // For normal layers, use JSON format | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const wmsParams = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LAYER: treeLayer.wmsName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| STYLES: treeLayer.wmsSelectedStyleName, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await wms.getLegendGraphic(wmsParams).then((response) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (const node of response.nodes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // If the layer has no symbology, there is no type property | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (node.hasOwnProperty('type')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| treeLayer.symbology = node; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }).catch((error) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.error(error); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return treeLayers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2045,12 +2045,15 @@ public function getUpdatedConfig() | |||||||||||||||||||
| && !array_key_exists('crs', $layerDatasource)) { | ||||||||||||||||||||
| $layerDatasource['crs'] = 'EPSG:3857'; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| // Set externalWmsToggle for ALL external WMS layers (not just EPSG:3857) | ||||||||||||||||||||
| $obj->externalWmsToggle = 'True'; | ||||||||||||||||||||
| $obj->externalAccess = $layerDatasource; | ||||||||||||||||||||
|
Comment on lines
+2048
to
+2050
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Activate external only for WMS layers. We should verify that the project's projection is recognized by the source service or that the OpenLayers layer created reuses the CRS of the source layer. |
||||||||||||||||||||
|
|
||||||||||||||||||||
| // if the layer datasource contains type and crs EPSG:3857 | ||||||||||||||||||||
| // external access can be provided | ||||||||||||||||||||
| // additional external access configuration can be provided | ||||||||||||||||||||
| if (array_key_exists('type', $layerDatasource) | ||||||||||||||||||||
| && $layerDatasource['crs'] == 'EPSG:3857') { | ||||||||||||||||||||
| $obj->externalWmsToggle = 'True'; | ||||||||||||||||||||
| $obj->externalAccess = $layerDatasource; | ||||||||||||||||||||
| // Additional external access for EPSG:3857 layers | ||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. keeps it for other |
||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
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.