mapcomplete/Customizations/Layers/BikeStations.ts

122 lines
4.9 KiB
TypeScript
Raw Normal View History

import {LayerDefinition} from "../LayerDefinition";
import {And, Tag, TagsFilter, Or, Not} from "../../Logic/TagsFilter";
import BikeStationChain from "../Questions/bike/StationChain";
import BikeStationPumpTools from "../Questions/bike/StationPumpTools";
import BikeStationStand from "../Questions/bike/StationStand";
import PumpManual from "../Questions/bike/PumpManual";
import BikeStationOperator from "../Questions/bike/StationOperator";
import BikeStationBrand from "../Questions/bike/StationBrand";
2020-07-16 07:54:32 +00:00
import FixedText from "../Questions/FixedText";
import PumpManometer from "../Questions/bike/PumpManometer";
2020-07-16 07:54:32 +00:00
import {ImageCarouselWithUploadConstructor} from "../../UI/Image/ImageCarouselWithUpload";
2020-07-16 13:56:10 +00:00
import PumpOperational from "../Questions/bike/PumpOperational";
2020-07-16 13:32:32 +00:00
import PumpValves from "../Questions/bike/PumpValves";
2020-07-20 21:43:42 +00:00
import Translations from "../../UI/i18n/Translations";
2020-07-31 15:38:03 +00:00
import {TagRenderingOptions} from "../TagRenderingOptions";
2020-07-16 12:21:06 +00:00
export default class BikeStations extends LayerDefinition {
private readonly repairStation = new Tag("amenity", "bicycle_repair_station");
2020-07-16 14:08:51 +00:00
private readonly pump = new Tag("service:bicycle:pump", "yes");
private readonly nopump = new Tag("service:bicycle:pump", "no");
2020-07-16 14:08:51 +00:00
private readonly pumpOperationalAny = new Tag("service:bicycle:pump:operational_status", "yes");
2020-07-17 10:00:52 +00:00
private readonly pumpOperationalOk = new Or([new Tag("service:bicycle:pump:operational_status", "yes"), new Tag("service:bicycle:pump:operational_status", "operational"), new Tag("service:bicycle:pump:operational_status", "ok"), new Tag("service:bicycle:pump:operational_status", "")]);
2020-07-16 14:08:51 +00:00
private readonly tools = new Tag("service:bicycle:tools", "yes");
private readonly notools = new Tag("service:bicycle:tools", "no");
private readonly to = Translations.t.cyclofix.station
2020-07-16 12:21:06 +00:00
constructor() {
2020-07-31 02:58:58 +00:00
super("bikestation");
2020-07-21 21:31:41 +00:00
this.name = Translations.t.cyclofix.station.name;
2020-07-22 16:01:16 +00:00
this.icon = "./assets/bike/repair_station_pump.svg";
const tr = Translations.t.cyclofix.station
this.overpassFilter = this.repairStation;
this.presets = [
{
title: tr.titlePump,
description: tr.services.pump,
tags: [this.repairStation, this.pump, this.notools]
},
{
title: tr.titleRepair,
description: tr.services.tools,
tags: [this.repairStation, this.tools, this.nopump]
},
{
title: tr.titlePumpAndRepair,
description: tr.services.both,
2020-07-29 19:43:58 +00:00
tags: [this.repairStation, this.tools, this.pump]
},
]
this.maxAllowedOverlapPercentage = 10;
this.minzoom = 13;
this.style = this.generateStyleFunction();
this.title = new TagRenderingOptions({
mappings: [
{
k: new And([this.pump, this.tools]),
txt: this.to.titlePumpAndRepair
},
{
k: new And([this.pump]),
txt: this.to.titlePump
},
{k: null, txt: this.to.titleRepair},
]
})
2020-07-21 22:50:30 +00:00
this.wayHandling = LayerDefinition.WAYHANDLING_CENTER_AND_WAY
2020-07-16 07:54:32 +00:00
this.elementsToShow = [
2020-07-16 07:54:32 +00:00
new ImageCarouselWithUploadConstructor(),
new BikeStationPumpTools(),
2020-07-16 12:21:06 +00:00
new BikeStationChain().OnlyShowIf(this.tools),
new BikeStationStand().OnlyShowIf(this.tools),
2020-07-16 07:54:32 +00:00
2020-07-16 12:21:06 +00:00
new PumpManual().OnlyShowIf(this.pump),
new PumpManometer().OnlyShowIf(this.pump),
2020-07-16 13:32:32 +00:00
new PumpValves().OnlyShowIf(this.pump),
2020-07-16 13:56:10 +00:00
new PumpOperational().OnlyShowIf(this.pump),
2020-07-16 07:54:32 +00:00
2020-07-20 21:43:42 +00:00
// new BikeStationOperator(),
// new BikeStationBrand() DISABLED
];
}
private generateStyleFunction() {
const self = this;
return function (properties: any) {
2020-07-16 13:56:10 +00:00
const hasPump = self.pump.matchesProperties(properties)
2020-07-17 10:00:52 +00:00
const isOperational = self.pumpOperationalOk.matchesProperties(properties)
2020-07-16 13:56:10 +00:00
const hasTools = self.tools.matchesProperties(properties)
let iconName = "repair_station.svg";
if (hasTools && hasPump && isOperational) {
iconName = "repair_station_pump.svg"
} else if(hasTools) {
2020-07-20 15:30:02 +00:00
iconName = "repair_station.svg"
} else if(hasPump) {
if (isOperational) {
iconName = "pump.svg"
2020-07-20 15:30:02 +00:00
} else {
iconName = "broken_pump_2.svg"
2020-07-20 15:30:02 +00:00
}
2020-07-16 13:56:10 +00:00
}
2020-07-16 13:56:10 +00:00
const iconUrl = `./assets/bike/${iconName}`
return {
color: "#00bb00",
icon: {
iconUrl: iconUrl,
2020-07-20 14:16:22 +00:00
iconSize: [50, 50],
2020-07-24 16:19:37 +00:00
iconAnchor: [25, 50]
}
};
};
}
}