From 99bd162d5ec49a53b900514ae3a0d267bb73a126 Mon Sep 17 00:00:00 2001 From: Dennis Sen Date: Tue, 30 Jan 2024 07:49:14 +0100 Subject: [PATCH 1/2] improve robustness on misconfiguration --- packages/plugins/LayerChooser/CHANGELOG.md | 4 ++++ .../plugins/LayerChooser/src/store/index.ts | 8 ++++++++ packages/plugins/Legend/CHANGELOG.md | 4 ++++ .../plugins/Legend/src/components/Legend.vue | 17 +++++++++++++---- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/plugins/LayerChooser/CHANGELOG.md b/packages/plugins/LayerChooser/CHANGELOG.md index a65763e54..87ea9bcde 100644 --- a/packages/plugins/LayerChooser/CHANGELOG.md +++ b/packages/plugins/LayerChooser/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## unpublished + +- Fix: The LayerChooser plugin will keep working on the error that a layer without entry in the service register has been configured. + ## 1.2.0 - Feature: Improved implementation to make plugin SPA-ready. diff --git a/packages/plugins/LayerChooser/src/store/index.ts b/packages/plugins/LayerChooser/src/store/index.ts index bf68604ce..cbf73ebb6 100644 --- a/packages/plugins/LayerChooser/src/store/index.ts +++ b/packages/plugins/LayerChooser/src/store/index.ts @@ -78,6 +78,14 @@ export const makeStoreModule = () => { id: layer.id, }) + if (rawLayer === null) { + console.error( + `@polar/plugin-layer-chooser: Layer ${layer.id} not found in service register. This is a configuration issue. The map might behave in unexpected ways.`, + layer + ) + return + } + if (rawLayer.typ !== 'WMS' && !layer.hideInMenu) { console.warn( `@polar/plugin-layer-chooser: Used configuration 'layers' on layer with type '${ diff --git a/packages/plugins/Legend/CHANGELOG.md b/packages/plugins/Legend/CHANGELOG.md index 731da76a2..7ff523e9e 100644 --- a/packages/plugins/Legend/CHANGELOG.md +++ b/packages/plugins/Legend/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## unpublished + +- Fix: The Legend plugin will keep working on the error that a layer without entry in the service register has been configured. + ## 1.1.0 - Feature: Locale string layer names are now translated. diff --git a/packages/plugins/Legend/src/components/Legend.vue b/packages/plugins/Legend/src/components/Legend.vue index 5b33f2e44..1a0f1e775 100644 --- a/packages/plugins/Legend/src/components/Legend.vue +++ b/packages/plugins/Legend/src/components/Legend.vue @@ -94,10 +94,19 @@ export default Vue.extend({ id: layer.id, }), })) - .map((layer) => ({ - ...layer, - legendUrl: masterportalapi.layerLib.getLegendURLs(layer.rawLayer)[0], - })) + .map((layer) => { + if (layer.rawLayer === null) { + // skip undefined layers + console.warn(`@polar/plugin-legend: Unknown layer.`, layer) + return {} + } + return { + ...layer, + legendUrl: masterportalapi.layerLib.getLegendURLs( + layer.rawLayer + )[0], + } + }) .filter((layer) => layer.name && layer.legendUrl) }, }, From 73f88c020f32754e013a2943770b1233eee0f919 Mon Sep 17 00:00:00 2001 From: Dennis Sen Date: Mon, 5 Feb 2024 07:32:35 +0100 Subject: [PATCH 2/2] remove outdated warning, hide non-existant layers --- packages/plugins/LayerChooser/CHANGELOG.md | 3 +- .../plugins/LayerChooser/src/store/index.ts | 66 +++++++++---------- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/packages/plugins/LayerChooser/CHANGELOG.md b/packages/plugins/LayerChooser/CHANGELOG.md index 87ea9bcde..db5f17f94 100644 --- a/packages/plugins/LayerChooser/CHANGELOG.md +++ b/packages/plugins/LayerChooser/CHANGELOG.md @@ -2,7 +2,8 @@ ## unpublished -- Fix: The LayerChooser plugin will keep working on the error that a layer without entry in the service register has been configured. +- Fix: The LayerChooser plugin will keep working on the error that a layer without entry in the service register has been configured. The layer will not be displayed. +- Fix: An outdated warning has been removed. ## 1.2.0 diff --git a/packages/plugins/LayerChooser/src/store/index.ts b/packages/plugins/LayerChooser/src/store/index.ts index cbf73ebb6..5a22fd3f8 100644 --- a/packages/plugins/LayerChooser/src/store/index.ts +++ b/packages/plugins/LayerChooser/src/store/index.ts @@ -5,6 +5,7 @@ import { import { LayerConfiguration, LayerConfigurationOptionLayers, + MapConfig, PolarModule, } from '@polar/lib-custom-types' import * as masterportalapi from '@masterportal/masterportalapi/src' @@ -28,6 +29,36 @@ export const getInitialState = (): LayerChooserState => ({ activeLayerIds: {}, }) +const getBackgroundsAndMasks = ( + configuration: MapConfig +): [LayerConfiguration[], LayerConfiguration[]] => + configuration.layers.reduce( + ([backgrounds, masks], current) => { + const rawLayer = masterportalapi.rawLayerList.getLayerWhere({ + id: current.id, + }) + + if (rawLayer === null) { + console.error( + `@polar/plugin-layer-chooser: Layer ${current.id} not found in service register. This is a configuration issue. The map might behave in unexpected ways.`, + current + ) + + return [backgrounds, masks] + } + if (current.type === 'background') { + return [[...backgrounds, current], masks] + } else if (current.type === 'mask') { + return [backgrounds, [...masks, current]] + } + console.error( + `@polar/plugin-layer-chooser: Unknown layer type ${current.type}. Layer is ignored by plugin.` + ) + return [backgrounds, masks] + }, + [[] as LayerConfiguration[], [] as LayerConfiguration[]] + ) + // OK for module creation // eslint-disable-next-line max-lines-per-function export const makeStoreModule = () => { @@ -41,20 +72,7 @@ export const makeStoreModule = () => { commit, dispatch, }): void { - const [backgrounds, masks] = configuration.layers.reduce( - ([backgrounds, masks], current) => { - if (current.type === 'background') { - return [[...backgrounds, current], masks] - } else if (current.type === 'mask') { - return [backgrounds, [...masks, current]] - } - console.error( - `@polar/plugin-layer-chooser: Unknown layer type ${current.type}. Layer is ignored by plugin.` - ) - return [backgrounds, masks] - }, - [[] as LayerConfiguration[], [] as LayerConfiguration[]] - ) + const [backgrounds, masks] = getBackgroundsAndMasks(configuration) // at most one background, arbitrarily many masks const activeBackground = backgrounds.find( @@ -68,7 +86,6 @@ export const makeStoreModule = () => { dispatch('setActiveMaskIds', asIdList(activeMasks)) dispatch('updateActiveAndAvailableLayersByZoom') - map.on('moveend', () => dispatch('updateActiveAndAvailableLayersByZoom') ) @@ -78,25 +95,6 @@ export const makeStoreModule = () => { id: layer.id, }) - if (rawLayer === null) { - console.error( - `@polar/plugin-layer-chooser: Layer ${layer.id} not found in service register. This is a configuration issue. The map might behave in unexpected ways.`, - layer - ) - return - } - - if (rawLayer.typ !== 'WMS' && !layer.hideInMenu) { - console.warn( - `@polar/plugin-layer-chooser: Used configuration 'layers' on layer with type '${ - rawLayer.typ - }', but only 'WMS' is supported. Ignoring configuration for ${JSON.stringify( - rawLayer - )}.` - ) - return - } - // Store preparation needed when `layers` is an option if (layer.options?.layers) { commit('setActiveLayerIds', {