forked from MapComplete/MapComplete
Add erase all option, formatting
This commit is contained in:
parent
8b2aff0244
commit
62244c02c4
5 changed files with 50 additions and 36 deletions
|
@ -8,10 +8,13 @@ export class Unit {
|
||||||
public readonly appliesToKeys: Set<string>;
|
public readonly appliesToKeys: Set<string>;
|
||||||
public readonly denominations: Denomination[];
|
public readonly denominations: Denomination[];
|
||||||
public readonly defaultDenom: Denomination;
|
public readonly defaultDenom: Denomination;
|
||||||
constructor(appliesToKeys: string[], applicableUnits: Denomination[]) {
|
public readonly eraseInvalid : boolean;
|
||||||
|
|
||||||
|
constructor(appliesToKeys: string[], applicableUnits: Denomination[], eraseInvalid: boolean) {
|
||||||
this.appliesToKeys = new Set(appliesToKeys);
|
this.appliesToKeys = new Set(appliesToKeys);
|
||||||
this.denominations = applicableUnits;
|
this.denominations = applicableUnits;
|
||||||
this.defaultDenom = applicableUnits.filter(denom => denom.default)[0]
|
this.defaultDenom = applicableUnits.filter(denom => denom.default)[0]
|
||||||
|
this.eraseInvalid = eraseInvalid
|
||||||
}
|
}
|
||||||
|
|
||||||
isApplicableToKey(key: string | undefined): boolean {
|
isApplicableToKey(key: string | undefined): boolean {
|
||||||
|
@ -49,11 +52,11 @@ this.defaultDenom = applicableUnits.filter(denom => denom.default)[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Denomination {
|
export class Denomination {
|
||||||
private readonly _human: Translation;
|
|
||||||
private readonly alternativeDenominations: string [];
|
|
||||||
public readonly canonical: string;
|
public readonly canonical: string;
|
||||||
readonly default: boolean;
|
readonly default: boolean;
|
||||||
readonly prefix: boolean;
|
readonly prefix: boolean;
|
||||||
|
private readonly _human: Translation;
|
||||||
|
private readonly alternativeDenominations: string [];
|
||||||
|
|
||||||
constructor(json: UnitConfigJson, context: string) {
|
constructor(json: UnitConfigJson, context: string) {
|
||||||
context = `${context}.unit(${json.canonicalDenomination})`
|
context = `${context}.unit(${json.canonicalDenomination})`
|
||||||
|
|
|
@ -220,7 +220,7 @@ export default class LayoutConfig {
|
||||||
throw `Multiple units are set as default: they have canonical values of ${defaultSet.map(u => u.canonicalDenomination).join(", ")}`
|
throw `Multiple units are set as default: they have canonical values of ${defaultSet.map(u => u.canonicalDenomination).join(", ")}`
|
||||||
}
|
}
|
||||||
const applicable = unit.applicableUnits.map((u, i) => new Denomination(u, `${context}.units[${i}]`))
|
const applicable = unit.applicableUnits.map((u, i) => new Denomination(u, `${context}.units[${i}]`))
|
||||||
result.push(new Unit( appliesTo, applicable));
|
result.push(new Unit(appliesTo, applicable, unit.eraseInvalidValues ?? false));
|
||||||
}
|
}
|
||||||
|
|
||||||
const seenKeys = new Set<string>()
|
const seenKeys = new Set<string>()
|
||||||
|
|
|
@ -249,7 +249,15 @@ export interface LayoutConfigJson {
|
||||||
*/
|
*/
|
||||||
appliesToKey: string[],
|
appliesToKey: string[],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The possible denominations
|
||||||
|
*/
|
||||||
applicableUnits: UnitConfigJson[]
|
applicableUnits: UnitConfigJson[]
|
||||||
|
/**
|
||||||
|
* If set, invalid values will be erased in the MC application (but not in OSM of course!)
|
||||||
|
* Be careful with setting this
|
||||||
|
*/
|
||||||
|
eraseInvalidValues?: boolean;
|
||||||
}[]
|
}[]
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -78,15 +78,13 @@ export default class FeaturePipeline implements FeatureSource {
|
||||||
|
|
||||||
merged.features.syncWith(allLoadedFeatures)
|
merged.features.syncWith(allLoadedFeatures)
|
||||||
|
|
||||||
const source =
|
this.features = new WayHandlingApplyingFeatureSource(flayers,
|
||||||
new WayHandlingApplyingFeatureSource(flayers,
|
|
||||||
new FilteringFeatureSource(
|
new FilteringFeatureSource(
|
||||||
flayers,
|
flayers,
|
||||||
locationControl,
|
locationControl,
|
||||||
selectedElement,
|
selectedElement,
|
||||||
merged
|
merged
|
||||||
));
|
)).features;
|
||||||
this.features = source.features;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -94,9 +94,14 @@ export default class SimpleMetaTagger {
|
||||||
}
|
}
|
||||||
const value = feature.properties[key]
|
const value = feature.properties[key]
|
||||||
const [, denomination] = unit.findDenomination(value)
|
const [, denomination] = unit.findDenomination(value)
|
||||||
const canonical = denomination.canonicalValue(value)
|
let canonical = denomination.canonicalValue(value) ?? undefined;
|
||||||
console.log("Rewritten ", key, " from", value, "into", canonical)
|
console.log("Rewritten ", key, " from", value, "into", canonical)
|
||||||
|
if(canonical === undefined && !unit.eraseInvalid) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
feature.properties[key] = canonical;
|
feature.properties[key] = canonical;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue