From 82093ffdf4cacf3d40e9cc38b84ed0d3e70f29c5 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Thu, 18 May 2023 15:44:54 +0200 Subject: [PATCH] Refactoring: new background selector --- Models/MenuState.ts | 4 + .../Conversion/CreateNoteImportLayer.ts | 8 +- Models/ThemeViewState.ts | 4 +- UI/Base/FloatOver.svelte | 2 +- UI/Base/IfHidden.svelte | 33 ++++ UI/Base/WeblateLink.svelte | 4 +- UI/BigComponents/BackgroundSwitcher.svelte | 82 ++++---- UI/BigComponents/CopyrightPanel.ts | 26 ++- UI/BigComponents/Geosearch.svelte | 180 ++++++++++-------- UI/BigComponents/HiddenThemeList.svelte | 2 +- UI/BigComponents/SelectedElementTitle.svelte | 2 +- UI/BigComponents/ThemeIntroPanel.svelte | 87 +++++++++ UI/Map/MapLibreAdaptor.ts | 11 +- UI/Map/OverlayMap.svelte | 69 +++++++ UI/Map/RasterLayerOverview.svelte | 73 +++++++ UI/Map/RasterLayerPicker.svelte | 87 +++++++-- UI/ThemeViewGUI.svelte | 138 ++++++-------- assets/layers/cafe_pub/cafe_pub.json | 4 +- .../charging_station/charging_station.json | 12 +- index.css | 7 + langs/en.json | 6 +- langs/nl.json | 4 +- package-lock.json | 21 +- package.json | 1 + public/css/index-tailwind-output.css | 60 ++++-- 25 files changed, 658 insertions(+), 269 deletions(-) create mode 100644 UI/Base/IfHidden.svelte create mode 100644 UI/BigComponents/ThemeIntroPanel.svelte create mode 100644 UI/Map/OverlayMap.svelte create mode 100644 UI/Map/RasterLayerOverview.svelte diff --git a/Models/MenuState.ts b/Models/MenuState.ts index 9cb84a00f..476006f26 100644 --- a/Models/MenuState.ts +++ b/Models/MenuState.ts @@ -24,6 +24,8 @@ export class MenuState { public readonly menuViewTabIndex: UIEventSource public readonly menuViewTab: UIEventSource + public readonly backgroundLayerSelectionIsOpened: UIEventSource = new UIEventSource(false) + public readonly highlightedLayerInFilters: UIEventSource = new UIEventSource( undefined ) @@ -102,5 +104,7 @@ export class MenuState { public closeAll() { this.menuIsOpened.setData(false) this.themeIsOpened.setData(false) + this.backgroundLayerSelectionIsOpened.setData(false) } + } diff --git a/Models/ThemeConfig/Conversion/CreateNoteImportLayer.ts b/Models/ThemeConfig/Conversion/CreateNoteImportLayer.ts index d74f1f8f5..daba77ce9 100644 --- a/Models/ThemeConfig/Conversion/CreateNoteImportLayer.ts +++ b/Models/ThemeConfig/Conversion/CreateNoteImportLayer.ts @@ -106,11 +106,11 @@ export default class CreateNoteImportLayer extends Conversion {const lines = feat.properties['_first_comment'].split('\\n'); const matchesMapCompleteURL = lines.map(l => l.match(\".*https://mapcomplete.osm.be/\\([a-zA-Z_-]+\\)\\(.html\\)?.*#import\")); const matchedIndexes = matchesMapCompleteURL.map((doesMatch, i) => [doesMatch !== null, i]).filter(v => v[0]).map(v => v[1]); return matchedIndexes[0] })()", - "_comments_count=feat.get('comments').length", - "_intro=(() => {const lines = feat.get('comments')[0].text.split('\\n'); lines.splice(feat.get('_trigger_index')-1, lines.length); return lines.filter(l => l !== '').join('
');})()", - "_tags=(() => {let lines = feat.get('comments')[0].text.split('\\n').map(l => l.trim()); lines.splice(0, feat.get('_trigger_index') + 1); lines = lines.filter(l => l != ''); return lines.join(';');})()", + "_comments_count=get(feat)('comments').length", + "_intro=(() => {const lines = get(feat)('comments')[0].text.split('\\n'); lines.splice(get(feat)('_trigger_index')-1, lines.length); return lines.filter(l => l !== '').join('
');})()", + "_tags=(() => {let lines = get(feat)('comments')[0].text.split('\\n').map(l => l.trim()); lines.splice(0, get(feat)('_trigger_index') + 1); lines = lines.filter(l => l != ''); return lines.join(';');})()", ], isShown: { and: ["_trigger_index~*", { or: isShownIfAny }], diff --git a/Models/ThemeViewState.ts b/Models/ThemeViewState.ts index b01e7e4fc..0a27bb066 100644 --- a/Models/ThemeViewState.ts +++ b/Models/ThemeViewState.ts @@ -303,7 +303,9 @@ export default class ThemeViewState implements SpecialVisualizationState { this.drawSpecialLayers() this.initHotkeys() this.miscSetup() - console.log("State setup completed", this) + if(!Utils.runningFromConsole){ + console.log("State setup completed", this) + } } /** diff --git a/UI/Base/FloatOver.svelte b/UI/Base/FloatOver.svelte index 6cbb25155..e7c4a0ca5 100644 --- a/UI/Base/FloatOver.svelte +++ b/UI/Base/FloatOver.svelte @@ -10,7 +10,7 @@
-
+
diff --git a/UI/Base/IfHidden.svelte b/UI/Base/IfHidden.svelte new file mode 100644 index 000000000..7f38dd20e --- /dev/null +++ b/UI/Base/IfHidden.svelte @@ -0,0 +1,33 @@ + + +{#if hasBeenShownPositive} + + + +{/if} + +{#if hasBeenShownNegative} + + + +{/if} diff --git a/UI/Base/WeblateLink.svelte b/UI/Base/WeblateLink.svelte index 289aba990..906585d46 100644 --- a/UI/Base/WeblateLink.svelte +++ b/UI/Base/WeblateLink.svelte @@ -16,11 +16,11 @@ {#if context} {#if $linkOnMobile} - + {:else if $linkToWeblate} - + {/if} diff --git a/UI/BigComponents/BackgroundSwitcher.svelte b/UI/BigComponents/BackgroundSwitcher.svelte index 7c948cb42..62a1b9127 100644 --- a/UI/BigComponents/BackgroundSwitcher.svelte +++ b/UI/BigComponents/BackgroundSwitcher.svelte @@ -3,13 +3,13 @@ import type {RasterLayerPolygon} from "../../Models/RasterLayers"; import {AvailableRasterLayers} from "../../Models/RasterLayers"; import Tr from "../Base/Tr.svelte"; - import {onDestroy} from "svelte"; + import {createEventDispatcher, onDestroy} from "svelte"; import Translations from "../i18n/Translations"; import Svg from "../../Svg"; import {Map as MlMap} from "maplibre-gl" - import MaplibreMap from "../Map/MaplibreMap.svelte"; - import {MapLibreAdaptor} from "../Map/MapLibreAdaptor"; import type {MapProperties} from "../../Models/MapProperties"; + import OverlayMap from "../Map/OverlayMap.svelte"; + import RasterLayerPicker from "../Map/RasterLayerPicker.svelte"; export let mapproperties: MapProperties export let normalMap: UIEventSource @@ -28,63 +28,55 @@ */ export let availableRasterLayers: Store - let altmap: UIEventSource = new UIEventSource(undefined) - let altproperties = new MapLibreAdaptor(altmap, {zoom: UIEventSource.feedFrom(mapproperties.zoom)}) - altproperties.allowMoving.setData(false) - altproperties.allowZooming.setData(false) - let altmap0: UIEventSource = new UIEventSource(undefined) - let altproperties0 = new MapLibreAdaptor(altmap0, {zoom: altproperties.zoom}) - // altproperties0.allowMoving.setData(false) - // altproperties0.allowZooming.setData(false) + let raster0 = new UIEventSource(undefined) + + let raster1 = new UIEventSource(undefined) + + let currentLayer: RasterLayerPolygon function updatedAltLayer() { const available = availableRasterLayers.data const current = rasterLayer.data const defaultLayer = AvailableRasterLayers.maplibre - const firstOther = available.find(l => l !== current && l !== defaultLayer) - - altproperties.rasterLayer.setData(firstOther) - const secondOther = available.find(l => l !== current && l !== firstOther && l !== defaultLayer) - altproperties0.rasterLayer.setData(secondOther) - + const firstOther = available.find(l => l !== defaultLayer) + const secondOther = available.find(l => l !== defaultLayer && l !== firstOther) + raster0.setData(firstOther === current ? defaultLayer : firstOther) + raster1.setData(secondOther === current ? defaultLayer : secondOther) } + updatedAltLayer() + onDestroy(mapproperties.rasterLayer.addCallbackAndRunD(updatedAltLayer)) onDestroy(availableRasterLayers.addCallbackAndRunD(updatedAltLayer)) - onDestroy(rasterLayer.addCallbackAndRunD(updatedAltLayer)) - function pixelCenterOf(map: UIEventSource): [number, number] { - const rect = map?.data?.getCanvas()?.getBoundingClientRect() - if (!rect) { - return undefined + function use(rasterLayer: UIEventSource): (() => void) { + return () => { + currentLayer = undefined + mapproperties.rasterLayer.setData(rasterLayer.data) } - const x = (rect.left + rect.right) / 2 - const y = (rect.top + rect.bottom) / 2 - return [x, y] } - mapproperties.location.addCallbackAndRunD(({lon, lat}) => { - if (!normalMap.data || !altmap.data) { - return - } - const altMapCenter = pixelCenterOf(altmap) - const c = normalMap.data.unproject(altMapCenter) - altproperties.location.setData({lon: c.lng, lat: c.lat}) - const altMapCenter0 = pixelCenterOf(altmap0) - const c0 = normalMap.data.unproject(altMapCenter0) - altproperties0.location.setData({lon: c0.lng, lat: c0.lat}) - }) + const dispatch = createEventDispatcher<{ copyright_clicked }>() -
-
- +
+
+ +
-
- -
-
- Current background: - +
+ +
+ +
+ +
diff --git a/UI/BigComponents/CopyrightPanel.ts b/UI/BigComponents/CopyrightPanel.ts index 3e8a3f470..08459ea60 100644 --- a/UI/BigComponents/CopyrightPanel.ts +++ b/UI/BigComponents/CopyrightPanel.ts @@ -22,6 +22,7 @@ import ContributorCount from "../../Logic/ContributorCount" import Img from "../Base/Img" import { TypedTranslation } from "../i18n/Translation" import GeoIndexedStore from "../../Logic/FeatureSource/Actors/GeoIndexedStore" +import {RasterLayerPolygon} from "../../Models/RasterLayers"; export class OpenIdEditor extends VariableUiElement { constructor( @@ -113,7 +114,7 @@ export default class CopyrightPanel extends Combine { constructor(state: { layout: LayoutConfig - mapProperties: { bounds: Store } + mapProperties: { readonly bounds: Store, readonly rasterLayer: Store } osmConnection: OsmConnection dataIsLoading: Store perLayer: ReadonlyMap @@ -173,6 +174,29 @@ export default class CopyrightPanel extends Combine { [ new Title(t.attributionTitle), t.attributionContent, + + new VariableUiElement(state.mapProperties.rasterLayer.mapD(layer => { + const props = layer.properties + const attrUrl = props.attribution?.url + const attrText = props.attribution?.text + + let bgAttr: BaseUIElement | string = undefined + if(attrText && attrUrl){ + bgAttr = ""+attrText+"" + }else if(attrUrl){ + bgAttr = attrUrl + }else{ + bgAttr = attrText + } + if(bgAttr){ + return Translations.t.general.attribution.attributionBackgroundLayerWithCopyright.Subs({ + name: props.name, + copyright: bgAttr + }) + } + return Translations.t.general.attribution.attributionBackgroundLayer.Subs(props) + })), + maintainer, dataContributors, CopyrightPanel.CodeContributors(contributors, t.codeContributionsBy), diff --git a/UI/BigComponents/Geosearch.svelte b/UI/BigComponents/Geosearch.svelte index 44aced7f0..330f74387 100644 --- a/UI/BigComponents/Geosearch.svelte +++ b/UI/BigComponents/Geosearch.svelte @@ -1,100 +1,116 @@
-
+ - {#if isRunning} - {Translations.t.general.search.searching} - {:else if feedback !== undefined} -
feedback = undefined}> - {feedback} -
- {:else } - keypr.key === "Enter" ? performSearch() : undefined} + {#if isRunning} + {Translations.t.general.search.searching} + {:else if feedback !== undefined} +
feedback = undefined}> + {feedback} +
+ {:else } + keypr.key === "Enter" ? performSearch() : undefined} - bind:value={searchContents} - placeholder={Translations.t.general.search.search}> - {/if} + bind:value={searchContents} + placeholder={Translations.t.general.search.search}> + {/if} -
-
- -
+ +
+ +
diff --git a/UI/BigComponents/HiddenThemeList.svelte b/UI/BigComponents/HiddenThemeList.svelte index 88db67e8f..eabf33dfb 100644 --- a/UI/BigComponents/HiddenThemeList.svelte +++ b/UI/BigComponents/HiddenThemeList.svelte @@ -13,7 +13,7 @@ export let onMainScreen: boolean = true const prefix = "mapcomplete-hidden-theme-" - const hiddenThemes: LayoutInformation[] = themeOverview["default"].filter( + const hiddenThemes: LayoutInformation[] = themeOverview.filter( (layout) => layout.hideFromOverview ) const userPreferences = state.osmConnection.preferencesHandler.preferences diff --git a/UI/BigComponents/SelectedElementTitle.svelte b/UI/BigComponents/SelectedElementTitle.svelte index 960f6bd11..5172b0cab 100644 --- a/UI/BigComponents/SelectedElementTitle.svelte +++ b/UI/BigComponents/SelectedElementTitle.svelte @@ -39,7 +39,7 @@ {layer}> -