forked from MapComplete/MapComplete
chore: automated housekeeping...
This commit is contained in:
parent
8ef7af613f
commit
00151afdea
114 changed files with 2857 additions and 2135 deletions
|
|
@ -210,7 +210,11 @@ export default class FilteredLayer {
|
|||
* - the specified 'global filters'
|
||||
* - the 'isShown'-filter set by the layer
|
||||
*/
|
||||
public isShown(properties: Record<string, string>, globalFilters?: GlobalFilter[], zoomlevel?: number): boolean {
|
||||
public isShown(
|
||||
properties: Record<string, string>,
|
||||
globalFilters?: GlobalFilter[],
|
||||
zoomlevel?: number
|
||||
): boolean {
|
||||
if (properties._deleted === "yes") {
|
||||
return false
|
||||
}
|
||||
|
|
@ -219,7 +223,7 @@ export default class FilteredLayer {
|
|||
if (neededTags !== undefined) {
|
||||
const doesMatch = neededTags.matchesProperties(properties)
|
||||
if (globalFilter.forceShowOnMatch) {
|
||||
if(doesMatch){
|
||||
if (doesMatch) {
|
||||
return true
|
||||
}
|
||||
} else if (!doesMatch) {
|
||||
|
|
@ -241,7 +245,10 @@ export default class FilteredLayer {
|
|||
}
|
||||
}
|
||||
|
||||
if(zoomlevel !== undefined && (this.layerDef.minzoom > zoomlevel || this.layerDef.minzoomVisible < zoomlevel)){
|
||||
if (
|
||||
zoomlevel !== undefined &&
|
||||
(this.layerDef.minzoom > zoomlevel || this.layerDef.minzoomVisible < zoomlevel)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,10 +20,14 @@ export interface MapProperties {
|
|||
readonly allowRotating: UIEventSource<true | boolean>
|
||||
readonly rotation: UIEventSource<number>
|
||||
readonly pitch: UIEventSource<number>
|
||||
readonly lastClickLocation: Store<{ lon: number; lat: number ; /**
|
||||
readonly lastClickLocation: Store<{
|
||||
lon: number
|
||||
lat: number
|
||||
/**
|
||||
* The nearest feature from a MapComplete layer
|
||||
*/
|
||||
nearestFeature?: Feature}>
|
||||
nearestFeature?: Feature
|
||||
}>
|
||||
readonly allowZooming: UIEventSource<true | boolean>
|
||||
readonly useTerrain: Store<boolean>
|
||||
readonly showScale: UIEventSource<boolean>
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ export default class PointRenderingConfig extends WithContextLoader {
|
|||
"end",
|
||||
"projected_centerpoint",
|
||||
"polygon_centroid",
|
||||
"waypoints"
|
||||
"waypoints",
|
||||
])
|
||||
public readonly location: Set<
|
||||
| "point"
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ export default class TagRenderingConfig {
|
|||
| string
|
||||
| TagRenderingConfigJson
|
||||
| (QuestionableTagRenderingConfigJson & { questionHintIsMd?: boolean }),
|
||||
context?: string,
|
||||
context?: string
|
||||
) {
|
||||
let json = <string | QuestionableTagRenderingConfigJson>config
|
||||
if (json === undefined) {
|
||||
|
|
@ -145,22 +145,22 @@ export default class TagRenderingConfig {
|
|||
this.questionhint = Translations.T(json.questionHint, translationKey + ".questionHint")
|
||||
this.questionHintIsMd = json["questionHintIsMd"] ?? false
|
||||
this.description = Translations.T(json.description, translationKey + ".description")
|
||||
if(json.onSoftDelete && !Array.isArray(json.onSoftDelete)){
|
||||
throw context+".onSoftDelete Not an array: "+typeof json.onSoftDelete
|
||||
if (json.onSoftDelete && !Array.isArray(json.onSoftDelete)) {
|
||||
throw context + ".onSoftDelete Not an array: " + typeof json.onSoftDelete
|
||||
}
|
||||
this.onSoftDelete = json.onSoftDelete?.map(t => {
|
||||
this.onSoftDelete = json.onSoftDelete?.map((t) => {
|
||||
const tag = TagUtils.Tag(t, context)
|
||||
if (tag instanceof RegexTag) {
|
||||
throw context+".onSoftDelete Invalid onSoftDelete: cannot upload tag " + t
|
||||
throw context + ".onSoftDelete Invalid onSoftDelete: cannot upload tag " + t
|
||||
}
|
||||
if (tag instanceof ComparingTag) {
|
||||
throw context+".onSoftDelete Invalid onSoftDelete: cannot upload tag " + t
|
||||
throw context + ".onSoftDelete Invalid onSoftDelete: cannot upload tag " + t
|
||||
}
|
||||
return tag
|
||||
})
|
||||
this.editButtonAriaLabel = Translations.T(
|
||||
json.editButtonAriaLabel,
|
||||
translationKey + ".editButtonAriaLabel",
|
||||
translationKey + ".editButtonAriaLabel"
|
||||
)
|
||||
|
||||
this.condition = TagUtils.Tag(json.condition ?? { and: [] }, `${context}.condition`)
|
||||
|
|
@ -176,7 +176,7 @@ export default class TagRenderingConfig {
|
|||
}
|
||||
this.metacondition = TagUtils.Tag(
|
||||
json.metacondition ?? { and: [] },
|
||||
`${context}.metacondition`,
|
||||
`${context}.metacondition`
|
||||
)
|
||||
if (json.freeform) {
|
||||
if (
|
||||
|
|
@ -194,7 +194,7 @@ export default class TagRenderingConfig {
|
|||
}, perhaps you meant ${Utils.sortedByLevenshteinDistance(
|
||||
json.freeform.key,
|
||||
<any>Validators.availableTypes,
|
||||
(s) => <any>s,
|
||||
(s) => <any>s
|
||||
)}`
|
||||
}
|
||||
const type: ValidatorType = <any>json.freeform.type ?? "string"
|
||||
|
|
@ -216,7 +216,7 @@ export default class TagRenderingConfig {
|
|||
placeholder,
|
||||
addExtraTags:
|
||||
json.freeform.addExtraTags?.map((tg, i) =>
|
||||
TagUtils.ParseUploadableTag(tg, `${context}.extratag[${i}]`),
|
||||
TagUtils.ParseUploadableTag(tg, `${context}.extratag[${i}]`)
|
||||
) ?? [],
|
||||
inline: json.freeform.inline ?? false,
|
||||
default: json.freeform.default,
|
||||
|
|
@ -282,8 +282,8 @@ export default class TagRenderingConfig {
|
|||
context,
|
||||
this.multiAnswer,
|
||||
this.question !== undefined,
|
||||
commonIconSize,
|
||||
),
|
||||
commonIconSize
|
||||
)
|
||||
)
|
||||
} else {
|
||||
this.mappings = []
|
||||
|
|
@ -309,7 +309,7 @@ export default class TagRenderingConfig {
|
|||
for (const expectedKey of keys) {
|
||||
if (usedKeys.indexOf(expectedKey) < 0) {
|
||||
const msg = `${context}.mappings[${i}]: This mapping only defines values for ${usedKeys.join(
|
||||
", ",
|
||||
", "
|
||||
)}, but it should also give a value for ${expectedKey}`
|
||||
this.configuration_warnings.push(msg)
|
||||
}
|
||||
|
|
@ -356,7 +356,7 @@ export default class TagRenderingConfig {
|
|||
context: string,
|
||||
multiAnswer?: boolean,
|
||||
isQuestionable?: boolean,
|
||||
commonSize: string = "small",
|
||||
commonSize: string = "small"
|
||||
): Mapping {
|
||||
const ctx = `${translationKey}.mappings.${i}`
|
||||
if (mapping.if === undefined) {
|
||||
|
|
@ -365,7 +365,7 @@ export default class TagRenderingConfig {
|
|||
if (mapping.then === undefined) {
|
||||
if (mapping["render"] !== undefined) {
|
||||
throw `${ctx}: Invalid mapping: no 'then'-clause found. You might have typed 'render' instead of 'then', change it in ${JSON.stringify(
|
||||
mapping,
|
||||
mapping
|
||||
)}`
|
||||
}
|
||||
throw `${ctx}: Invalid mapping: no 'then'-clause found in ${JSON.stringify(mapping)}`
|
||||
|
|
@ -376,7 +376,7 @@ export default class TagRenderingConfig {
|
|||
|
||||
if (mapping["render"] !== undefined) {
|
||||
throw `${ctx}: Invalid mapping: a 'render'-key is present, this is probably a bug: ${JSON.stringify(
|
||||
mapping,
|
||||
mapping
|
||||
)}`
|
||||
}
|
||||
if (typeof mapping.if !== "string" && mapping.if["length"] !== undefined) {
|
||||
|
|
@ -387,8 +387,14 @@ export default class TagRenderingConfig {
|
|||
throw `${ctx}.addExtraTags: expected a list, but got a ${typeof mapping.addExtraTags}`
|
||||
}
|
||||
if (mapping.addExtraTags !== undefined && multiAnswer) {
|
||||
const usedKeys = mapping.addExtraTags?.flatMap((et) => TagUtils.Tag(et, context).usedKeys())
|
||||
if (usedKeys.some((key) => TagUtils.Tag(mapping.if, context).usedKeys().indexOf(key) > 0)) {
|
||||
const usedKeys = mapping.addExtraTags?.flatMap((et) =>
|
||||
TagUtils.Tag(et, context).usedKeys()
|
||||
)
|
||||
if (
|
||||
usedKeys.some(
|
||||
(key) => TagUtils.Tag(mapping.if, context).usedKeys().indexOf(key) > 0
|
||||
)
|
||||
) {
|
||||
throw `${ctx}: Invalid mapping: got a multi-Answer with addExtraTags which also modifies one of the keys; this is not allowed`
|
||||
}
|
||||
}
|
||||
|
|
@ -399,11 +405,11 @@ export default class TagRenderingConfig {
|
|||
} else if (mapping.hideInAnswer !== undefined) {
|
||||
hideInAnswer = TagUtils.Tag(
|
||||
mapping.hideInAnswer,
|
||||
`${context}.mapping[${i}].hideInAnswer`,
|
||||
`${context}.mapping[${i}].hideInAnswer`
|
||||
)
|
||||
}
|
||||
const addExtraTags = (mapping.addExtraTags ?? []).map((str, j) =>
|
||||
TagUtils.SimpleTag(str, `${ctx}.addExtraTags[${j}]`),
|
||||
TagUtils.SimpleTag(str, `${ctx}.addExtraTags[${j}]`)
|
||||
)
|
||||
if (hideInAnswer === true && addExtraTags.length > 0) {
|
||||
throw `${ctx}: Invalid mapping: 'hideInAnswer' is set to 'true', but 'addExtraTags' is enabled as well. This means that extra tags will be applied if this mapping is chosen as answer, but it cannot be chosen as answer. This either indicates a thought error or obsolete code that must be removed.`
|
||||
|
|
@ -499,7 +505,7 @@ export default class TagRenderingConfig {
|
|||
* @constructor
|
||||
*/
|
||||
public GetRenderValues(
|
||||
tags: Record<string, string>,
|
||||
tags: Record<string, string>
|
||||
): { then: Translation; icon?: string; iconClass?: string }[] {
|
||||
if (!this.multiAnswer) {
|
||||
return [this.GetRenderValueWithImage(tags)]
|
||||
|
|
@ -522,7 +528,7 @@ export default class TagRenderingConfig {
|
|||
return mapping
|
||||
}
|
||||
return undefined
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
if (freeformKeyDefined && tags[this.freeform.key] !== undefined) {
|
||||
|
|
@ -530,7 +536,7 @@ export default class TagRenderingConfig {
|
|||
applicableMappings
|
||||
?.flatMap((m) => m.if?.usedTags() ?? [])
|
||||
?.filter((kv) => kv.key === this.freeform.key)
|
||||
?.map((kv) => kv.value),
|
||||
?.map((kv) => kv.value)
|
||||
)
|
||||
|
||||
const freeformValues = tags[this.freeform.key].split(";")
|
||||
|
|
@ -539,7 +545,7 @@ export default class TagRenderingConfig {
|
|||
applicableMappings.push({
|
||||
then: new TypedTranslation<object>(
|
||||
this.render.replace("{" + this.freeform.key + "}", leftover).translations,
|
||||
this.render.context,
|
||||
this.render.context
|
||||
),
|
||||
})
|
||||
}
|
||||
|
|
@ -557,7 +563,7 @@ export default class TagRenderingConfig {
|
|||
* @constructor
|
||||
*/
|
||||
public GetRenderValueWithImage(
|
||||
tags: Record<string, string>,
|
||||
tags: Record<string, string>
|
||||
): { then: TypedTranslation<any>; icon?: string; iconClass?: string } | undefined {
|
||||
if (this.condition !== undefined) {
|
||||
if (!this.condition.matchesProperties(tags)) {
|
||||
|
|
@ -626,7 +632,7 @@ export default class TagRenderingConfig {
|
|||
const answerMappings = this.mappings?.filter((m) => m.hideInAnswer !== true)
|
||||
if (key === undefined) {
|
||||
const values: { k: string; v: string }[][] = Utils.NoNull(
|
||||
answerMappings?.map((m) => m.if.asChange({})) ?? [],
|
||||
answerMappings?.map((m) => m.if.asChange({})) ?? []
|
||||
)
|
||||
if (values.length === 0) {
|
||||
return
|
||||
|
|
@ -644,15 +650,15 @@ export default class TagRenderingConfig {
|
|||
return {
|
||||
key: commonKey,
|
||||
values: Utils.NoNull(
|
||||
values.map((arr) => arr.filter((item) => item.k === commonKey)[0]?.v),
|
||||
values.map((arr) => arr.filter((item) => item.k === commonKey)[0]?.v)
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
let values = Utils.NoNull(
|
||||
answerMappings?.map(
|
||||
(m) => m.if.asChange({}).filter((item) => item.k === key)[0]?.v,
|
||||
) ?? [],
|
||||
(m) => m.if.asChange({}).filter((item) => item.k === key)[0]?.v
|
||||
) ?? []
|
||||
)
|
||||
if (values.length === undefined) {
|
||||
values = undefined
|
||||
|
|
@ -716,7 +722,7 @@ export default class TagRenderingConfig {
|
|||
freeformValue: string | undefined,
|
||||
singleSelectedMapping: number,
|
||||
multiSelectedMapping: boolean[] | undefined,
|
||||
currentProperties: Record<string, string>,
|
||||
currentProperties: Record<string, string>
|
||||
): UploadableTag {
|
||||
if (typeof freeformValue === "string") {
|
||||
freeformValue = freeformValue?.trim()
|
||||
|
|
@ -791,7 +797,7 @@ export default class TagRenderingConfig {
|
|||
new And([
|
||||
new Tag(this.freeform.key, freeformValue),
|
||||
...(this.freeform.addExtraTags ?? []),
|
||||
]),
|
||||
])
|
||||
)
|
||||
}
|
||||
const and = TagUtils.FlattenMultiAnswer([...selectedMappings, ...unselectedMappings])
|
||||
|
|
@ -861,11 +867,11 @@ export default class TagRenderingConfig {
|
|||
}
|
||||
const msgs: string[] = [
|
||||
icon +
|
||||
" " +
|
||||
"*" +
|
||||
m.then.textFor(lang) +
|
||||
"* is shown if with " +
|
||||
m.if.asHumanString(true, false, {}),
|
||||
" " +
|
||||
"*" +
|
||||
m.then.textFor(lang) +
|
||||
"* is shown if with " +
|
||||
m.if.asHumanString(true, false, {}),
|
||||
]
|
||||
|
||||
if (m.hideInAnswer === true) {
|
||||
|
|
@ -874,11 +880,11 @@ export default class TagRenderingConfig {
|
|||
if (m.ifnot !== undefined) {
|
||||
msgs.push(
|
||||
"Unselecting this answer will add " +
|
||||
m.ifnot.asHumanString(true, false, {}),
|
||||
m.ifnot.asHumanString(true, false, {})
|
||||
)
|
||||
}
|
||||
return msgs.join(". ")
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -887,7 +893,7 @@ export default class TagRenderingConfig {
|
|||
const conditionAsLink = (<TagsFilter>this.condition.optimize()).asHumanString(
|
||||
true,
|
||||
false,
|
||||
{},
|
||||
{}
|
||||
)
|
||||
condition =
|
||||
"This tagrendering is only visible in the popup if the following condition is met: " +
|
||||
|
|
@ -921,7 +927,7 @@ export default class TagRenderingConfig {
|
|||
this.metacondition,
|
||||
this.condition,
|
||||
this.freeform?.key ? new RegexTag(this.freeform?.key, /.*/) : undefined,
|
||||
this.invalidValues,
|
||||
this.invalidValues
|
||||
)
|
||||
for (const m of this.mappings ?? []) {
|
||||
tags.push(m.if)
|
||||
|
|
@ -943,7 +949,7 @@ export default class TagRenderingConfig {
|
|||
*/
|
||||
public removeToSetUnknown(
|
||||
partOfLayer: LayerConfig,
|
||||
currentTags: Record<string, string>,
|
||||
currentTags: Record<string, string>
|
||||
): string[] | undefined {
|
||||
if (!partOfLayer?.source || !currentTags) {
|
||||
return
|
||||
|
|
@ -991,7 +997,7 @@ export class TagRenderingConfigUtils {
|
|||
public static withNameSuggestionIndex(
|
||||
config: TagRenderingConfig,
|
||||
tags: UIEventSource<Record<string, string>>,
|
||||
feature?: Feature,
|
||||
feature?: Feature
|
||||
): Store<TagRenderingConfig> {
|
||||
const isNSI = NameSuggestionIndex.supportedTypes().indexOf(config.freeform?.key) >= 0
|
||||
if (!isNSI) {
|
||||
|
|
@ -1009,8 +1015,8 @@ export class TagRenderingConfigUtils {
|
|||
tags,
|
||||
country.split(";"),
|
||||
center,
|
||||
{ sortByFrequency: true },
|
||||
),
|
||||
{ sortByFrequency: true }
|
||||
)
|
||||
)
|
||||
})
|
||||
return extraMappings.map((extraMappings) => {
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ export default class ThemeViewState implements SpecialVisualizationState {
|
|||
this.map = new UIEventSource<MlMap>(undefined)
|
||||
const geolocationState = new GeoLocationState()
|
||||
const initial = new InitialMapPositioning(layout, geolocationState)
|
||||
this.mapProperties = new MapLibreAdaptor(this.map, initial, {correctClick: 20})
|
||||
this.mapProperties = new MapLibreAdaptor(this.map, initial, { correctClick: 20 })
|
||||
|
||||
this.featureSwitchIsTesting = this.featureSwitches.featureSwitchIsTesting
|
||||
this.featureSwitchUserbadge = this.featureSwitches.featureSwitchEnableLogin
|
||||
|
|
@ -557,9 +557,12 @@ export default class ThemeViewState implements SpecialVisualizationState {
|
|||
})
|
||||
}
|
||||
|
||||
private setSelectedElement(feature: Feature){
|
||||
private setSelectedElement(feature: Feature) {
|
||||
const current = this.selectedElement.data
|
||||
if(current?.properties?.id !== undefined && current.properties.id === feature.properties.id ){
|
||||
if (
|
||||
current?.properties?.id !== undefined &&
|
||||
current.properties.id === feature.properties.id
|
||||
) {
|
||||
console.log("Not setting selected, same id", current, feature)
|
||||
return // already set
|
||||
}
|
||||
|
|
@ -1002,13 +1005,12 @@ export default class ThemeViewState implements SpecialVisualizationState {
|
|||
this.userRelatedState.recentlyVisitedSearch.add(r)
|
||||
})
|
||||
|
||||
this.mapProperties.lastClickLocation.addCallbackD(lastClick => {
|
||||
if(lastClick.mode !== "left" || !lastClick.nearestFeature){
|
||||
this.mapProperties.lastClickLocation.addCallbackD((lastClick) => {
|
||||
if (lastClick.mode !== "left" || !lastClick.nearestFeature) {
|
||||
return
|
||||
}
|
||||
const f = lastClick.nearestFeature
|
||||
this.setSelectedElement(f)
|
||||
|
||||
})
|
||||
|
||||
this.userRelatedState.showScale.addCallbackAndRun((showScale) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue