Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/viewer/src/store/modules/i18n/actions/setLang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,25 @@ import i18n, { langToLocale, type SupportedLang } from '@/modules/i18n'
import useLayersStore from '@/store/modules/layers'
import redoSearch from '@/store/modules/search/utils/redoSearch'

interface SetLangOptions {
changeLayersOnTopicChange?: boolean
}

export default function setLang(
this: I18nStore,
lang: SupportedLang,
dispatcher: ActionDispatcher,
): void
export default function setLang(
this: I18nStore,
lang: SupportedLang,
dispatcher: ActionDispatcher
) {
optionsOrDispatcher: SetLangOptions | ActionDispatcher,
dispatcherOrNothing?: ActionDispatcher
): void {
const dispatcher = dispatcherOrNothing ?? (optionsOrDispatcher as ActionDispatcher)
const options = dispatcherOrNothing ? (optionsOrDispatcher as SetLangOptions) : {}
this.lang = lang
i18n.global.locale.value = langToLocale(lang)
useLayersStore().loadLayersConfig({ changeLayersOnTopicChange: true }, dispatcher)
useLayersStore().loadLayersConfig({ changeLayersOnTopicChange: options.changeLayersOnTopicChange }, dispatcher)
redoSearch()
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function changeTopic(
this.current = topicId
this.loadTopic(
{
changeLayers: this.router.currentRoute.value.query.layers === undefined,
changeLayers: true,
},
dispatcher
)
Expand Down
46 changes: 40 additions & 6 deletions packages/viewer/src/store/modules/topics/actions/loadTopic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,49 @@ export default function loadTopic(

loadTopicTreeForTopic(i18nStore.lang, this.current, layersStore.config)
.then((topicTree) => {
if (!this.currentTopic) {
return
}
this.setTopicTree(topicTree.layers, dispatcher)
this.setTopicTreeOpenedThemesIds([this.current, ...topicTree.itemIdToOpen], dispatcher)
if (this.currentTopic?.defaultBackgroundLayer) {
layersStore.setBackground(this.currentTopic?.defaultBackgroundLayer.id, dispatcher)
} else {
layersStore.setBackground(undefined, dispatcher)
if (options.changeLayers) {
if (this.currentTopic.defaultBackgroundLayer) {
layersStore.setBackground(this.currentTopic.defaultBackgroundLayer.id, dispatcher)
} else {
layersStore.setBackground(undefined, dispatcher)
}

if (this.currentTopic.layersToActivate) {
layersStore.setLayers(this.currentTopic.layersToActivate, dispatcher)
}
}
if (options.changeLayers && this.currentTopic?.layersToActivate) {
layersStore.setLayers(this.currentTopic.layersToActivate, dispatcher)
if (this.currentTopic.layersToActivate) {
const layersStore = useLayersStore()
// Get IDs of currently active layers
const activeLayerIds = new Set(layersStore.activeLayers.map(layer => layer.id))

// Create a map of active layers by ID for quick lookup with their time configs
const activeLayersMap = new Map(
layersStore.activeLayers.map(layer => [layer.id, layer])
)

// Filter layersToActivate to only include layers that are currently active
const layersToKeep = this.currentTopic.layersToActivate.filter(layer =>
activeLayerIds.has(layer.id)
).map(layer => {
const activeLayer = activeLayersMap.get(layer.id)
layer.isVisible = activeLayer?.isVisible || false
// If the active layer has a time config and current time entry, update the new layer's time config
if (activeLayer?.timeConfig?.currentTimeEntry && layer.timeConfig) {
layer.timeConfig.currentTimeEntry = activeLayer.timeConfig.currentTimeEntry
}

return layer
})
// Only set layers if there are any to keep
if (layersToKeep.length > 0) {
layersStore.setLayers(layersToKeep, dispatcher)
}
}
})
.catch((error) => {
Expand Down
Loading