forked from MapComplete/MapComplete
Refactoring: use theme instead of layout in a lot of places
This commit is contained in:
parent
9427083939
commit
bdc9ba52a6
104 changed files with 445 additions and 449 deletions
|
|
@ -4,7 +4,7 @@ import Constants from "../../Models/Constants"
|
|||
import FilterConfig, { FilterConfigOption } from "../../Models/ThemeConfig/FilterConfig"
|
||||
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
||||
import LayerState from "../State/LayerState"
|
||||
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"
|
||||
import ThemeConfig from "../../Models/ThemeConfig/ThemeConfig"
|
||||
|
||||
export type FilterSearchResult = { option: FilterConfigOption, filter: FilterConfig, layer: LayerConfig, index: number }
|
||||
|
||||
|
|
@ -13,9 +13,9 @@ export type FilterSearchResult = { option: FilterConfigOption, filter: FilterCon
|
|||
* Searches matching filters
|
||||
*/
|
||||
export default class FilterSearch {
|
||||
private readonly _state: {layerState: LayerState, layout: LayoutConfig}
|
||||
private readonly _state: {layerState: LayerState, theme: ThemeConfig}
|
||||
|
||||
constructor(state: {layerState: LayerState, layout: LayoutConfig}) {
|
||||
constructor(state: {layerState: LayerState, theme: ThemeConfig}) {
|
||||
this._state = state
|
||||
}
|
||||
|
||||
|
|
@ -30,7 +30,7 @@ export default class FilterSearch {
|
|||
return query
|
||||
}).filter(q => q.length > 0)
|
||||
const possibleFilters: FilterSearchResult[] = []
|
||||
for (const layer of this._state.layout.layers) {
|
||||
for (const layer of this._state.theme.layers) {
|
||||
if (!Array.isArray(layer.filters)) {
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
import SearchUtils from "./SearchUtils"
|
||||
import ThemeSearch from "./ThemeSearch"
|
||||
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
||||
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"
|
||||
import ThemeConfig from "../../Models/ThemeConfig/ThemeConfig"
|
||||
import { Utils } from "../../Utils"
|
||||
|
||||
export default class LayerSearch {
|
||||
|
||||
private readonly _layout: LayoutConfig
|
||||
private readonly _theme: ThemeConfig
|
||||
private readonly _layerWhitelist: Set<string>
|
||||
|
||||
constructor(layout: LayoutConfig) {
|
||||
this._layout = layout
|
||||
this._layerWhitelist = new Set(layout.layers
|
||||
constructor(theme: ThemeConfig) {
|
||||
this._theme = theme
|
||||
this._layerWhitelist = new Set(theme.layers
|
||||
.filter(l => l.isNormal())
|
||||
.map(l => l.id))
|
||||
}
|
||||
|
|
@ -29,8 +29,7 @@ export default class LayerSearch {
|
|||
continue
|
||||
}
|
||||
const keywords = ThemeSearch.officialThemes.layers[id]
|
||||
const distance = Math.min(...queryParts.map(q => SearchUtils.scoreKeywords(q, keywords)))
|
||||
result[id] = distance
|
||||
result[id] = Math.min(...queryParts.map(q => SearchUtils.scoreKeywords(q, keywords)))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
@ -44,7 +43,7 @@ export default class LayerSearch {
|
|||
const asList: ({ layer: LayerConfig, score: number })[] = []
|
||||
for (const layer in scores) {
|
||||
asList.push({
|
||||
layer: this._layout.getLayer(layer),
|
||||
layer: this._theme.getLayer(layer),
|
||||
score: scores[layer],
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import LayoutConfig, { MinimalLayoutInformation } from "../../Models/ThemeConfig/LayoutConfig"
|
||||
import ThemeConfig, { MinimalThemeInformation } from "../../Models/ThemeConfig/ThemeConfig"
|
||||
import { Store } from "../UIEventSource"
|
||||
import UserRelatedState from "../State/UserRelatedState"
|
||||
import { Utils } from "../../Utils"
|
||||
|
|
@ -10,7 +10,7 @@ import { OsmConnection } from "../Osm/OsmConnection"
|
|||
|
||||
|
||||
type ThemeSearchScore = {
|
||||
theme: MinimalLayoutInformation,
|
||||
theme: MinimalThemeInformation,
|
||||
lowest: number,
|
||||
perLayer?: Record<string, number>,
|
||||
other: number,
|
||||
|
|
@ -20,10 +20,10 @@ type ThemeSearchScore = {
|
|||
export default class ThemeSearch {
|
||||
|
||||
public static readonly officialThemes: {
|
||||
themes: MinimalLayoutInformation[],
|
||||
themes: MinimalThemeInformation[],
|
||||
layers: Record<string, Record<string, string[]>>
|
||||
} = <any> themeOverview
|
||||
public static readonly officialThemesById: Map<string, MinimalLayoutInformation> = new Map<string, MinimalLayoutInformation>()
|
||||
public static readonly officialThemesById: Map<string, MinimalThemeInformation> = new Map<string, MinimalThemeInformation>()
|
||||
static {
|
||||
for (const th of ThemeSearch.officialThemes.themes ?? []) {
|
||||
ThemeSearch.officialThemesById.set(th.id, th)
|
||||
|
|
@ -33,17 +33,17 @@ export default class ThemeSearch {
|
|||
|
||||
private readonly _knownHiddenThemes: Store<Set<string>>
|
||||
private readonly _layersToIgnore: string[]
|
||||
private readonly _otherThemes: MinimalLayoutInformation[]
|
||||
private readonly _otherThemes: MinimalThemeInformation[]
|
||||
|
||||
constructor(state: {osmConnection: OsmConnection, layout: LayoutConfig}) {
|
||||
this._layersToIgnore = state.layout.layers.filter(l => l.isNormal()).map(l => l.id)
|
||||
constructor(state: {osmConnection: OsmConnection, theme: ThemeConfig}) {
|
||||
this._layersToIgnore = state.theme.layers.filter(l => l.isNormal()).map(l => l.id)
|
||||
this._knownHiddenThemes = UserRelatedState.initDiscoveredHiddenThemes(state.osmConnection).map(list => new Set(list))
|
||||
this._otherThemes = ThemeSearch.officialThemes.themes
|
||||
.filter(th => th.id !== state.layout.id)
|
||||
.filter(th => th.id !== state.theme.id)
|
||||
}
|
||||
|
||||
|
||||
public search(query: string, limit: number, threshold: number = 3): MinimalLayoutInformation[] {
|
||||
public search(query: string, limit: number, threshold: number = 3): MinimalThemeInformation[] {
|
||||
if (query.length < 1) {
|
||||
return []
|
||||
}
|
||||
|
|
@ -101,7 +101,7 @@ export default class ThemeSearch {
|
|||
* @param ignoreLayers
|
||||
* @private
|
||||
*/
|
||||
private static scoreThemes(query: string, themes: MinimalLayoutInformation[], ignoreLayers: string[] = undefined): Record<string, ThemeSearchScore> {
|
||||
private static scoreThemes(query: string, themes: MinimalThemeInformation[], ignoreLayers: string[] = undefined): Record<string, ThemeSearchScore> {
|
||||
if (query?.length < 1) {
|
||||
return undefined
|
||||
}
|
||||
|
|
@ -147,13 +147,13 @@ export default class ThemeSearch {
|
|||
return results
|
||||
}
|
||||
|
||||
public static sortedByLowestScores(search: string, themes: MinimalLayoutInformation[], ignoreLayers: string[] = []): ThemeSearchScore[] {
|
||||
public static sortedByLowestScores(search: string, themes: MinimalThemeInformation[], ignoreLayers: string[] = []): ThemeSearchScore[] {
|
||||
const scored = Object.values(this.scoreThemes(search, themes, ignoreLayers))
|
||||
scored.sort((a, b) => a.lowest - b.lowest)
|
||||
return scored
|
||||
}
|
||||
|
||||
public static sortedByLowest(search: string, themes: MinimalLayoutInformation[], ignoreLayers: string[] = []): MinimalLayoutInformation[] {
|
||||
public static sortedByLowest(search: string, themes: MinimalThemeInformation[], ignoreLayers: string[] = []): MinimalThemeInformation[] {
|
||||
return this.sortedByLowestScores(search, themes, ignoreLayers)
|
||||
.map(th => th.theme)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue