forked from MapComplete/MapComplete
refactoring
This commit is contained in:
parent
b94a8f5745
commit
5d0fe31c41
114 changed files with 2412 additions and 2958 deletions
|
@ -5,7 +5,6 @@ import Translations from "../../UI/i18n/Translations"
|
|||
import { TagUtils } from "../../Logic/Tags/TagUtils"
|
||||
import { TagConfigJson } from "./Json/TagConfigJson"
|
||||
import { UIEventSource } from "../../Logic/UIEventSource"
|
||||
import { FilterState } from "../FilteredLayer"
|
||||
import { QueryParameters } from "../../Logic/Web/QueryParameters"
|
||||
import { Utils } from "../../Utils"
|
||||
import { RegexTag } from "../../Logic/Tags/RegexTag"
|
||||
|
@ -144,14 +143,7 @@ export default class FilterConfig {
|
|||
})
|
||||
}
|
||||
|
||||
public initState(): UIEventSource<FilterState> {
|
||||
function reset(state: FilterState): string {
|
||||
if (state === undefined) {
|
||||
return ""
|
||||
}
|
||||
return "" + state.state
|
||||
}
|
||||
|
||||
public initState(): UIEventSource<undefined | number | string> {
|
||||
let defaultValue = ""
|
||||
if (this.options.length > 1) {
|
||||
defaultValue = "" + (this.defaultSelection ?? 0)
|
||||
|
@ -159,6 +151,8 @@ export default class FilterConfig {
|
|||
// Only a single option
|
||||
if (this.defaultSelection === 0) {
|
||||
defaultValue = "true"
|
||||
} else {
|
||||
defaultValue = "false"
|
||||
}
|
||||
}
|
||||
const qp = QueryParameters.GetQueryParameter(
|
||||
|
@ -168,12 +162,6 @@ export default class FilterConfig {
|
|||
)
|
||||
|
||||
if (this.options.length > 1) {
|
||||
// This is a multi-option filter; state should be a number which selects the correct entry
|
||||
const possibleStates: FilterState[] = this.options.map((opt, i) => ({
|
||||
currentFilter: opt.osmTags,
|
||||
state: i,
|
||||
}))
|
||||
|
||||
// We map the query parameter for this case
|
||||
return qp.sync(
|
||||
(str) => {
|
||||
|
@ -182,62 +170,29 @@ export default class FilterConfig {
|
|||
// Nope, not a correct number!
|
||||
return undefined
|
||||
}
|
||||
return possibleStates[parsed]
|
||||
return parsed
|
||||
},
|
||||
[],
|
||||
reset
|
||||
(n) => "" + n
|
||||
)
|
||||
}
|
||||
|
||||
const option = this.options[0]
|
||||
|
||||
if (option.fields.length > 0) {
|
||||
return qp.sync(
|
||||
(str) => {
|
||||
// There are variables in play!
|
||||
// str should encode a json-hash
|
||||
try {
|
||||
const props = JSON.parse(str)
|
||||
|
||||
const origTags = option.originalTagsSpec
|
||||
const rewrittenTags = Utils.WalkJson(origTags, (v) => {
|
||||
if (typeof v !== "string") {
|
||||
return v
|
||||
}
|
||||
for (const key in props) {
|
||||
v = (<string>v).replace("{" + key + "}", props[key])
|
||||
}
|
||||
return v
|
||||
})
|
||||
const parsed = TagUtils.Tag(rewrittenTags)
|
||||
return <FilterState>{
|
||||
currentFilter: parsed,
|
||||
state: str,
|
||||
}
|
||||
} catch (e) {
|
||||
return undefined
|
||||
}
|
||||
},
|
||||
[],
|
||||
reset
|
||||
)
|
||||
return qp
|
||||
}
|
||||
|
||||
// The last case is pretty boring: it is checked or it isn't
|
||||
const filterState: FilterState = {
|
||||
currentFilter: option.osmTags,
|
||||
state: "true",
|
||||
}
|
||||
return qp.sync(
|
||||
(str) => {
|
||||
// Only a single option exists here
|
||||
if (str === "true") {
|
||||
return filterState
|
||||
return 0
|
||||
}
|
||||
return undefined
|
||||
},
|
||||
[],
|
||||
reset
|
||||
(n) => (n === undefined ? "false" : "true")
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -205,25 +205,6 @@ export interface LayoutConfigJson {
|
|||
}
|
||||
)[]
|
||||
|
||||
/**
|
||||
* If defined, data will be clustered.
|
||||
* Defaults to {maxZoom: 16, minNeeded: 500}
|
||||
*/
|
||||
clustering?:
|
||||
| {
|
||||
/**
|
||||
* All zoom levels above 'maxzoom' are not clustered anymore.
|
||||
* Defaults to 18
|
||||
*/
|
||||
maxZoom?: number
|
||||
/**
|
||||
* The number of elements per tile needed to start clustering
|
||||
* If clustering is defined, defaults to 250
|
||||
*/
|
||||
minNeededElements?: number
|
||||
}
|
||||
| false
|
||||
|
||||
/**
|
||||
* The URL of a custom CSS stylesheet to modify the layout
|
||||
*/
|
||||
|
|
|
@ -40,10 +40,6 @@ export default class LayoutConfig implements LayoutInformation {
|
|||
public defaultBackgroundId?: string
|
||||
public layers: LayerConfig[]
|
||||
public tileLayerSources: TilesourceConfig[]
|
||||
public readonly clustering?: {
|
||||
maxZoom: number
|
||||
minNeededElements: number
|
||||
}
|
||||
public readonly hideFromOverview: boolean
|
||||
public lockLocation: boolean | [[number, number], [number, number]]
|
||||
public readonly enableUserBadge: boolean
|
||||
|
@ -188,22 +184,6 @@ export default class LayoutConfig implements LayoutInformation {
|
|||
context + ".extraLink"
|
||||
)
|
||||
|
||||
this.clustering = {
|
||||
maxZoom: 16,
|
||||
minNeededElements: 250,
|
||||
}
|
||||
if (json.clustering === false) {
|
||||
this.clustering = {
|
||||
maxZoom: 0,
|
||||
minNeededElements: 100000,
|
||||
}
|
||||
} else if (json.clustering) {
|
||||
this.clustering = {
|
||||
maxZoom: json.clustering.maxZoom ?? 18,
|
||||
minNeededElements: json.clustering.minNeededElements ?? 250,
|
||||
}
|
||||
}
|
||||
|
||||
this.hideFromOverview = json.hideFromOverview ?? false
|
||||
this.lockLocation = <[[number, number], [number, number]]>json.lockLocation ?? undefined
|
||||
this.enableUserBadge = json.enableUserBadge ?? true
|
||||
|
|
|
@ -11,8 +11,6 @@ import { FixedUiElement } from "../../UI/Base/FixedUiElement"
|
|||
import Img from "../../UI/Base/Img"
|
||||
import Combine from "../../UI/Base/Combine"
|
||||
import { VariableUiElement } from "../../UI/Base/VariableUIElement"
|
||||
import { OsmTags } from "../OsmFeature"
|
||||
import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson"
|
||||
|
||||
export default class PointRenderingConfig extends WithContextLoader {
|
||||
private static readonly allowed_location_codes = new Set<string>([
|
||||
|
@ -176,7 +174,7 @@ export default class PointRenderingConfig extends WithContextLoader {
|
|||
return PointRenderingConfig.FromHtmlMulti(htmlDefs, rotation, false, defaultPin)
|
||||
}
|
||||
|
||||
public GetSimpleIcon(tags: Store<OsmTags>): BaseUIElement {
|
||||
public GetSimpleIcon(tags: Store<Record<string, string>>): BaseUIElement {
|
||||
const self = this
|
||||
if (this.icon === undefined) {
|
||||
return undefined
|
||||
|
@ -187,7 +185,7 @@ export default class PointRenderingConfig extends WithContextLoader {
|
|||
}
|
||||
|
||||
public RenderIcon(
|
||||
tags: Store<OsmTags>,
|
||||
tags: Store<Record<string, string>>,
|
||||
clickable: boolean,
|
||||
options?: {
|
||||
noSize?: false | boolean
|
||||
|
@ -277,7 +275,7 @@ export default class PointRenderingConfig extends WithContextLoader {
|
|||
}
|
||||
}
|
||||
|
||||
private GetBadges(tags: Store<OsmTags>): BaseUIElement {
|
||||
private GetBadges(tags: Store<Record<string, string>>): BaseUIElement {
|
||||
if (this.iconBadges.length === 0) {
|
||||
return undefined
|
||||
}
|
||||
|
@ -309,7 +307,7 @@ export default class PointRenderingConfig extends WithContextLoader {
|
|||
).SetClass("absolute bottom-0 right-1/3 h-1/2 w-0")
|
||||
}
|
||||
|
||||
private GetLabel(tags: Store<OsmTags>): BaseUIElement {
|
||||
private GetLabel(tags: Store<Record<string, string>>): BaseUIElement {
|
||||
if (this.label === undefined) {
|
||||
return undefined
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue