forked from MapComplete/MapComplete
Fix: don't crash if an unselected element is selected (by not selecting it)
This commit is contained in:
parent
b10d999b05
commit
981b412180
2 changed files with 16 additions and 3 deletions
|
|
@ -32,11 +32,13 @@ export class WithSelectedElementState extends UserMapFeatureswitchState {
|
|||
if (lastClick.mode !== "left") {
|
||||
return
|
||||
}
|
||||
this.setSelectedElement(lastClick.nearestFeature)
|
||||
const nearestFeature = lastClick.nearestFeature
|
||||
this.setSelectedElement(nearestFeature)
|
||||
})
|
||||
|
||||
// Add the selected element to the recently visited history
|
||||
this.selectedElement.addCallbackD((selected) => {
|
||||
console.trace("Selected element is", selected)
|
||||
const [osm_type, osm_id] = selected.properties.id.split("/")
|
||||
const [lon, lat] = GeoOperations.centerpointCoordinates(selected)
|
||||
const layer = this.theme.getMatchingLayer(selected.properties)
|
||||
|
|
@ -65,12 +67,21 @@ export class WithSelectedElementState extends UserMapFeatureswitchState {
|
|||
}
|
||||
|
||||
protected setSelectedElement(feature: Feature) {
|
||||
if (!feature) {
|
||||
this.selectedElement.setData(undefined)
|
||||
return
|
||||
}
|
||||
const layer = this.theme.getMatchingLayer(feature?.properties)
|
||||
if (layer?.title === undefined) {
|
||||
console.log("Not selecting feature", feature, ": no title (or no matching layer) found, unselectable element")
|
||||
return
|
||||
}
|
||||
|
||||
const current = this.selectedElement.data
|
||||
if (
|
||||
current?.properties?.id !== undefined &&
|
||||
current.properties.id === feature?.properties?.id
|
||||
) {
|
||||
console.log("Not setting selected, same id", current, feature)
|
||||
return // already set
|
||||
}
|
||||
this.selectedElement.setData(feature)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue