Refactoring: fix rendering artefact when switching selected element

This commit is contained in:
Pieter Vander Vennet 2023-04-21 00:25:56 +02:00
parent c6e12fdd6b
commit 3aeedf22c8
4 changed files with 27 additions and 14 deletions

View file

@ -20,7 +20,6 @@ export default class FeaturePropertiesStore {
public trackFeatureSource(source: FeatureSource) { public trackFeatureSource(source: FeatureSource) {
const self = this const self = this
source.features.addCallbackAndRunD((features) => { source.features.addCallbackAndRunD((features) => {
console.log("Re-indexing features")
for (const feature of features) { for (const feature of features) {
const id = feature.properties.id const id = feature.properties.id
if (id === undefined) { if (id === undefined) {

View file

@ -71,7 +71,7 @@ export default class MetaTagging {
return return
} }
console.log("Recalculating metatags...") console.trace("Recalculating metatags...")
const metatagsToApply: SimpleMetaTagger[] = [] const metatagsToApply: SimpleMetaTagger[] = []
for (const metatag of SimpleMetaTaggers.metatags) { for (const metatag of SimpleMetaTaggers.metatags) {
if (metatag.includesDates) { if (metatag.includesDates) {

View file

@ -302,6 +302,10 @@ export default class ThemeViewState implements SpecialVisualizationState {
}) })
return return
} }
// We first clear the selection to make sure no weird state is around
this.selectedLayer.setData(undefined)
this.selectedElement.setData(undefined)
this.selectedElement.setData(feature) this.selectedElement.setData(feature)
this.selectedLayer.setData(last_click_layer.layerDef) this.selectedLayer.setData(last_click_layer.layerDef)
}, },

View file

@ -1,5 +1,5 @@
<script lang="ts"> <script lang="ts">
import { Store, UIEventSource } from "../Logic/UIEventSource"; import { UIEventSource } from "../Logic/UIEventSource";
import { Map as MlMap } from "maplibre-gl"; import { Map as MlMap } from "maplibre-gl";
import MaplibreMap from "./Map/MaplibreMap.svelte"; import MaplibreMap from "./Map/MaplibreMap.svelte";
import FeatureSwitchState from "../Logic/State/FeatureSwitchState"; import FeatureSwitchState from "../Logic/State/FeatureSwitchState";
@ -32,19 +32,31 @@
import ModalRight from "./Base/ModalRight.svelte"; import ModalRight from "./Base/ModalRight.svelte";
import { Utils } from "../Utils"; import { Utils } from "../Utils";
import Hotkeys from "./Base/Hotkeys"; import Hotkeys from "./Base/Hotkeys";
import { VariableUiElement } from "./Base/VariableUIElement";
import SvelteUIElement from "./Base/SvelteUIElement";
import { onDestroy } from "svelte";
export let state: ThemeViewState; export let state: ThemeViewState;
let layout = state.layout; let layout = state.layout;
let selectedElementTags: Store<UIEventSource<Record<string, string>>> =
state.selectedElement.mapD((f) => {
return state.featureProperties.getStore(f.properties.id);
}
);
let maplibremap: UIEventSource<MlMap> = state.map; let maplibremap: UIEventSource<MlMap> = state.map;
let selectedElement: UIEventSource<Feature> = state.selectedElement; let selectedElement: UIEventSource<Feature> = state.selectedElement;
let selectedLayer: UIEventSource<LayerConfig> = state.selectedLayer; let selectedLayer: UIEventSource<LayerConfig> = state.selectedLayer;
const selectedViewElement = selectedElement.map(selectedElement => {
// Svelte doesn't properly reload some of the legacy UI-elements
// As such, we _reconstruct_ the selectedElementView every time a new feature is selected
// This is a bit wasteful, but until everything is a svelte-component, this should do the trick
const layer = selectedLayer.data;
if (selectedElement === undefined || layer === undefined) {
return undefined;
}
const tags = state.featureProperties.getStore(selectedElement.properties.id);
return new SvelteUIElement(SelectedElementView, {state, layer, selectedElement, tags})
}, [selectedLayer]);
let mapproperties: MapProperties = state.mapProperties; let mapproperties: MapProperties = state.mapProperties;
let featureSwitches: FeatureSwitchState = state.featureSwitches; let featureSwitches: FeatureSwitchState = state.featureSwitches;
let availableLayers = state.availableLayers; let availableLayers = state.availableLayers;
@ -101,13 +113,11 @@
</If> </If>
</div> </div>
{#if $selectedElement !== undefined && $selectedLayer !== undefined} <If condition={selectedViewElement.map(v => v !== undefined)}>
<ModalRight on:close={() => {selectedElement.setData(undefined)}}> <ModalRight on:close={() => {selectedElement.setData(undefined)}}>
<SelectedElementView layer={$selectedLayer} selectedElement={$selectedElement} <ToSvelte construct={new VariableUiElement(selectedViewElement)}></ToSvelte>
tags={$selectedElementTags} state={state} />
</ModalRight> </ModalRight>
</If>
{/if}
<If condition={state.guistate.themeIsOpened}> <If condition={state.guistate.themeIsOpened}>
<!-- Theme page --> <!-- Theme page -->