Skip to content

Commit 160d1d2

Browse files
committed
PB-2064: refactor load topic
1 parent 8829e7f commit 160d1d2

File tree

1 file changed

+22
-30
lines changed
  • packages/viewer/src/store/modules/topics/actions

1 file changed

+22
-30
lines changed

packages/viewer/src/store/modules/topics/actions/loadTopic.ts

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { Layer } from '@swissgeo/layers'
2-
31
import log, { LogPreDefinedColor } from '@swissgeo/log'
42

53
import type { LoadTopicOptions, TopicsStore } from '@/store/modules/topics/types/topics'
@@ -36,7 +34,28 @@ export default function loadTopic(
3634
}
3735
}
3836
if (this.currentTopic.layersToActivate) {
39-
const layersToKeep = updateActiveLayersFromTopics.call(this)
37+
const layersStore = useLayersStore()
38+
// Get IDs of currently active layers
39+
const activeLayerIds = new Set(layersStore.activeLayers.map(layer => layer.id))
40+
41+
// Create a map of active layers by ID for quick lookup with their time configs
42+
const activeLayersMap = new Map(
43+
layersStore.activeLayers.map(layer => [layer.id, layer])
44+
)
45+
46+
// Filter layersToActivate to only include layers that are currently active
47+
const layersToKeep = this.currentTopic.layersToActivate.filter(layer =>
48+
activeLayerIds.has(layer.id)
49+
).map(layer => {
50+
const activeLayer = activeLayersMap.get(layer.id)
51+
layer.isVisible = activeLayer?.isVisible || false
52+
// If the active layer has a time config and current time entry, update the new layer's time config
53+
if (activeLayer?.timeConfig?.currentTimeEntry && layer.timeConfig) {
54+
layer.timeConfig.currentTimeEntry = activeLayer.timeConfig.currentTimeEntry
55+
}
56+
57+
return layer
58+
})
4059
// Only set layers if there are any to keep
4160
if (layersToKeep.length > 0) {
4261
layersStore.setLayers(layersToKeep, dispatcher)
@@ -53,30 +72,3 @@ export default function loadTopic(
5372
})
5473
})
5574
}
56-
57-
58-
function updateActiveLayersFromTopics(this: TopicsStore): Layer[] {
59-
const layersStore = useLayersStore()
60-
// Get IDs of currently active layers
61-
const activeLayerIds = new Set(layersStore.activeLayers.map(layer => layer.id))
62-
63-
// Create a map of active layers by ID for quick lookup with their time configs
64-
const activeLayersMap = new Map(
65-
layersStore.activeLayers.map(layer => [layer.id, layer])
66-
)
67-
68-
// Filter layersToActivate to only include layers that are currently active
69-
const layersToKeep = this.currentTopic!.layersToActivate.filter(layer =>
70-
activeLayerIds.has(layer.id)
71-
).map(layer => {
72-
const activeLayer = activeLayersMap.get(layer.id)
73-
layer.isVisible = activeLayer?.isVisible || false
74-
// If the active layer has a time config and current time entry, update the new layer's time config
75-
if (activeLayer?.timeConfig?.currentTimeEntry && layer.timeConfig) {
76-
layer.timeConfig.currentTimeEntry = activeLayer.timeConfig.currentTimeEntry
77-
}
78-
79-
return layer
80-
})
81-
return layersToKeep
82-
}

0 commit comments

Comments
 (0)