Fix dynamically selecting the popup when changing the hash

This commit is contained in:
Pieter Vander Vennet 2023-02-09 16:05:37 +01:00
parent 162ab325f9
commit df92bda151
2 changed files with 18 additions and 10 deletions

View file

@ -90,12 +90,12 @@ export default class SelectedFeatureHandler {
if (feature === undefined) {
return
}
const currentlySeleced = state.selectedElement.data
if (currentlySeleced === undefined) {
const currentlySelected = state.selectedElement.data
if (currentlySelected === undefined) {
state.selectedElement.setData(feature)
return
}
if (currentlySeleced.properties?.id === feature.properties.id) {
if (currentlySelected.properties?.id === feature.properties.id) {
// We already have the right feature
return
}

View file

@ -136,7 +136,7 @@ export default class ShowDataLayerImplementation {
if (this._leafletMap.data === undefined) {
return
}
const v = this.leafletLayersPerId.get(selected.properties.id + selected.geometry.type)
const v = this.leafletLayersPerId.get(selected.properties.id)
if (v === undefined) {
return
}
@ -335,7 +335,20 @@ export default class ShowDataLayerImplementation {
icon: L.divIcon(style),
})
}
/**
* Creates a function which, for the given feature, will open the featureInfoBox (and lazyly create it)
* This function is cached
* @param feature
* @param key
* @param layer
* @private
*/
private createActivateFunction(feature, key: string, layer: LayerConfig): (event) => void {
if (this.leafletLayersPerId.has(key)) {
return this.leafletLayersPerId.get(key).activateFunc
}
let infobox: ScrollableFullScreen = undefined
const self = this
@ -373,12 +386,7 @@ export default class ShowDataLayerImplementation {
return
}
const key = feature.properties.id
let activate: (event) => void
if (this.leafletLayersPerId.has(key)) {
activate = this.leafletLayersPerId.get(key).activateFunc
} else {
activate = this.createActivateFunction(feature, key, layer)
}
const activate = this.createActivateFunction(feature, key, layer)
// We also have to open on rightclick, doubleclick, ... as users sometimes do this. See #1219
leafletLayer.on({