diff --git a/Models/RasterLayerProperties.ts b/Models/RasterLayerProperties.ts index a4bf0e09b..2686ebe2a 100644 --- a/Models/RasterLayerProperties.ts +++ b/Models/RasterLayerProperties.ts @@ -1,3 +1,12 @@ +export type EliCategory = + | "photo" + | "map" + | "historicmap" + | "osmbasedmap" + | "historicphoto" + | "qa" + | "elevation" + | "other" export interface RasterLayerProperties { /** * The name of the imagery source @@ -9,16 +18,7 @@ export interface RasterLayerProperties { readonly id: string readonly url: string - readonly category?: - | string - | "photo" - | "map" - | "historicmap" - | "osmbasedmap" - | "historicphoto" - | "qa" - | "elevation" - | "other" + readonly category?: string | EliCategory readonly attribution?: { readonly url?: string diff --git a/Models/ThemeViewState.ts b/Models/ThemeViewState.ts index b36be04b0..53afde28d 100644 --- a/Models/ThemeViewState.ts +++ b/Models/ThemeViewState.ts @@ -45,6 +45,7 @@ import { NewGeometryFromChangesFeatureSource } from "../Logic/FeatureSource/Sour import OsmObjectDownloader from "../Logic/Osm/OsmObjectDownloader" import ShowOverlayRasterLayer from "../UI/Map/ShowOverlayRasterLayer" import { Utils } from "../Utils" +import { EliCategory } from "./RasterLayerProperties" /** * @@ -291,14 +292,59 @@ export default class ThemeViewState implements SpecialVisualizationState { } } ) - /* + Hotkeys.RegisterHotkey( { shift: "O" }, Translations.t.hotkeyDocumentation.selectMapnik, () => { - this.state.backgroundLayer.setData(AvailableBaseLayers.osmCarto) + this.mapProperties.rasterLayer.setData(AvailableRasterLayers.osmCarto) } - )//*/ + ) + const self = this + + function setLayerCategory(category: EliCategory) { + const available = self.availableLayers.data + const matchingCategoryLayers = available.filter( + (l) => l.properties.category === category + ) + const best = + matchingCategoryLayers.find((l) => l.properties.best) ?? matchingCategoryLayers[0] + const rasterLayer = self.mapProperties.rasterLayer + if (rasterLayer.data !== best) { + rasterLayer.setData(best) + return + } + + // The current layer is already selected... + // We switch the layers again + + if (category === "osmbasedmap") { + rasterLayer.setData(undefined) + } else { + // search the _second_ best layer + const secondbest = matchingCategoryLayers.find( + (l) => l.properties.best && l !== best + ) + const secondNotBest = matchingCategoryLayers.find((l) => l !== best) + rasterLayer.setData(secondbest ?? secondNotBest) + } + } + + Hotkeys.RegisterHotkey( + { nomod: "O" }, + Translations.t.hotkeyDocumentation.selectOsmbasedmap, + () => setLayerCategory("osmbasedmap") + ) + + Hotkeys.RegisterHotkey({ nomod: "M" }, Translations.t.hotkeyDocumentation.selectMap, () => + setLayerCategory("map") + ) + + Hotkeys.RegisterHotkey( + { nomod: "P" }, + Translations.t.hotkeyDocumentation.selectAerial, + () => setLayerCategory("photo") + ) } /** diff --git a/langs/ca.json b/langs/ca.json index d2b7381c6..b4a7c3f40 100644 --- a/langs/ca.json +++ b/langs/ca.json @@ -362,7 +362,6 @@ "intro": "MapComplete admet les tecles següents:", "key": "Combinació de tecles", "openLayersPanel": "Obre el panell de fons, capes i filtres", - "selectBackground": "Seleccioneu una capa de fons de la categoria {category}", "selectMapnik": "Estableix la capa de fons OpenStreetMap-carto", "selectSearch": "Seleccioneu la barra de cerca per cercar ubicacions", "title": "Dreceres" diff --git a/langs/cs.json b/langs/cs.json index 48fad68b1..ddccbedb9 100644 --- a/langs/cs.json +++ b/langs/cs.json @@ -207,7 +207,6 @@ "intro": "MapComplete podporuje následující klávesy:", "key": "Kombinace kláves", "openLayersPanel": "Otevře panel Pozadí, vrstvy a filtry", - "selectBackground": "Vybrat vrstvu pozadí kategorie {category}", "selectMapnik": "Nastaví vrstvu pozadí na OpenStreetMap-carto", "selectSearch": "Vybere vyhledávací řádek pro vyhledávání míst", "title": "Klávesové zkratky" diff --git a/langs/de.json b/langs/de.json index 0931ed5af..2b56ad03a 100644 --- a/langs/de.json +++ b/langs/de.json @@ -362,7 +362,6 @@ "intro": "MapComplete unterstützt folgende Tastaturbefehle:", "key": "Tastenkombination", "openLayersPanel": "Öffnet das Bedienfeld Hintergrund, Ebenen und Filter", - "selectBackground": "Wählen Sie eine Hintergrundebene der Kategorie {category} aus", "selectMapnik": "Setzt die Hintergrundebene auf OpenStreetMap-carto", "selectSearch": "Suchleiste auswählen, um nach Orten zu suchen", "title": "Tastaturbefehle" diff --git a/langs/en.json b/langs/en.json index dc34045bc..eceb2a6aa 100644 --- a/langs/en.json +++ b/langs/en.json @@ -386,8 +386,10 @@ "intro": "MapComplete supports the following keys:", "key": "Key combination", "openLayersPanel": "Opens the Background, layers and filters panel", - "selectBackground": "Select a background layer of category {category}", - "selectMapnik": "Sets the background layer to OpenStreetMap-carto", + "selectAerial": "Set the background to aerial or satellite imagery. Toggles between the two best, available layers", + "selectMap": "Set the background to a map from external sources. Toggles between the two best, available layers", + "selectMapnik": "Set the background layer to OpenStreetMap-carto", + "selectOsmbasedmap": "Set the background layer to on OpenStreetMap-based map (or disable the background raster layer)", "selectSearch": "Select the search bar to search locations", "title": "Hotkeys" }, diff --git a/langs/fr.json b/langs/fr.json index 15b2c80d8..09455c6c9 100644 --- a/langs/fr.json +++ b/langs/fr.json @@ -311,7 +311,6 @@ "closeSidebar": "Fermer la barre latérale", "key": "Combinaison de touches", "openLayersPanel": "Ouvre le panneau fond-de-plan, couches et filtres", - "selectBackground": "Sélectionnez un fond de carte de type {category}", "selectMapnik": "Appliquer le fond de carte OpenStreetMap-carto", "selectSearch": "Sélectionner la barre de recherche de lieux", "title": "Raccourcis clavier" diff --git a/langs/nl.json b/langs/nl.json index 3635b3c94..e9f5f26b2 100644 --- a/langs/nl.json +++ b/langs/nl.json @@ -362,7 +362,6 @@ "intro": "MapComplete ondersteunt de volgende sneltoetsen:", "key": "Toets-combinatie", "openLayersPanel": "Open het paneel met lagen, filters en achtergrondkaart", - "selectBackground": "Selecteer een achtergrondlaag van category {category}", "selectMapnik": "Selecteer OpenStreetMap-carto als achtergrondlaag", "selectSearch": "Selecteer de zoekbalk om locaties te zoeken", "title": "Sneltoetsen"