diff --git a/Customizations/Layers/BikeServices.ts b/Customizations/Layers/BikeServices.ts index 590e249..e79ff33 100644 --- a/Customizations/Layers/BikeServices.ts +++ b/Customizations/Layers/BikeServices.ts @@ -1,5 +1,5 @@ import {LayerDefinition} from "../LayerDefinition"; -import {And, Tag} from "../../Logic/TagsFilter"; +import {And, Tag, TagsFilter} from "../../Logic/TagsFilter"; import * as L from "leaflet"; import BikeStationChain from "../Questions/BikeStationChain"; import BikeStationPumpTools from "../Questions/BikeStationPumpTools"; @@ -10,8 +10,14 @@ import BikeStationBrand from "../Questions/BikeStationBrand"; import FixedText from "../Questions/FixedText"; import {BikePumpManometer} from "../Questions/BikePumpManometer"; import {ImageCarouselWithUploadConstructor} from "../../UI/Image/ImageCarouselWithUpload"; +import {BikePumpOperationalStatus} from "../Questions/BikePumpOperationalStatus"; export default class BikeServices extends LayerDefinition { + + + private readonly pump: TagsFilter = new Tag("service:bicycle:pump", "yes"); + private readonly tools: TagsFilter = new Tag("service:bicycle:tools", "yes"); + constructor() { super(); this.name = "bike station or pump"; @@ -31,7 +37,6 @@ export default class BikeServices extends LayerDefinition { this.style = this.generateStyleFunction(); this.title = new FixedText("Bike station"); - const pump = new Tag("service:bicycle:pump", "yes"); this.elementsToShow = [ @@ -39,11 +44,12 @@ export default class BikeServices extends LayerDefinition { new BikeStationPumpTools(), - new BikeStationChain().OnlyShowIf(new Tag("service:bicycle:tools", "yes")), - new BikeStationStand().OnlyShowIf(new Tag("service:bicycle:tools", "yes")), + new BikeStationChain().OnlyShowIf(this.tools), + new BikeStationStand().OnlyShowIf(this.tools), - new PumpManual().OnlyShowIf(pump), - new BikePumpManometer().OnlyShowIf(pump), + new PumpManual().OnlyShowIf(this.pump), + new BikePumpManometer().OnlyShowIf(this.pump), + new BikePumpOperationalStatus().OnlyShowIf(this.pump), new BikeStationOperator(), new BikeStationBrand() @@ -54,7 +60,8 @@ export default class BikeServices extends LayerDefinition { private generateStyleFunction() { const self = this; return function (properties: any) { - const onlyPump = properties["service:bicycle:tools"] == "no" && properties["service:bicycle:pump"] == "yes"; + const onlyPump = self.pump.matchesProperties(properties) && + !self.tools.matchesProperties(properties) const iconUrl = onlyPump ? "./assets/pump.svg" : "./assets/wrench.svg" return { color: "#00bb00", diff --git a/Customizations/Questions/BikePumpOperationalStatus.ts b/Customizations/Questions/BikePumpOperationalStatus.ts new file mode 100644 index 0000000..37933af --- /dev/null +++ b/Customizations/Questions/BikePumpOperationalStatus.ts @@ -0,0 +1,15 @@ +import {TagDependantUIElement} from "../UIElementConstructor"; +import {TagRenderingOptions} from "../TagRendering"; +import {Tag} from "../../Logic/TagsFilter"; + +export class BikePumpOperationalStatus extends TagRenderingOptions{ + constructor() { + super({ + question: "Is the bicycle pump still operational?", + mappings: [ + {k: new Tag("service:bicycle:pump:operational_status","broken"), txt: "This pump is broken"}, + {k: new Tag("service:bicycle:pump:operational_status",""), txt: "This pump is operational"} + ] + }); + } +} \ No newline at end of file diff --git a/Logic/TagsFilter.ts b/Logic/TagsFilter.ts index bf039a5..dec52ac 100644 --- a/Logic/TagsFilter.ts +++ b/Logic/TagsFilter.ts @@ -1,8 +1,21 @@ -export class Regex implements TagsFilter { + +export abstract class TagsFilter { + abstract matches(tags: { k: string, v: string }[]): boolean + abstract asOverpass(): string[] + abstract substituteValues(tags: any) : TagsFilter; + + matchesProperties(properties: any) : boolean{ + return this.matches(TagUtils.proprtiesToKV(properties)); + } +} + + +export class Regex extends TagsFilter { private _k: string; private _r: string; constructor(k: string, r: string) { + super(); this._k = k; this._r = r; } @@ -37,11 +50,12 @@ export class Regex implements TagsFilter { } -export class Tag implements TagsFilter { +export class Tag extends TagsFilter { public key: string; public value: string; constructor(key: string, value: string) { + super() this.key = key; this.value = value; } @@ -85,11 +99,12 @@ export class Tag implements TagsFilter { } -export class Or implements TagsFilter { +export class Or extends TagsFilter { public or: TagsFilter[] constructor(or: TagsFilter[]) { + super(); this.or = or; } @@ -127,11 +142,12 @@ export class Or implements TagsFilter { } -export class And implements TagsFilter { +export class And extends TagsFilter { public and: TagsFilter[] constructor(and: TagsFilter[]) { + super(); this.and = and; } @@ -185,13 +201,6 @@ export class And implements TagsFilter { } } -export interface TagsFilter { - matches(tags: { k: string, v: string }[]): boolean - - asOverpass(): string[] - - substituteValues(tags: any) : TagsFilter; -} export class TagUtils {