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") {
|
if (lastClick.mode !== "left") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.setSelectedElement(lastClick.nearestFeature)
|
const nearestFeature = lastClick.nearestFeature
|
||||||
|
this.setSelectedElement(nearestFeature)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Add the selected element to the recently visited history
|
// Add the selected element to the recently visited history
|
||||||
this.selectedElement.addCallbackD((selected) => {
|
this.selectedElement.addCallbackD((selected) => {
|
||||||
|
console.trace("Selected element is", selected)
|
||||||
const [osm_type, osm_id] = selected.properties.id.split("/")
|
const [osm_type, osm_id] = selected.properties.id.split("/")
|
||||||
const [lon, lat] = GeoOperations.centerpointCoordinates(selected)
|
const [lon, lat] = GeoOperations.centerpointCoordinates(selected)
|
||||||
const layer = this.theme.getMatchingLayer(selected.properties)
|
const layer = this.theme.getMatchingLayer(selected.properties)
|
||||||
|
@ -65,12 +67,21 @@ export class WithSelectedElementState extends UserMapFeatureswitchState {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected setSelectedElement(feature: Feature) {
|
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
|
const current = this.selectedElement.data
|
||||||
if (
|
if (
|
||||||
current?.properties?.id !== undefined &&
|
current?.properties?.id !== undefined &&
|
||||||
current.properties.id === feature?.properties?.id
|
current.properties.id === feature?.properties?.id
|
||||||
) {
|
) {
|
||||||
console.log("Not setting selected, same id", current, feature)
|
|
||||||
return // already set
|
return // already set
|
||||||
}
|
}
|
||||||
this.selectedElement.setData(feature)
|
this.selectedElement.setData(feature)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Feature } from "geojson"
|
import type { Feature } from "geojson"
|
||||||
import { ImmutableStore, Store, UIEventSource } from "../../Logic/UIEventSource"
|
import { Store, UIEventSource } from "../../Logic/UIEventSource"
|
||||||
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
||||||
import type { SpecialVisualizationState } from "../SpecialVisualization"
|
import type { SpecialVisualizationState } from "../SpecialVisualization"
|
||||||
import TagRenderingAnswer from "../Popup/TagRendering/TagRenderingAnswer.svelte"
|
import TagRenderingAnswer from "../Popup/TagRendering/TagRenderingAnswer.svelte"
|
||||||
|
@ -35,7 +35,9 @@
|
||||||
<!-- Title element and title icons-->
|
<!-- Title element and title icons-->
|
||||||
<h3 class="m-0">
|
<h3 class="m-0">
|
||||||
<a href={`#${$tags.id}`}>
|
<a href={`#${$tags.id}`}>
|
||||||
|
{#if layer.title}
|
||||||
<TagRenderingAnswer config={layer.title} {selectedElement} {state} {tags} {layer} />
|
<TagRenderingAnswer config={layer.title} {selectedElement} {state} {tags} {layer} />
|
||||||
|
{/if}
|
||||||
</a>
|
</a>
|
||||||
</h3>
|
</h3>
|
||||||
<div
|
<div
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue