Fix line renderings

This commit is contained in:
Pieter Vander Vennet 2021-11-08 19:46:43 +01:00
parent ec09a72cae
commit 95101a7212
11 changed files with 327 additions and 12 deletions

View file

@ -706,6 +706,43 @@
}
]
},
"lineCap": {
"description": "The form at the end of a line",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"type": "string"
}
]
},
"fill": {
"description": "Wehter or not to fill polygons",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"enum": [
"no",
"yes"
],
"type": "string"
}
]
},
"fillColor": {
"description": "The color to fill a polygon with.\nIf undefined, this will be slightly more opaque version of the stroke line",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"type": "string"
}
]
},
"offset": {
"description": "The number of pixels this line should be moved.\nUse a positive numbe to move to the right, a negative to move to the left (left/right as defined by the drawing direction of the line).\n\nIMPORTANT: MapComplete will already normalize 'key:both:property' and 'key:both' into the corresponding 'key:left' and 'key:right' tagging (same for 'sidewalk=left/right/both' which is rewritten to 'sidewalk:left' and 'sidewalk:right')\nThis simplifies programming. Refer to the CalculatedTags.md-documentation for more details",
"anyOf": [

View file

@ -702,6 +702,43 @@ export default {
}
]
},
"lineCap": {
"description": "The form at the end of a line",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"type": "string"
}
]
},
"fill": {
"description": "Wehter or not to fill polygons",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"enum": [
"no",
"yes"
],
"type": "string"
}
]
},
"fillColor": {
"description": "The color to fill a polygon with.\nIf undefined, this will be slightly more opaque version of the stroke line",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"type": "string"
}
]
},
"offset": {
"description": "The number of pixels this line should be moved.\nUse a positive numbe to move to the right, a negative to move to the left (left/right as defined by the drawing direction of the line).\n\nIMPORTANT: MapComplete will already normalize 'key:both:property' and 'key:both' into the corresponding 'key:left' and 'key:right' tagging (same for 'sidewalk=left/right/both' which is rewritten to 'sidewalk:left' and 'sidewalk:right')\nThis simplifies programming. Refer to the CalculatedTags.md-documentation for more details",
"anyOf": [

View file

@ -612,6 +612,43 @@
}
]
},
"lineCap": {
"description": "The form at the end of a line",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"type": "string"
}
]
},
"fill": {
"description": "Wehter or not to fill polygons",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"enum": [
"no",
"yes"
],
"type": "string"
}
]
},
"fillColor": {
"description": "The color to fill a polygon with.\nIf undefined, this will be slightly more opaque version of the stroke line",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"type": "string"
}
]
},
"offset": {
"description": "The number of pixels this line should be moved.\nUse a positive numbe to move to the right, a negative to move to the left (left/right as defined by the drawing direction of the line).\n\nIMPORTANT: MapComplete will already normalize 'key:both:property' and 'key:both' into the corresponding 'key:left' and 'key:right' tagging (same for 'sidewalk=left/right/both' which is rewritten to 'sidewalk:left' and 'sidewalk:right')\nThis simplifies programming. Refer to the CalculatedTags.md-documentation for more details",
"anyOf": [

View file

@ -608,6 +608,43 @@ export default {
}
]
},
"lineCap": {
"description": "The form at the end of a line",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"type": "string"
}
]
},
"fill": {
"description": "Wehter or not to fill polygons",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"enum": [
"no",
"yes"
],
"type": "string"
}
]
},
"fillColor": {
"description": "The color to fill a polygon with.\nIf undefined, this will be slightly more opaque version of the stroke line",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"type": "string"
}
]
},
"offset": {
"description": "The number of pixels this line should be moved.\nUse a positive numbe to move to the right, a negative to move to the left (left/right as defined by the drawing direction of the line).\n\nIMPORTANT: MapComplete will already normalize 'key:both:property' and 'key:both' into the corresponding 'key:left' and 'key:right' tagging (same for 'sidewalk=left/right/both' which is rewritten to 'sidewalk:left' and 'sidewalk:right')\nThis simplifies programming. Refer to the CalculatedTags.md-documentation for more details",
"anyOf": [

View file

@ -35,6 +35,43 @@
}
]
},
"lineCap": {
"description": "The form at the end of a line",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"type": "string"
}
]
},
"fill": {
"description": "Wehter or not to fill polygons",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"enum": [
"no",
"yes"
],
"type": "string"
}
]
},
"fillColor": {
"description": "The color to fill a polygon with.\nIf undefined, this will be slightly more opaque version of the stroke line",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"type": "string"
}
]
},
"offset": {
"description": "The number of pixels this line should be moved.\nUse a positive numbe to move to the right, a negative to move to the left (left/right as defined by the drawing direction of the line).\n\nIMPORTANT: MapComplete will already normalize 'key:both:property' and 'key:both' into the corresponding 'key:left' and 'key:right' tagging (same for 'sidewalk=left/right/both' which is rewritten to 'sidewalk:left' and 'sidewalk:right')\nThis simplifies programming. Refer to the CalculatedTags.md-documentation for more details",
"anyOf": [

View file

@ -35,6 +35,43 @@ export default {
}
]
},
"lineCap": {
"description": "The form at the end of a line",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"type": "string"
}
]
},
"fill": {
"description": "Wehter or not to fill polygons",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"enum": [
"no",
"yes"
],
"type": "string"
}
]
},
"fillColor": {
"description": "The color to fill a polygon with.\nIf undefined, this will be slightly more opaque version of the stroke line",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"type": "string"
}
]
},
"offset": {
"description": "The number of pixels this line should be moved.\nUse a positive numbe to move to the right, a negative to move to the left (left/right as defined by the drawing direction of the line).\n\nIMPORTANT: MapComplete will already normalize 'key:both:property' and 'key:both' into the corresponding 'key:left' and 'key:right' tagging (same for 'sidewalk=left/right/both' which is rewritten to 'sidewalk:left' and 'sidewalk:right')\nThis simplifies programming. Refer to the CalculatedTags.md-documentation for more details",
"anyOf": [

View file

@ -375,6 +375,43 @@
}
]
},
"lineCap": {
"description": "The form at the end of a line",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"type": "string"
}
]
},
"fill": {
"description": "Wehter or not to fill polygons",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"enum": [
"no",
"yes"
],
"type": "string"
}
]
},
"fillColor": {
"description": "The color to fill a polygon with.\nIf undefined, this will be slightly more opaque version of the stroke line",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"type": "string"
}
]
},
"offset": {
"description": "The number of pixels this line should be moved.\nUse a positive numbe to move to the right, a negative to move to the left (left/right as defined by the drawing direction of the line).\n\nIMPORTANT: MapComplete will already normalize 'key:both:property' and 'key:both' into the corresponding 'key:left' and 'key:right' tagging (same for 'sidewalk=left/right/both' which is rewritten to 'sidewalk:left' and 'sidewalk:right')\nThis simplifies programming. Refer to the CalculatedTags.md-documentation for more details",
"anyOf": [

View file

@ -371,6 +371,43 @@ export default {
}
]
},
"lineCap": {
"description": "The form at the end of a line",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"type": "string"
}
]
},
"fill": {
"description": "Wehter or not to fill polygons",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"enum": [
"no",
"yes"
],
"type": "string"
}
]
},
"fillColor": {
"description": "The color to fill a polygon with.\nIf undefined, this will be slightly more opaque version of the stroke line",
"anyOf": [
{
"$ref": "#/definitions/TagRenderingConfigJson"
},
{
"type": "string"
}
]
},
"offset": {
"description": "The number of pixels this line should be moved.\nUse a positive numbe to move to the right, a negative to move to the left (left/right as defined by the drawing direction of the line).\n\nIMPORTANT: MapComplete will already normalize 'key:both:property' and 'key:both' into the corresponding 'key:left' and 'key:right' tagging (same for 'sidewalk=left/right/both' which is rewritten to 'sidewalk:left' and 'sidewalk:right')\nThis simplifies programming. Refer to the CalculatedTags.md-documentation for more details",
"anyOf": [

View file

@ -21,8 +21,8 @@ export default class LineRenderingConfig extends WithContextLoader {
this.width = this.tr("width", "7");
this.dashArray = this.tr("dashArray", "");
this.lineCap = this.tr("lineCap", "round");
this.fill = this.tr("fill", "round");
this.fillColor = this.tr("fillColor", "round");
this.fill = this.tr("fill", undefined);
this.fillColor = this.tr("fillColor", undefined);
this.leftRightSensitive = json.offset !== undefined && json.offset !== 0 && json.offset !== "0"
@ -30,7 +30,7 @@ export default class LineRenderingConfig extends WithContextLoader {
}
public GenerateLeafletStyle(tags: {}):
{ fillColor: string; color: string; lineCap: string; offset: number; weight: number; dashArray: string; fill: string } {
{ fillColor?: string; color: string; lineCap: string; offset: number; weight: number; dashArray: string; fill?: boolean } {
function rendernum(tr: TagRenderingConfig, deflt: number) {
const str = Number(render(tr, "" + deflt));
const n = Number(str);
@ -44,7 +44,11 @@ export default class LineRenderingConfig extends WithContextLoader {
if (tags === undefined) {
return deflt
}
if(tr === undefined){return deflt}
const str = tr?.GetRenderValue(tags)?.txt ?? deflt;
if (str === "") {
return deflt
}
return Utils.SubstituteKeys(str, tags)?.replace(/{.*}/g, "");
}
@ -55,16 +59,27 @@ export default class LineRenderingConfig extends WithContextLoader {
"--catch-detail-color"
);
}
return {
const style = {
color,
dashArray,
weight: rendernum(this.width, 5),
lineCap: render(this.lineCap),
offset: rendernum(this.offset, 0),
fill: render(this.fill),
fillColor: render(this.fillColor)
offset: rendernum(this.offset, 0)
}
const fillStr = render(this.fill, undefined)
let fill: boolean = undefined;
if (fillStr !== undefined && fillStr !== "") {
style["fill"] = fillStr === "yes" || fillStr === "true"
}
const fillColorStr = render(this.fillColor, undefined)
if(fillColorStr !== undefined){
style["fillColor"] = fillColorStr
}
return style
}
}

View file

@ -172,13 +172,14 @@ export default class ShowDataLayer {
if (offsettedLine !== undefined) {
self.geoLayer.removeLayer(offsettedLine)
}
// @ts-ignore
offsettedLine = L.polyline(coords, lineStyle);
this.postProcessFeature(feat, offsettedLine)
offsettedLine.addTo(this.geoLayer)
})
} else {
this.geoLayer.addData(feat);
}
}
} catch (e) {
console.error("Could not add ", feat, "to the geojson layer in leaflet due to", e, e.stack)
}

View file

@ -110,12 +110,13 @@
"end"
],
"icon": "circle:#ccc",
"iconSize": "20,20,center"
"iconSize": "3,3,center"
},
{
"#": "The center line",
"color": "#ffffff55",
"width": 8
"width": 8,
"lineCap": "butt"
},
{
"#": "left",
@ -145,7 +146,8 @@
}
]
},
"offset": -6
"offset": -6,
"lineCap": "butt"
},
{
"color": "#888",
@ -172,6 +174,7 @@
}
]
},
"lineCap": "butt",
"offset": 6
}
],