From 95101a72125f607bf992dc97c6eac9f28919e789 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Mon, 8 Nov 2021 19:46:43 +0100 Subject: [PATCH] Fix line renderings --- Docs/Schemas/LayerConfigJson.schema.json | 37 +++++++++++++++++++ Docs/Schemas/LayerConfigJsonJSC.ts | 37 +++++++++++++++++++ Docs/Schemas/LayoutConfigJson.schema.json | 37 +++++++++++++++++++ Docs/Schemas/LayoutConfigJsonJSC.ts | 37 +++++++++++++++++++ .../LineRenderingConfigJson.schema.json | 37 +++++++++++++++++++ Docs/Schemas/LineRenderingConfigJsonJSC.ts | 37 +++++++++++++++++++ Docs/Schemas/TilesourceConfigJson.schema.json | 37 +++++++++++++++++++ Docs/Schemas/TilesourceConfigJsonJSC.ts | 37 +++++++++++++++++++ Models/ThemeConfig/LineRenderingConfig.ts | 31 ++++++++++++---- UI/ShowDataLayer/ShowDataLayer.ts | 3 +- assets/themes/sidewalks/sidewalks.json | 9 +++-- 11 files changed, 327 insertions(+), 12 deletions(-) diff --git a/Docs/Schemas/LayerConfigJson.schema.json b/Docs/Schemas/LayerConfigJson.schema.json index bd55fed7fa..471fd02820 100644 --- a/Docs/Schemas/LayerConfigJson.schema.json +++ b/Docs/Schemas/LayerConfigJson.schema.json @@ -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": [ diff --git a/Docs/Schemas/LayerConfigJsonJSC.ts b/Docs/Schemas/LayerConfigJsonJSC.ts index 3ed0943cdf..3f72a2e974 100644 --- a/Docs/Schemas/LayerConfigJsonJSC.ts +++ b/Docs/Schemas/LayerConfigJsonJSC.ts @@ -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": [ diff --git a/Docs/Schemas/LayoutConfigJson.schema.json b/Docs/Schemas/LayoutConfigJson.schema.json index d1a251ffcc..0acf04ad5d 100644 --- a/Docs/Schemas/LayoutConfigJson.schema.json +++ b/Docs/Schemas/LayoutConfigJson.schema.json @@ -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": [ diff --git a/Docs/Schemas/LayoutConfigJsonJSC.ts b/Docs/Schemas/LayoutConfigJsonJSC.ts index 881b5ecd74..2c337340e2 100644 --- a/Docs/Schemas/LayoutConfigJsonJSC.ts +++ b/Docs/Schemas/LayoutConfigJsonJSC.ts @@ -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": [ diff --git a/Docs/Schemas/LineRenderingConfigJson.schema.json b/Docs/Schemas/LineRenderingConfigJson.schema.json index 162aa38eb2..0f7289f025 100644 --- a/Docs/Schemas/LineRenderingConfigJson.schema.json +++ b/Docs/Schemas/LineRenderingConfigJson.schema.json @@ -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": [ diff --git a/Docs/Schemas/LineRenderingConfigJsonJSC.ts b/Docs/Schemas/LineRenderingConfigJsonJSC.ts index 9d71a41b54..2c0642834f 100644 --- a/Docs/Schemas/LineRenderingConfigJsonJSC.ts +++ b/Docs/Schemas/LineRenderingConfigJsonJSC.ts @@ -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": [ diff --git a/Docs/Schemas/TilesourceConfigJson.schema.json b/Docs/Schemas/TilesourceConfigJson.schema.json index 4e86e52cd8..da181e8e54 100644 --- a/Docs/Schemas/TilesourceConfigJson.schema.json +++ b/Docs/Schemas/TilesourceConfigJson.schema.json @@ -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": [ diff --git a/Docs/Schemas/TilesourceConfigJsonJSC.ts b/Docs/Schemas/TilesourceConfigJsonJSC.ts index 1183f4be6c..a21c3f2ccb 100644 --- a/Docs/Schemas/TilesourceConfigJsonJSC.ts +++ b/Docs/Schemas/TilesourceConfigJsonJSC.ts @@ -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": [ diff --git a/Models/ThemeConfig/LineRenderingConfig.ts b/Models/ThemeConfig/LineRenderingConfig.ts index 93d746f4f3..f2eed60d14 100644 --- a/Models/ThemeConfig/LineRenderingConfig.ts +++ b/Models/ThemeConfig/LineRenderingConfig.ts @@ -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 + } } \ No newline at end of file diff --git a/UI/ShowDataLayer/ShowDataLayer.ts b/UI/ShowDataLayer/ShowDataLayer.ts index 44c5dcad82..6c74c5f4a4 100644 --- a/UI/ShowDataLayer/ShowDataLayer.ts +++ b/UI/ShowDataLayer/ShowDataLayer.ts @@ -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) } diff --git a/assets/themes/sidewalks/sidewalks.json b/assets/themes/sidewalks/sidewalks.json index 721e3108c2..71f1baa3c2 100644 --- a/assets/themes/sidewalks/sidewalks.json +++ b/assets/themes/sidewalks/sidewalks.json @@ -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 } ],