2020-07-17 17:21:07 +02:00
|
|
|
import {LayerDefinition} from "../LayerDefinition";
|
2020-09-05 15:27:35 +02:00
|
|
|
import {And, Or, RegexTag, Tag} from "../../Logic/Tags";
|
2020-07-31 17:38:03 +02:00
|
|
|
import {TagRenderingOptions} from "../TagRenderingOptions";
|
2020-08-31 02:59:47 +02:00
|
|
|
import {FromJSON} from "../JSON/FromJSON";
|
2020-07-17 17:21:07 +02:00
|
|
|
|
|
|
|
export class Widths extends LayerDefinition {
|
|
|
|
|
2020-08-30 01:13:18 +02:00
|
|
|
private readonly cyclistWidth: number;
|
|
|
|
private readonly carWidth: number;
|
|
|
|
private readonly pedestrianWidth: number;
|
2020-07-17 17:21:07 +02:00
|
|
|
|
|
|
|
private readonly _bothSideParking = new Tag("parking:lane:both", "parallel");
|
|
|
|
private readonly _noSideParking = new Tag("parking:lane:both", "no_parking");
|
2020-07-19 00:13:45 +02:00
|
|
|
private readonly _otherParkingMode =
|
|
|
|
new Or([
|
|
|
|
new Tag("parking:lane:both", "perpendicular"),
|
|
|
|
new Tag("parking:lane:left", "perpendicular"),
|
|
|
|
new Tag("parking:lane:right", "perpendicular"),
|
|
|
|
new Tag("parking:lane:both", "diagonal"),
|
|
|
|
new Tag("parking:lane:left", "diagonal"),
|
|
|
|
new Tag("parking:lane:right", "diagonal"),
|
|
|
|
])
|
|
|
|
|
2020-07-17 17:21:07 +02:00
|
|
|
|
|
|
|
private readonly _leftSideParking =
|
|
|
|
new And([new Tag("parking:lane:left", "parallel"), new Tag("parking:lane:right", "no_parking")]);
|
|
|
|
private readonly _rightSideParking =
|
|
|
|
new And([new Tag("parking:lane:right", "parallel"), new Tag("parking:lane:left", "no_parking")]);
|
|
|
|
|
2020-07-17 18:57:07 +02:00
|
|
|
|
|
|
|
private _sidewalkBoth = new Tag("sidewalk", "both");
|
|
|
|
private _sidewalkLeft = new Tag("sidewalk", "left");
|
|
|
|
private _sidewalkRight = new Tag("sidewalk", "right");
|
|
|
|
private _sidewalkNone = new Tag("sidewalk", "none");
|
|
|
|
|
|
|
|
|
2020-07-17 17:21:07 +02:00
|
|
|
private readonly _oneSideParking = new Or([this._leftSideParking, this._rightSideParking]);
|
|
|
|
|
2020-08-31 02:59:47 +02:00
|
|
|
private readonly _notCarfree =
|
|
|
|
FromJSON.Tag({"and":[
|
|
|
|
"highway!~pedestrian|living_street",
|
|
|
|
"access!~destination",
|
|
|
|
"motor_vehicle!~destination|no"
|
|
|
|
]});
|
|
|
|
|
2020-07-17 17:21:07 +02:00
|
|
|
private calcProps(properties) {
|
|
|
|
let parkingStateKnown = true;
|
|
|
|
let parallelParkingCount = 0;
|
|
|
|
|
|
|
|
if (this._oneSideParking.matchesProperties(properties)) {
|
|
|
|
parallelParkingCount = 1;
|
|
|
|
} else if (this._bothSideParking.matchesProperties(properties)) {
|
|
|
|
parallelParkingCount = 2;
|
|
|
|
} else if (this._noSideParking.matchesProperties(properties)) {
|
|
|
|
parallelParkingCount = 0;
|
2020-07-19 00:13:45 +02:00
|
|
|
} else if (this._otherParkingMode.matchesProperties(properties)) {
|
|
|
|
parallelParkingCount = 0;
|
2020-07-17 17:21:07 +02:00
|
|
|
} else {
|
|
|
|
parkingStateKnown = false;
|
|
|
|
console.log("No parking data for ", properties.name, properties.id, properties)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-30 01:13:18 +02:00
|
|
|
let pedestrianFlowNeeded;
|
2020-07-17 18:57:07 +02:00
|
|
|
if (this._sidewalkBoth.matchesProperties(properties)) {
|
|
|
|
pedestrianFlowNeeded = 0;
|
|
|
|
} else if (this._sidewalkNone.matchesProperties(properties)) {
|
|
|
|
pedestrianFlowNeeded = 2;
|
|
|
|
} else if (this._sidewalkLeft.matchesProperties(properties) || this._sidewalkRight.matches(properties)) {
|
|
|
|
pedestrianFlowNeeded = 1;
|
|
|
|
} else {
|
|
|
|
pedestrianFlowNeeded = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-17 17:21:07 +02:00
|
|
|
let onewayCar = properties.oneway === "yes";
|
|
|
|
let onewayBike = properties["oneway:bicycle"] === "yes" ||
|
|
|
|
(onewayCar && properties["oneway:bicycle"] === undefined)
|
|
|
|
|
2020-07-18 00:49:22 +02:00
|
|
|
let cyclingAllowed =
|
|
|
|
!(properties.bicycle === "use_sidepath"
|
|
|
|
|| properties.bicycle === "no");
|
2020-07-17 17:21:07 +02:00
|
|
|
|
|
|
|
let carWidth = (onewayCar ? 1 : 2) * this.carWidth;
|
2020-07-18 00:49:22 +02:00
|
|
|
let cyclistWidth = 0;
|
|
|
|
if (cyclingAllowed) {
|
|
|
|
cyclistWidth = (onewayBike ? 1 : 2) * this.cyclistWidth;
|
|
|
|
}
|
2020-07-17 17:21:07 +02:00
|
|
|
|
|
|
|
const width = parseFloat(properties["width:carriageway"]);
|
|
|
|
|
|
|
|
|
2020-07-27 09:38:21 +02:00
|
|
|
const targetWidthIgnoringPedestrians =
|
2020-07-17 17:21:07 +02:00
|
|
|
carWidth +
|
|
|
|
cyclistWidth +
|
|
|
|
parallelParkingCount * this.carWidth;
|
|
|
|
|
2020-07-27 09:38:21 +02:00
|
|
|
const targetWidth = targetWidthIgnoringPedestrians + Math.max(0, pedestrianFlowNeeded) * this.pedestrianWidth;
|
|
|
|
|
2020-07-17 17:21:07 +02:00
|
|
|
return {
|
|
|
|
parkingLanes: parallelParkingCount,
|
|
|
|
parkingStateKnown: parkingStateKnown,
|
|
|
|
width: width,
|
|
|
|
targetWidth: targetWidth,
|
2020-07-27 09:38:21 +02:00
|
|
|
targetWidthIgnoringPedestrians: targetWidthIgnoringPedestrians,
|
2020-07-17 18:57:07 +02:00
|
|
|
onewayBike: onewayBike,
|
|
|
|
pedestrianFlowNeeded: pedestrianFlowNeeded,
|
2020-07-18 00:49:22 +02:00
|
|
|
cyclingAllowed: cyclingAllowed
|
2020-07-17 17:21:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
constructor(carWidth: number,
|
2020-07-17 18:57:07 +02:00
|
|
|
cyclistWidth: number,
|
|
|
|
pedestrianWidth: number) {
|
2020-07-31 04:58:58 +02:00
|
|
|
super("width");
|
2020-07-17 17:21:07 +02:00
|
|
|
this.carWidth = carWidth;
|
|
|
|
this.cyclistWidth = cyclistWidth;
|
2020-07-17 18:57:07 +02:00
|
|
|
this.pedestrianWidth = pedestrianWidth;
|
2020-07-18 20:40:51 +02:00
|
|
|
this.minzoom = 12;
|
2020-07-17 18:57:07 +02:00
|
|
|
|
|
|
|
function r(n: number) {
|
|
|
|
const pre = Math.floor(n);
|
|
|
|
const post = Math.floor((n * 10) % 10);
|
|
|
|
return "" + pre + "." + post;
|
|
|
|
}
|
2020-07-17 17:21:07 +02:00
|
|
|
|
|
|
|
this.name = "widths";
|
2020-09-05 15:27:35 +02:00
|
|
|
this.overpassFilter = new RegexTag("width:carriageway", /.*/);
|
2020-07-17 17:21:07 +02:00
|
|
|
|
|
|
|
this.title = new TagRenderingOptions({
|
|
|
|
freeform: {
|
|
|
|
renderTemplate: "{name}",
|
|
|
|
template: "$$$",
|
|
|
|
key: "name"
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
const self = this;
|
|
|
|
this.style = (properties) => {
|
|
|
|
|
2020-07-17 18:57:07 +02:00
|
|
|
let c = "#f00";
|
2020-07-17 17:21:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
const props = self.calcProps(properties);
|
2020-07-27 09:38:21 +02:00
|
|
|
if (props.width >= props.targetWidthIgnoringPedestrians) {
|
2020-07-17 18:57:07 +02:00
|
|
|
c = "#fa0"
|
|
|
|
}
|
2020-07-18 00:49:22 +02:00
|
|
|
if (props.width >= props.targetWidth || !props.cyclingAllowed) {
|
2020-07-17 18:57:07 +02:00
|
|
|
c = "#0c0";
|
2020-07-17 17:21:07 +02:00
|
|
|
}
|
|
|
|
|
2020-07-17 18:57:07 +02:00
|
|
|
if (!props.parkingStateKnown && properties["note:width:carriageway"] === undefined) {
|
2020-07-17 17:21:07 +02:00
|
|
|
c = "#f0f"
|
|
|
|
}
|
2020-07-17 18:57:07 +02:00
|
|
|
|
2020-09-05 15:27:35 +02:00
|
|
|
if (!this._notCarfree.matchesProperties(properties)) {
|
2020-07-17 17:21:07 +02:00
|
|
|
c = "#aaa";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-17 18:57:07 +02:00
|
|
|
// Mark probably wrong data
|
2020-07-17 17:21:07 +02:00
|
|
|
if (props.width > 15) {
|
2020-07-17 18:57:07 +02:00
|
|
|
c = "#f0f"
|
2020-07-17 17:21:07 +02:00
|
|
|
}
|
|
|
|
|
2020-07-17 18:57:07 +02:00
|
|
|
let dashArray = undefined;
|
|
|
|
if (props.onewayBike) {
|
2020-09-09 18:42:13 +02:00
|
|
|
dashArray = [5, 6]
|
2020-07-17 18:57:07 +02:00
|
|
|
}
|
2020-07-17 17:21:07 +02:00
|
|
|
return {
|
|
|
|
icon: null,
|
|
|
|
color: c,
|
2020-09-09 18:42:13 +02:00
|
|
|
weight: 5,
|
2020-07-17 17:21:07 +02:00
|
|
|
dashArray: dashArray
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.elementsToShow = [
|
|
|
|
new TagRenderingOptions({
|
|
|
|
mappings: [
|
|
|
|
{
|
|
|
|
k: this._bothSideParking,
|
2020-07-17 18:57:07 +02:00
|
|
|
txt: "Auto's kunnen langs beide zijden parkeren.<br+>Dit gebruikt <b>" + r(this.carWidth * 2) + "m</b><br/>"
|
2020-07-17 17:21:07 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
k: this._oneSideParking,
|
2020-07-17 18:57:07 +02:00
|
|
|
txt: "Auto's kunnen langs één kant parkeren.<br/>Dit gebruikt <b>" + r(this.carWidth) + "m</b><br/>"
|
2020-07-17 17:21:07 +02:00
|
|
|
},
|
2020-07-19 00:13:45 +02:00
|
|
|
{
|
|
|
|
k: this._otherParkingMode,
|
|
|
|
txt: "Deze straat heeft dwarsparkeren of diagonaalparkeren aan minstens één zijde. Deze parkeerruimte is niet opgenomen in de straatbreedte."
|
|
|
|
},
|
2020-07-17 17:21:07 +02:00
|
|
|
{k: this._noSideParking, txt: "Auto's mogen hier niet parkeren"},
|
2020-07-17 18:57:07 +02:00
|
|
|
],
|
|
|
|
freeform: {
|
|
|
|
key: "note:width:carriageway",
|
|
|
|
renderTemplate: "{note:width:carriageway}",
|
|
|
|
template: "$$$",
|
|
|
|
}
|
2020-08-31 02:59:47 +02:00
|
|
|
}).OnlyShowIf(this._notCarfree),
|
2020-07-17 18:57:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
new TagRenderingOptions({
|
|
|
|
mappings: [
|
|
|
|
{
|
|
|
|
k: this._sidewalkNone,
|
|
|
|
txt: "Deze straat heeft geen voetpaden. Voetgangers hebben hier <b>" + r(this.pedestrianWidth * 2) + "m</b> nodig"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
k: new Or([this._sidewalkLeft, this._sidewalkRight]),
|
|
|
|
txt: "Deze straat heeft een voetpad aan één kant. Voetgangers hebben hier <b>" + r(this.pedestrianWidth) + "m</b> nodig"
|
|
|
|
},
|
|
|
|
{k: this._sidewalkBoth, txt: "Deze straat heeft voetpad aan beide zijden."},
|
|
|
|
],
|
|
|
|
freeform: {
|
|
|
|
key: "note:width:carriageway",
|
|
|
|
renderTemplate: "{note:width:carriageway}",
|
|
|
|
template: "$$$",
|
|
|
|
}
|
2020-08-31 02:59:47 +02:00
|
|
|
}).OnlyShowIf(this._notCarfree),
|
2020-07-17 18:57:07 +02:00
|
|
|
|
|
|
|
|
2020-07-17 17:21:07 +02:00
|
|
|
new TagRenderingOptions({
|
|
|
|
mappings: [
|
2020-07-18 00:49:22 +02:00
|
|
|
{
|
|
|
|
k: new Tag("bicycle", "use_sidepath"),
|
|
|
|
txt: "Er is een afgescheiden, verplicht te gebruiken fietspad. Fietsen op dit wegsegment hoeft dus niet"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
k: new Tag("bicycle", "no"),
|
|
|
|
txt: "Fietsen is hier niet toegestaan"
|
|
|
|
},
|
2020-07-17 17:21:07 +02:00
|
|
|
{
|
|
|
|
k: new Tag("oneway:bicycle", "yes"),
|
2020-07-17 18:57:07 +02:00
|
|
|
txt: "Eenrichtingsverkeer, óók voor fietsers. Dit gebruikt <b>" + r(this.carWidth + this.cyclistWidth) + "m</b>"
|
2020-07-17 17:21:07 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
k: new And([new Tag("oneway", "yes"), new Tag("oneway:bicycle", "no")]),
|
2020-07-17 18:57:07 +02:00
|
|
|
txt: "Tweerichtingverkeer voor fietsers, eenrichting voor auto's Dit gebruikt <b>" + r(this.carWidth + 2 * this.cyclistWidth) + "m</b>"
|
2020-07-17 17:21:07 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
k: new Tag("oneway", "yes"),
|
|
|
|
txt: "Eenrichtingsverkeer voor iedereen. Dit gebruikt <b>" + (this.carWidth + this.cyclistWidth) + "m</b>"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
k: null,
|
2020-07-17 18:57:07 +02:00
|
|
|
txt: "Tweerichtingsverkeer voor iedereen. Dit gebruikt <b>" + r(2 * this.carWidth + 2 * this.cyclistWidth) + "m</b>"
|
2020-07-17 17:21:07 +02:00
|
|
|
}
|
|
|
|
]
|
2020-08-31 02:59:47 +02:00
|
|
|
}).OnlyShowIf(this._notCarfree),
|
2020-07-17 17:21:07 +02:00
|
|
|
|
|
|
|
new TagRenderingOptions(
|
|
|
|
{
|
|
|
|
tagsPreprocessor: (tags) => {
|
|
|
|
const props = self.calcProps(tags);
|
2020-07-17 18:57:07 +02:00
|
|
|
tags.targetWidth = r(props.targetWidth);
|
|
|
|
tags.short = "";
|
|
|
|
if (props.width < props.targetWidth) {
|
2020-09-28 01:00:24 +02:00
|
|
|
tags.short = `<span class='alert'>Dit is ${r(props.targetWidth - props.width)}m te weinig</span>`
|
2020-07-17 18:57:07 +02:00
|
|
|
}
|
2020-09-28 01:00:24 +02:00
|
|
|
console.log("SHORT", tags.short)
|
2020-07-17 17:21:07 +02:00
|
|
|
},
|
2020-09-28 01:00:24 +02:00
|
|
|
mappings: [
|
|
|
|
{
|
|
|
|
k: null,
|
|
|
|
txt: "De totale nodige ruimte voor vlot en veilig verkeer is dus <span class='thanks'>{targetWidth}m</span><br/>{short}"
|
|
|
|
}
|
2020-07-31 01:45:54 +02:00
|
|
|
]
|
2020-07-17 17:21:07 +02:00
|
|
|
}
|
2020-08-31 02:59:47 +02:00
|
|
|
).OnlyShowIf(this._notCarfree),
|
2020-07-17 17:21:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
new TagRenderingOptions({
|
|
|
|
mappings: [
|
|
|
|
{k:new Tag("highway","living_street"),txt: "Dit is een woonerf"},
|
2020-07-18 20:40:51 +02:00
|
|
|
{k:new Tag("highway","pedestrian"),txt: "Deze weg is autovrij"}
|
2020-07-17 17:21:07 +02:00
|
|
|
]
|
|
|
|
}),
|
|
|
|
|
|
|
|
new TagRenderingOptions({
|
|
|
|
mappings: [
|
|
|
|
{
|
|
|
|
k: new Tag("sidewalk", "none"),
|
|
|
|
txt: "De afstand van huis tot huis is <b>{width:carriageway}m</b>"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
k: new Tag("sidewalk", "left"),
|
|
|
|
txt: "De afstand van huis tot voetpad is <b>{width:carriageway}m</b>"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
k: new Tag("sidewalk", "right"),
|
|
|
|
txt: "De afstand van huis tot voetpad is <b>{width:carriageway}m</b>"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
k: new Tag("sidewalk", "both"),
|
|
|
|
txt: "De afstand van voetpad tot voetpad is <b>{width:carriageway}m</b>"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
k: new Tag("sidewalk", ""),
|
|
|
|
txt: "De straatbreedte is <b>{width:carriageway}m</b>"
|
|
|
|
}
|
|
|
|
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|