1- import type { Layer } from '@swissgeo/layers'
2-
31import log , { LogPreDefinedColor } from '@swissgeo/log'
42
53import 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