Skip to content

Commit

Permalink
Merge pull request #99 from Dataport/fix/improve-robustness-on-miscon…
Browse files Browse the repository at this point in the history
…figuration

improve robustness on misconfiguration
  • Loading branch information
warm-coolguy authored Feb 5, 2024
2 parents ec0e4a0 + 3648aef commit d72fb34
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 30 deletions.
5 changes: 5 additions & 0 deletions packages/plugins/LayerChooser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## unpublished

- 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

- Feature: Improved implementation to make plugin SPA-ready.
Expand Down
58 changes: 32 additions & 26 deletions packages/plugins/LayerChooser/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
import {
LayerConfiguration,
LayerConfigurationOptionLayers,
MapConfig,
PolarModule,
} from '@polar/lib-custom-types'
import * as masterportalapi from '@masterportal/masterportalapi/src'
Expand All @@ -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 = () => {
Expand All @@ -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(
Expand All @@ -68,7 +86,6 @@ export const makeStoreModule = () => {
dispatch('setActiveMaskIds', asIdList(activeMasks))

dispatch('updateActiveAndAvailableLayersByZoom')

map.on('moveend', () =>
dispatch('updateActiveAndAvailableLayersByZoom')
)
Expand All @@ -78,17 +95,6 @@ export const makeStoreModule = () => {
id: layer.id,
})

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', {
Expand Down
4 changes: 4 additions & 0 deletions packages/plugins/Legend/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
17 changes: 13 additions & 4 deletions packages/plugins/Legend/src/components/Legend.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
},
Expand Down

0 comments on commit d72fb34

Please sign in to comment.