Refactoring: add hotkeys to switch backgrounds

This commit is contained in:
Pieter Vander Vennet 2023-04-21 16:47:25 +02:00
parent 3c0a19ebc6
commit ee4b0fd238
8 changed files with 63 additions and 20 deletions

View file

@ -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

View file

@ -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")
)
}
/**

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"
},

View file

@ -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"

View file

@ -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"