Refactoring: save ID to the hash of the URL

This commit is contained in:
Pieter Vander Vennet 2023-04-24 02:54:15 +02:00
parent 7d941e8a9a
commit 78c56f6fa2
4 changed files with 27 additions and 163 deletions

View file

@ -286,7 +286,7 @@ export default class LayoutConfig implements LayoutInformation {
return { untranslated, total }
}
public getMatchingLayer(tags: any): LayerConfig | undefined {
public getMatchingLayer(tags: Record<string, string>): LayerConfig | undefined {
if (tags === undefined) {
return undefined
}

View file

@ -48,6 +48,7 @@ import { Utils } from "../Utils"
import { EliCategory } from "./RasterLayerProperties"
import BackgroundLayerResetter from "../Logic/Actors/BackgroundLayerResetter"
import SaveFeatureSourceToLocalStorage from "../Logic/FeatureSource/Actors/SaveFeatureSourceToLocalStorage"
import Hash from "../Logic/Web/Hash"
/**
*
@ -429,6 +430,30 @@ export default class ThemeViewState implements SpecialVisualizationState {
* Setup various services for which no reference are needed
*/
private initActors() {
this.selectedElement.addCallback((selected) => {
Hash.hash.setData(selected?.properties?.id)
})
Hash.hash.mapD(
(hash) => {
console.log("Searching for an id:", hash)
if (this.selectedElement.data?.properties?.id === hash) {
// We already have the correct hash
return
}
const found = this.indexedFeatures.featuresById.data?.get(hash)
console.log("Found:", found)
if (!found) {
return
}
const layer = this.layout.getMatchingLayer(found.properties)
this.selectedElement.setData(found)
this.selectedLayer.setData(layer)
},
[this.indexedFeatures.featuresById]
)
new MetaTagging(this)
new TitleHandler(this.selectedElement, this.selectedLayer, this.featureProperties, this)
new ChangeToElementsActor(this.changes, this.featureProperties)