Ported bicycle parking layer to .json-file

This commit is contained in:
Pieter Vander Vennet 2020-09-03 02:05:09 +02:00
parent ee9c9e201f
commit 5f4c2ec536
18 changed files with 415 additions and 336 deletions

View file

@ -8,14 +8,13 @@ import Translation from "../../UI/i18n/Translation";
import {LayerConfigJson} from "./LayerConfigJson";
import {LayerDefinition, Preset} from "../LayerDefinition";
import {TagDependantUIElementConstructor} from "../UIElementConstructor";
import FixedText from "../Questions/FixedText";
import Translations from "../../UI/i18n/Translations";
import Combine from "../../UI/Base/Combine";
import {ImageCarouselWithUploadConstructor} from "../../UI/Image/ImageCarouselWithUpload";
import {ImageCarouselConstructor} from "../../UI/Image/ImageCarousel";
import * as drinkingWater from "../../assets/layers/drinking_water/drinking_water.json";
import * as ghostbikes from "../../assets/layers/ghost_bike/ghost_bike.json"
import * as viewpoint from "../../assets/layers/viewpoint/viewpoint.json"
import * as bike_parking from "../../assets/layers/bike_parking/bike_parking.json"
import {Utils} from "../../Utils";
export class FromJSON {
@ -29,6 +28,7 @@ export class FromJSON {
FromJSON.Layer(drinkingWater),
FromJSON.Layer(ghostbikes),
FromJSON.Layer(viewpoint),
FromJSON.Layer(bike_parking),
];
for (const layer of sharedLayersList) {
@ -201,7 +201,7 @@ export class FromJSON {
if (tag.indexOf("!~") >= 0) {
const split = Utils.SplitFirst(tag, "!~");
if (split[1] === "*") {
split[1] = ".*"
split[1] = "..*"
}
return new RegexTag(
split[0],
@ -212,7 +212,7 @@ export class FromJSON {
if (tag.indexOf("!=") >= 0) {
const split = Utils.SplitFirst(tag, "!=");
if (split[1] === "*") {
split[1] = ".*"
split[1] = "..*"
}
return new RegexTag(
split[0],
@ -223,7 +223,7 @@ export class FromJSON {
if (tag.indexOf("~") >= 0) {
const split = Utils.SplitFirst(tag, "~");
if (split[1] === "*") {
split[1] = ".*"
split[1] = "..*"
}
return new RegexTag(
split[0],
@ -259,6 +259,8 @@ export class FromJSON {
const iconSize = FromJSON.TagRenderingWithDefault(json.iconSize, "iconSize", "40,40,center");
const color = FromJSON.TagRenderingWithDefault(json.color, "layercolor", "#0000ff");
const width = FromJSON.TagRenderingWithDefault(json.width, "layerwidth", "10");
const tagRenderings = json.tagRenderings?.map(FromJSON.TagRendering) ?? [];
const renderTags = {"id": "node/-1"}
const presets: Preset[] = json?.presets?.map(preset => {
return ({
@ -317,12 +319,13 @@ export class FromJSON {
title: FromJSON.TagRendering(json.title),
minzoom: json.minzoom,
presets: presets,
elementsToShow: json.tagRenderings?.map(FromJSON.TagRendering) ?? [],
elementsToShow: tagRenderings,
style: style,
wayHandling: json.wayHandling
}
);
console.log("Parsed layer is ", layer);
return layer;
}

View file

@ -1,52 +1,17 @@
import {LayerDefinition} from "../LayerDefinition";
import {Tag} from "../../Logic/Tags";
import FixedText from "../Questions/FixedText";
import ParkingType from "../Questions/bike/ParkingType";
import ParkingCapacity from "../Questions/bike/ParkingCapacity";
import {ImageCarouselWithUploadConstructor} from "../../UI/Image/ImageCarouselWithUpload";
import Translations from "../../UI/i18n/Translations";
import ParkingAccessCargo from "../Questions/bike/ParkingAccessCargo";
import ParkingCapacityCargo from "../Questions/bike/ParkingCapacityCargo";
export default class BikeParkings extends LayerDefinition {
private readonly accessCargoDesignated = new Tag("cargo_bike", "designated");
private readonly accessCargoDesignated = new Tag();
constructor() {
super("bikeparking");
this.name = Translations.t.cyclofix.parking.name;
this.icon = "./assets/bike/parking.svg";
this.overpassFilter = new Tag("amenity", "bicycle_parking");
this.presets = [{
title: Translations.t.cyclofix.parking.title,
tags: [
new Tag("amenity", "bicycle_parking"),
]
}];
this.maxAllowedOverlapPercentage = 10;
this.minzoom = 17;
this.style = function () {
return {
color: "#00bb00",
icon: {
iconUrl: "./assets/bike/parking.svg",
iconSize: [50, 50],
iconAnchor: [25, 50]
}
};
};
this.title = new FixedText(Translations.t.cyclofix.parking.title)
super(undefined);
this.elementsToShow = [
new ImageCarouselWithUploadConstructor(),
//new ParkingOperator(),
new ParkingType(),
new ParkingCapacity(),
new ParkingAccessCargo(),
new ParkingCapacityCargo().OnlyShowIf(this.accessCargoDesignated)
//new ParkingOperator(),
];
this.wayHandling = LayerDefinition.WAYHANDLING_CENTER_AND_WAY;
}
}

View file

@ -14,7 +14,7 @@ export default class Cyclofix extends Layout {
"cyclofix",
["en", "nl", "fr","gl"],
Translations.t.cyclofix.title,
[new BikeServices(), new BikeShops(), "drinking_water", new BikeParkings(), new BikeOtherShops(), new BikeCafes()],
[new BikeServices(), new BikeShops(), "drinking_water", "bike_parking", new BikeOtherShops(), new BikeCafes()],
16,
50.8465573,
4.3516970,

View file

@ -1,20 +0,0 @@
import { Tag } from "../../../Logic/Tags";
import Translations from "../../../UI/i18n/Translations";
import {TagRenderingOptions} from "../../TagRenderingOptions";
export default class ParkingAccessCargo extends TagRenderingOptions {
constructor() {
const key = "cargo_bike"
const to = Translations.t.cyclofix.parking.access_cargo
super({
priority: 15,
question: to.question.Render(),
mappings: [
{k: new Tag(key, "yes"), txt: to.yes},
{k: new Tag(key, "designated"), txt: to.designated},
{k: new Tag(key, "no"), txt: to.no}
]
});
}
}

View file

@ -1,18 +0,0 @@
import Translations from "../../../UI/i18n/Translations";
import {TagRenderingOptions} from "../../TagRenderingOptions";
export default class ParkingCapacity extends TagRenderingOptions {
constructor() {
const to = Translations.t.cyclofix.parking.capacity
super({
priority: 15,
question: to.question,
freeform: {
key: "capacity",
renderTemplate: to.render,
template: to.template
}
});
}
}

View file

@ -1,18 +0,0 @@
import Translations from "../../../UI/i18n/Translations";
import {TagRenderingOptions} from "../../TagRenderingOptions";
export default class ParkingCapacityCargo extends TagRenderingOptions {
constructor() {
const to = Translations.t.cyclofix.parking.capacity_cargo
super({
priority: 10,
question: to.question,
freeform: {
key: "capacity:cargo_bike",
renderTemplate: to.render,
template: to.template
}
});
}
}

View file

@ -1,60 +0,0 @@
import {Tag} from "../../../Logic/Tags";
import Translations from "../../../UI/i18n/Translations";
import Combine from "../../../UI/Base/Combine";
import {TagRenderingOptions} from "../../TagRenderingOptions";
class ParkingTypeHelper {
static GenerateMappings() {
const images = {
stands: "assets/bike/parking_staple.svg",
wall_loops: "assets/bike/parking_wall_loops.svg",
handlebar_holder: "assets/bike/parking_handlebar_holder.svg",
rack: "assets/bike/parking_rack.svg",
shed: "assets/bike/parking_shed.svg"
};
const toImg = (url) => `<br /><img width="150px" src=${url}>`
const mappings = [];
const to = Translations.t.cyclofix.parking.type
for (const imagesKey in images) {
const mapping =
{
k: new Tag("bicycle_parking", imagesKey),
txt: new Combine([
to[imagesKey],
to.eg,
toImg(images[imagesKey])
])
};
mappings.push(mapping);
}
return mappings;
}
}
export default class ParkingType extends TagRenderingOptions {
constructor() {
const to = Translations.t.cyclofix.parking.type
super({
priority: 5,
question: to.question,
freeform: {
key: "bicycle_parking",
extraTags: new Tag("fixme", "Freeform bicycle_parking= tag used: possibly a wrong value"),
template: to.template.txt,
renderTemplate: to.render.txt,
placeholder: Translations.t.cyclofix.freeFormPlaceholder,
},
mappings: ParkingTypeHelper.GenerateMappings()
});
}
}

View file

@ -205,7 +205,13 @@ TagRendering extends UIElement implements TagDependantUIElement {
InputElement<TagsFilter> {
const elements = [];
let freeformElement = undefined;
if (options.freeform !== undefined) {
freeformElement = this.InputForFreeForm(options.freeform);
}
if (options.mappings !== undefined) {
const previousTexts= [];
@ -221,10 +227,11 @@ TagRendering extends UIElement implements TagDependantUIElement {
elements.push(this.InputElementForMapping(mapping));
}
}
if (options.freeform !== undefined) {
elements.push(this.InputForFreeForm(options.freeform));
if(freeformElement !== undefined) {
elements.push(freeformElement);
}
if (elements.length == 0) {
@ -239,7 +246,7 @@ TagRendering extends UIElement implements TagDependantUIElement {
}
private InputElementForMapping(mapping: { k: TagsFilter, txt: string | Translation }) {
private InputElementForMapping(mapping: { k: TagsFilter, txt: (string | Translation) }) {
return new FixedInputElement(this.ApplyTemplate(mapping.txt),
mapping.k.substituteValues(this.currentTags.data)
);
@ -454,8 +461,6 @@ TagRendering extends UIElement implements TagDependantUIElement {
"</span>"]).Render();
}
console.log("No rendering for",this)
return "";
}
@ -466,7 +471,6 @@ TagRendering extends UIElement implements TagDependantUIElement {
private ApplyTemplate(template: string | Translation): UIElement {
if (template === undefined || template === null) {
console.warn("Applying template which is undefined by ",this); // TODO THis error msg can probably be removed
return undefined;
}
return new VariableUiElement(this.currentTags.map(tags => {