General cleanup, improve sidewalk rendering

This commit is contained in:
Pieter Vander Vennet 2021-10-22 02:16:07 +02:00
parent 20fa5028d9
commit 72edc9bdcc
6 changed files with 53 additions and 35 deletions

View file

@ -97,9 +97,9 @@ export default class SimpleMetaTagger {
/** /**
* Sets the key onto the properties (but doesn't overwrite if already existing) * Sets the key onto the properties (but doesn't overwrite if already existing)
*/ */
function set(key, value) { function set(k, value) {
if (tgs[key] === undefined || tgs[key] === "") { if (tgs[k] === undefined || tgs[k] === "") {
tgs[key] = value tgs[k] = value
somethingChanged = true somethingChanged = true
} }
} }

View file

@ -25,10 +25,7 @@ export default class LineRenderingConfig extends WithContextLoader {
this.offset = this.tr("offset", "0"); this.offset = this.tr("offset", "0");
} }
public GenerateLeafletStyle( tags: {} ):
public GenerateLeafletStyle(
tags: UIEventSource<any>
):
{ {
color: string, color: string,
weight: number, weight: number,
@ -48,8 +45,8 @@ export default class LineRenderingConfig extends WithContextLoader {
if (tags === undefined) { if (tags === undefined) {
return deflt return deflt
} }
const str = tr?.GetRenderValue(tags.data)?.txt ?? deflt; const str = tr?.GetRenderValue(tags)?.txt ?? deflt;
return Utils.SubstituteKeys(str, tags.data)?.replace(/{.*}/g, ""); return Utils.SubstituteKeys(str, tags)?.replace(/{.*}/g, "");
} }
const dashArray = render(this.dashArray)?.split(" ")?.map(Number); const dashArray = render(this.dashArray)?.split(" ")?.map(Number);
@ -62,7 +59,6 @@ export default class LineRenderingConfig extends WithContextLoader {
const weight = rendernum(this.width, 5); const weight = rendernum(this.width, 5);
const offset = rendernum(this.offset, 0) const offset = rendernum(this.offset, 0)
console.log("Calculated offset:", offset, "for", this.offset)
return { return {
color, color,
weight, weight,

View file

@ -141,7 +141,7 @@ export default class TagRenderingConfig {
const mp = { const mp = {
if: TagUtils.Tag(mapping.if, `${mappingContext}.if`), if: TagUtils.Tag(mapping.if, `${mappingContext}.if`),
ifnot: (mapping.ifnot !== undefined ? TagUtils.Tag(mapping.ifnot, `${mappingContext}.ifnot`) : undefined), ifnot: (mapping.ifnot !== undefined ? TagUtils.Tag(mapping.ifnot, `${mappingContext}.ifnot`) : undefined),
then: Translations.T(mapping.then, `{mappingContext}.then`), then: Translations.T(mapping.then, `${mappingContext}.then`),
hideInAnswer: hideInAnswer hideInAnswer: hideInAnswer
}; };
if (this.question) { if (this.question) {

View file

@ -148,14 +148,18 @@ export default class ShowDataLayer {
try { try {
if ((feat.geometry.type === "LineString" || feat.geometry.type === "MultiLineString")) { if ((feat.geometry.type === "LineString" || feat.geometry.type === "MultiLineString")) {
const self = this;
const coords = L.GeoJSON.coordsToLatLngs(feat.geometry.coordinates) const coords = L.GeoJSON.coordsToLatLngs(feat.geometry.coordinates)
const tagsSource = this.allElements?.addOrGetElement(feat) ?? new UIEventSource<any>(feat.properties); const tagsSource = this.allElements?.addOrGetElement(feat) ?? new UIEventSource<any>(feat.properties);
const lineStyle = this._layerToShow.lineRendering[feat.lineRenderingIndex].GenerateLeafletStyle(tagsSource) let offsettedLine;
const offsettedLine = L.polyline(coords, lineStyle); tagsSource.map(tags => this._layerToShow.lineRendering[feat.lineRenderingIndex].GenerateLeafletStyle(tags)).addCallbackAndRunD(lineStyle => {
if (offsettedLine !== undefined) {
self.geoLayer.removeLayer(offsettedLine)
}
offsettedLine = L.polyline(coords, lineStyle);
this.postProcessFeature(feat, offsettedLine) this.postProcessFeature(feat, offsettedLine)
offsettedLine.addTo(this.geoLayer) offsettedLine.addTo(this.geoLayer)
})
} else { } else {
this.geoLayer.addData(feat); this.geoLayer.addData(feat);
} }

View file

@ -26,6 +26,9 @@ export default class Translations {
if (t === undefined || t === null) { if (t === undefined || t === null) {
return undefined; return undefined;
} }
if(typeof t === "number"){
t = ""+t
}
if (typeof t === "string") { if (typeof t === "string") {
return new Translation({"*": t}, context); return new Translation({"*": t}, context);
} }

View file

@ -41,7 +41,7 @@
"tagRenderings": [], "tagRenderings": [],
"mapRendering": [ "mapRendering": [
{ {
"color": "#ddd", "color": "#ffffff55",
"width": 8 "width": 8
}, },
{ {
@ -49,11 +49,12 @@
"render": "#888" "render": "#888"
}, },
"width": { "width": {
"render": "8", "render": 6,
"mappings": [ "mappings": [
{ {
"if": { "if": {
"or": [ "or": [
"sidewalk:left=",
"sidewalk:left=no", "sidewalk:left=no",
"sidewalk:left=separate" "sidewalk:left=separate"
] ]
@ -62,12 +63,26 @@
} }
] ]
}, },
"offset": -8 "offset": -6
}, },
{ {
"color": "#888", "color": "#888",
"width": 8, "width": {
"offset": 8 "render": 6,
"mappings": [
{
"if": {
"or": [
"sidewalk:right=",
"sidewalk:right=no",
"sidewalk:right=separate"
]
},
"then": 0
}
]
},
"offset": 6
} }
], ],
"allowSplit": true "allowSplit": true