Skip to content

Commit 2be8a82

Browse files
Merge pull request #454 from Dataport/dish-toggle-label-visibility-with-belonging-geomlayer
Dish toggle label visibility with belonging geomlayer
2 parents 434ce0c + fb139f4 commit 2be8a82

File tree

5 files changed

+136
-3
lines changed

5 files changed

+136
-3
lines changed

packages/clients/dish/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# CHANGELOG
22

33
## unpublished
4+
5+
- Feature: Monumental label layer toggles its visibility depending on visible monumental layer geometries.
46
- Fix: Add new configuration parameters for DishExportMap to configure different host (backend host might differ from `internalHost`) and to simplify adjustments for backend changes.
57
- Fix: Add terms of use for internal map.
68
- Fix: Open links for BKG and their terms of use in new tab.

packages/clients/dish/src/mapConfigurations/layerConfigIntern.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
import { scaleFromZoomLevel } from '../utils/calculateScaleFromResolution'
2121

2222
const alkisMinZoom = 10
23-
const beschriftungMinZoom = 9
23+
export const beschriftungMinZoom = 9
2424

2525
const layersIntern: LayerConfiguration[] = [
2626
{
@@ -155,7 +155,7 @@ const layersIntern: LayerConfiguration[] = [
155155
name: `Beschriftung (ab 1:${thousandsSeparator(
156156
scaleFromZoomLevel(beschriftungMinZoom)
157157
)})`,
158-
minZoom: 9,
158+
minZoom: beschriftungMinZoom,
159159
},
160160
]
161161

packages/clients/dish/src/polar-client.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import { FeatureCollection, Geometry, GeometryCollection } from 'geojson'
88
import { GeoJSON } from 'ol/format'
99
import packageInfo from '../package.json'
1010
import { navigateToDenkmal } from './utils/navigateToDenkmal'
11+
import { watchActiveMaskIds } from './utils/watchActiveMaksIds'
1112
import { addPlugins } from './addPlugins'
1213
import { services } from './services'
1314
import { getMapConfiguration } from './mapConfigurations/mapConfig'
1415
import { CONTENT_ENUM } from './plugins/Modal/store'
1516
import './styles.css'
1617
import selectionLayer from './selectionLayer'
1718
import { DishUrlParams } from './types'
19+
1820
// eslint-disable-next-line no-console
1921
console.log(`DISH map client running in version ${packageInfo.version}.`)
2022

@@ -40,6 +42,8 @@ export default {
4042
const objektId = parameters.get('ObjektID')
4143
if (mode === 'INTERN') {
4244
subscribeToExportedMap(map)
45+
// watch for changes in activeMaskIds to update beschriftung layer
46+
watchActiveMaskIds(map)
4347
map.$store.commit('plugin/selectionObject/setObjectId', objektId)
4448
if (typeof objektId === 'string') {
4549
zoomToInternalFeature(map, objektId, urlParams)

packages/clients/dish/src/servicesIntern.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const denkmaelerWmService = {
3030
layers: '0,1,2,3,4,6,24,25',
3131
}
3232

33-
const beschriftungService = {
33+
export const beschriftungService = {
3434
...commonConfigDenkmaelWMS,
3535
id: beschriftung,
3636
name: 'Beschriftung',
@@ -116,3 +116,30 @@ export const servicesIntern = [
116116
bddColInternService,
117117
dop20ColInternService,
118118
]
119+
120+
export const labeledLayerServices = [
121+
denkmaelerWmService,
122+
kontrollbedarfService,
123+
verlustService,
124+
]
125+
126+
// Map of geom layername to label layername of denkmal WMS service
127+
export const layerLabelMap = new Map([
128+
['0', '9'],
129+
['1', '10'],
130+
['2', '11'],
131+
['3', '12'],
132+
['4', '13'],
133+
['6', '15'],
134+
['7', '16'],
135+
['8', '17'],
136+
['19', '30'],
137+
['20', '31'],
138+
['21', '32'],
139+
['22', '33'],
140+
['23', '34'],
141+
['24', '26'],
142+
['25', '27'],
143+
['28', '35'],
144+
['29', '36'],
145+
])
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { MapInstance } from '@polar/core'
2+
import {
3+
beschriftungService,
4+
labeledLayerServices,
5+
layerLabelMap,
6+
} from '../servicesIntern'
7+
import { beschriftungMinZoom } from '../mapConfigurations/layerConfigIntern'
8+
9+
function getOlLabelLayer(instance) {
10+
const map = instance.$store.getters.map
11+
return map
12+
.getLayers()
13+
.getArray()
14+
.find((l) => l.get('id') === beschriftungService.id)
15+
}
16+
17+
export function watchActiveMaskIds(instance: MapInstance) {
18+
let previousLayers = ''
19+
20+
const updateLabelLayers = () => {
21+
const activeLayerIds =
22+
instance.$store.getters['plugin/layerChooser/activeLayerIds']
23+
const activeMaskIds =
24+
instance.$store.getters['plugin/layerChooser/activeMaskIds']
25+
const masks = instance.$store.getters['plugin/layerChooser/masks']
26+
27+
const allActiveLabelLayers = getAllActiveLabelLayers(
28+
activeLayerIds,
29+
activeMaskIds
30+
)
31+
const LAYERS = allActiveLabelLayers.join(',')
32+
33+
if (LAYERS === previousLayers) {
34+
return
35+
}
36+
37+
previousLayers = LAYERS
38+
39+
if (LAYERS !== '') {
40+
updateBeschriftungsLayer(instance, LAYERS)
41+
setBeschriftungVisibilityInMenu(masks, instance, false)
42+
} else {
43+
setBeschriftungVisibilityInMenu(masks, instance, true)
44+
getOlLabelLayer(instance)?.setVisible(false)
45+
}
46+
}
47+
48+
instance.$store.watch(
49+
(_, getters) => ({
50+
activeLayerIds: getters['plugin/layerChooser/activeLayerIds'],
51+
activeMaskIds: getters['plugin/layerChooser/activeMaskIds'],
52+
}),
53+
updateLabelLayers,
54+
{ immediate: true }
55+
)
56+
}
57+
58+
function getAllActiveLabelLayers(activeLayerIds, activeMaskIds) {
59+
const activeLabeledLayers = Object.entries(activeLayerIds)
60+
.filter(
61+
([key]) =>
62+
labeledLayerServices.map((service) => service.id).includes(key) &&
63+
activeMaskIds.includes(key)
64+
)
65+
.map(([, value]) => value)
66+
.flat()
67+
return activeLabeledLayers
68+
.map((l) => {
69+
return layerLabelMap.get(l as string)
70+
})
71+
.filter((s) => s)
72+
}
73+
74+
function updateBeschriftungsLayer(instance: MapInstance, LAYERS: string) {
75+
const olLabelLayer = getOlLabelLayer(instance)
76+
const olSource = olLabelLayer?.getSource()
77+
if (olSource) {
78+
const updatedParams = { ...olSource.getParams(), LAYERS }
79+
olSource.updateParams(updatedParams)
80+
}
81+
const currentZoom = instance.$store.getters.map.getView().getZoom()
82+
if (currentZoom >= beschriftungMinZoom) {
83+
olLabelLayer?.setVisible(true)
84+
} else {
85+
olLabelLayer?.setVisible(false)
86+
}
87+
}
88+
89+
function setBeschriftungVisibilityInMenu(
90+
masks,
91+
instance: MapInstance,
92+
hiddenInMenu: boolean
93+
) {
94+
const masksArray = masks.map((mask) =>
95+
mask.id === beschriftungService.id
96+
? { ...mask, hideInMenu: hiddenInMenu }
97+
: mask
98+
)
99+
instance.$store.commit('plugin/layerChooser/setMasks', masksArray)
100+
}

0 commit comments

Comments
 (0)