forked from MapComplete/MapComplete
Refactoring: split 'ThemeViewState' into many classes
This commit is contained in:
parent
2b858bd2aa
commit
dbcbf2787d
34 changed files with 1503 additions and 1227 deletions
72
src/Models/ThemeViewState/WithSearchState.ts
Normal file
72
src/Models/ThemeViewState/WithSearchState.ts
Normal file
|
@ -0,0 +1,72 @@
|
|||
import ThemeConfig from "../ThemeConfig/ThemeConfig"
|
||||
import SearchState from "../../Logic/State/SearchState"
|
||||
import Hotkeys from "../../UI/Base/Hotkeys"
|
||||
import Translations from "../../UI/i18n/Translations"
|
||||
import Zoomcontrol from "../../UI/Zoomcontrol"
|
||||
import { WithVisualFeedbackState } from "./WithVisualFeedbackState"
|
||||
import { ShowDataLayerOptions } from "../../UI/Map/ShowDataLayerOptions"
|
||||
import LayerConfig from "../ThemeConfig/LayerConfig"
|
||||
import ShowDataLayer from "../../UI/Map/ShowDataLayer"
|
||||
|
||||
export class WithSearchState extends WithVisualFeedbackState {
|
||||
public readonly searchState: SearchState
|
||||
|
||||
constructor(theme: ThemeConfig, mvtAvailableLayers: Set<string>) {
|
||||
super(theme, mvtAvailableLayers)
|
||||
this.searchState = new SearchState(this)
|
||||
this.initHotkeysSearch()
|
||||
|
||||
{
|
||||
// Register the search layer on the map
|
||||
|
||||
const source = this.searchState.locationResults
|
||||
const flayer = this.layerState.filteredLayers.get("search")
|
||||
this.featureProperties.trackFeatureSource(source)
|
||||
const options: ShowDataLayerOptions & { layer: LayerConfig } = {
|
||||
features: source,
|
||||
doShowLayer: flayer.isDisplayed,
|
||||
layer: flayer.layerDef,
|
||||
metaTags: this.userRelatedState.preferencesAsTags,
|
||||
onClick: (feature) => {
|
||||
this.searchState.clickedOnMap(feature)
|
||||
}
|
||||
}
|
||||
new ShowDataLayer(this.map, options)
|
||||
}
|
||||
}
|
||||
|
||||
private initHotkeysSearch() {
|
||||
const docs = Translations.t.hotkeyDocumentation
|
||||
|
||||
Hotkeys.RegisterHotkey(
|
||||
{ ctrl: "F" },
|
||||
docs.selectSearch,
|
||||
() => {
|
||||
this.searchState.feedback.set(undefined)
|
||||
this.searchState.searchIsFocused.set(true)
|
||||
}
|
||||
)
|
||||
|
||||
Hotkeys.RegisterHotkey({ nomod: "Escape", onUp: true }, docs.closeSidebar, () => {
|
||||
if (this.previewedImage.data !== undefined) {
|
||||
this.previewedImage.setData(undefined)
|
||||
return
|
||||
}
|
||||
if (this.selectedElement.data) {
|
||||
this.selectedElement.setData(undefined)
|
||||
return
|
||||
}
|
||||
if (this.searchState.showSearchDrawer.data) {
|
||||
this.searchState.showSearchDrawer.set(false)
|
||||
return
|
||||
}
|
||||
if (this.guistate.closeAll()) {
|
||||
return
|
||||
}
|
||||
Zoomcontrol.resetzoom()
|
||||
this.focusOnMap()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue