From fa58754c8a33cfbf9a30c55e85f536cecccac343 Mon Sep 17 00:00:00 2001 From: Felix Sommer Date: Fri, 21 Nov 2025 15:02:46 +0100 Subject: [PATCH 01/11] PB-2064: fix import map layers --- .../src/parsers/WMSCapabilitiesParser.ts | 45 ++++++++++++------- .../menu/components/LayerCatalogueItem.vue | 9 ++-- .../cypress/tests-e2e/importToolMaps.cy.ts | 10 ++--- 3 files changed, 39 insertions(+), 25 deletions(-) diff --git a/packages/layers/src/parsers/WMSCapabilitiesParser.ts b/packages/layers/src/parsers/WMSCapabilitiesParser.ts index 63786f7d59..b82549fe6b 100644 --- a/packages/layers/src/parsers/WMSCapabilitiesParser.ts +++ b/packages/layers/src/parsers/WMSCapabilitiesParser.ts @@ -467,12 +467,14 @@ function getFeatureInfoCapability( * @param options.params URL parameters to pass to WMS server * @param options.ignoreError Don't throw exception in case of error, but return a default value or * undefined + * @param parentsArray Optional parents array (internal parameter for recursion) * @returns Layer object, or undefined in case of error (and ignoreError is equal to true) */ function getExternalLayer( capabilities: WMSCapabilitiesResponse, layerOrLayerId: WMSCapabilityLayer | string, - options?: ExternalLayerParsingOptions + options?: ExternalLayerParsingOptions, + parentsArray?: WMSCapabilityLayer[], ): ExternalWMSLayer | undefined { if (!layerOrLayerId) { // without a layer object or layer ID we can do nothing @@ -482,26 +484,34 @@ function getExternalLayer( const { outputProjection = WGS84, initialValues = {}, ignoreErrors = true } = options ?? {} const { currentYear, params } = initialValues - let layerId: string - if (typeof layerOrLayerId === 'string') { - layerId = layerOrLayerId + let layer: WMSCapabilityLayer | undefined + let parents: WMSCapabilityLayer[] | undefined + + // If we have a layer object, use it directly with provided parents + if (typeof layerOrLayerId !== 'string') { + layer = layerOrLayerId + parents = parentsArray ?? [] } else { - layerId = layerOrLayerId.Name - } - if (!capabilities.Capability?.Layer?.Layer) { - return - } + // If we have a layer ID, search for it + const layerId = layerOrLayerId + if (!capabilities.Capability?.Layer?.Layer) { + return + } - const layerAndParents = findLayerRecurse( - layerId, - [capabilities.Capability.Layer], - [capabilities.Capability.Layer] - ) - if (!layerAndParents) { - return + const layerAndParents = findLayerRecurse( + layerId, + [capabilities.Capability.Layer], + [capabilities.Capability.Layer] + ) + if (!layerAndParents) { + return + } + layer = layerAndParents.layer + parents = layerAndParents.parents } - const { layer, parents } = layerAndParents + if (!layer) { + const layerId = typeof layerOrLayerId === 'string' ? layerOrLayerId : layerOrLayerId.Name const msg = `No WMS layer ${layerId} found in Capabilities ${capabilities.originUrl.toString()}` log.error({ title: 'WMS Capabilities parser', @@ -513,6 +523,7 @@ function getExternalLayer( } throw new CapabilitiesError(msg, 'no_layer_found') } + // Go through the child to get valid layers let layers: ExternalWMSLayer[] = [] diff --git a/packages/viewer/src/modules/menu/components/LayerCatalogueItem.vue b/packages/viewer/src/modules/menu/components/LayerCatalogueItem.vue index b3693ca2c3..a9882e8276 100644 --- a/packages/viewer/src/modules/menu/components/LayerCatalogueItem.vue +++ b/packages/viewer/src/modules/menu/components/LayerCatalogueItem.vue @@ -6,7 +6,7 @@ import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome' import { type FlatExtent, LV95, type NormalizedExtent } from '@swissgeo/coordinates' -import { type GeoAdminGroupOfLayers, type Layer, LayerType } from '@swissgeo/layers' +import { type ExternalWMSLayer, type GeoAdminGroupOfLayers, type Layer, LayerType } from '@swissgeo/layers' import log from '@swissgeo/log' import { booleanContains, polygon } from '@turf/turf' import { computed, onMounted, ref, watch } from 'vue' @@ -61,8 +61,11 @@ const showItem = computed(() => { const isGroupOfLayers = (layer: Layer): layer is GeoAdminGroupOfLayers => { return layer.type === LayerType.GROUP } +const isWmsLayer = (layer: Layer): layer is ExternalWMSLayer => { + return layer.type === LayerType.WMS +} -const hasChildren = computed(() => isGroupOfLayers(item) && item?.layers?.length > 0) +const hasChildren = computed(() => (isGroupOfLayers(item) ||isWmsLayer(item)) && item?.layers?.length && item?.layers?.length > 0) const hasDescription = computed(() => canBeAddedToTheMap.value && item?.hasDescription) const isPhoneMode = computed(() => uiStore.isPhoneMode) @@ -320,7 +323,7 @@ function containsLayer(layers: Layer[], searchText: string): boolean {