From 6e9d4b327e41af5a4ad8227acea16e5687f2c884 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Tue, 30 Nov 2021 18:10:46 +0100 Subject: [PATCH] Fix selecting another background layer in minimaps --- Logic/UIEventSource.ts | 8 +++++++- UI/BigComponents/BackgroundMapSwitch.ts | 1 + UI/NewPoint/ConfirmLocationOfPoint.ts | 10 +++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Logic/UIEventSource.ts b/Logic/UIEventSource.ts index acbf23f27..ebf4400c2 100644 --- a/Logic/UIEventSource.ts +++ b/Logic/UIEventSource.ts @@ -11,6 +11,10 @@ export class UIEventSource { constructor(data: T, tag: string = "") { this.tag = tag; this.data = data; + if(tag === undefined || tag === ""){ + const callstack = new Error().stack.split("\n") + this.tag = callstack[1] + } UIEventSource.allSources.push(this); } @@ -278,9 +282,11 @@ export class UIEventSource { g: ((j: J, t: T) => T) = undefined): UIEventSource { const self = this; + const stack = new Error().stack.split("\n"); + const callee = stack[1] const newSource = new UIEventSource( f(this.data), - "map(" + this.tag + ")" + "map(" + this.tag + ")@"+callee ); const update = function () { diff --git a/UI/BigComponents/BackgroundMapSwitch.ts b/UI/BigComponents/BackgroundMapSwitch.ts index 16fd17bb3..268fde159 100644 --- a/UI/BigComponents/BackgroundMapSwitch.ts +++ b/UI/BigComponents/BackgroundMapSwitch.ts @@ -197,6 +197,7 @@ export default class BackgroundMapSwitch extends Combine { super(buttons) this.SetClass("flex") + currentBackground.addCallbackAndRun(bg => console.trace("Current background is", bg.id)) } } \ No newline at end of file diff --git a/UI/NewPoint/ConfirmLocationOfPoint.ts b/UI/NewPoint/ConfirmLocationOfPoint.ts index 68e380997..3782ecf2b 100644 --- a/UI/NewPoint/ConfirmLocationOfPoint.ts +++ b/UI/NewPoint/ConfirmLocationOfPoint.ts @@ -12,6 +12,7 @@ import Translations from "../i18n/Translations"; import Svg from "../../Svg"; import Toggle from "../Input/Toggle"; import SimpleAddUI, {PresetInfo} from "../BigComponents/SimpleAddUI"; +import BaseLayer from "../../Models/BaseLayer"; export default class ConfirmLocationOfPoint extends Combine { @@ -19,7 +20,8 @@ export default class ConfirmLocationOfPoint extends Combine { constructor( state: { osmConnection: OsmConnection, - featurePipeline: FeaturePipeline + featurePipeline: FeaturePipeline, + backgroundLayer: UIEventSource }, filterViewIsOpened: UIEventSource, preset: PresetInfo, @@ -35,9 +37,11 @@ export default class ConfirmLocationOfPoint extends Combine { const zloc = {...loc, zoom: 19} const locationSrc = new UIEventSource(zloc); - let backgroundLayer = undefined; + let backgroundLayer = new UIEventSource(state?.backgroundLayer?.data ?? AvailableBaseLayers.osmCarto); if (preset.preciseInput.preferredBackground) { - backgroundLayer = AvailableBaseLayers.SelectBestLayerAccordingTo(locationSrc, new UIEventSource(preset.preciseInput.preferredBackground)) + const defaultBackground = AvailableBaseLayers.SelectBestLayerAccordingTo(locationSrc, new UIEventSource(preset.preciseInput.preferredBackground)); + // Note that we _break the link_ here, as the minimap will take care of the switching! + backgroundLayer.setData(defaultBackground.data) } let snapToFeatures: UIEventSource<{ feature: any }[]> = undefined