From 30dacffddfeaf04d99bc2b10373bc474ddb916b0 Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Mon, 13 Sep 2021 06:31:12 +0300 Subject: [PATCH] Support bridges for roads. --- map_machine/constructor.py | 5 +---- map_machine/figure.py | 29 +++++++++++++++++++++++++++++ map_machine/icons/icons.svg | 7 +++++-- map_machine/mapper.py | 29 +++-------------------------- 4 files changed, 38 insertions(+), 32 deletions(-) diff --git a/map_machine/constructor.py b/map_machine/constructor.py index 8631341..873a032 100644 --- a/map_machine/constructor.py +++ b/map_machine/constructor.py @@ -291,10 +291,7 @@ class Constructor: priority: int icon_set: IconSet icon_set, priority = self.scheme.get_icon( - self.extractor, - line.tags, - processed, - self.configuration, + self.extractor, line.tags, processed, self.configuration ) if icon_set is not None: labels: list[Label] = self.scheme.construct_text( diff --git a/map_machine/figure.py b/map_machine/figure.py index a9fc29e..8a16a82 100644 --- a/map_machine/figure.py +++ b/map_machine/figure.py @@ -245,6 +245,35 @@ class Road(Figure): except ValueError: pass + def draw( + self, + svg: Drawing, + flinger: Flinger, + color: Color, + extra_width: float = 0, + ) -> None: + """Draw road as simple SVG path.""" + flinger.get_scale() + width: float + if self.width is not None: + width = self.width + else: + width = self.matcher.default_width + if extra_width and self.tags.get("bridge") == "yes": + color = Color("#666666") + scale: float = flinger.get_scale(self.outers[0][0].coordinates) + path_commands: str = self.get_path(flinger) + path: Path = Path(d=path_commands) + style: dict[str, Any] = { + "fill": "none", + "stroke": color.hex, + "stroke-linecap": "round", + "stroke-linejoin": "round", + "stroke-width": scale * width + extra_width, + } + path.update(style) + svg.add(path) + class Crater(Tagged): """ diff --git a/map_machine/icons/icons.svg b/map_machine/icons/icons.svg index 1c84991..1a48cd6 100644 --- a/map_machine/icons/icons.svg +++ b/map_machine/icons/icons.svg @@ -23321,9 +23321,12 @@ inkscape:connector-curvature="0" sodipodi:nodetypes="cc" /> + inkscape:label="#rect11071"> + toll booth + diff --git a/map_machine/mapper.py b/map_machine/mapper.py index 2bfb83b..53022bf 100644 --- a/map_machine/mapper.py +++ b/map_machine/mapper.py @@ -4,7 +4,7 @@ Simple OpenStreetMap renderer. import argparse import logging from pathlib import Path -from typing import Any, Iterator, Optional +from typing import Iterator, Optional import numpy as np import svgwrite @@ -74,9 +74,9 @@ class Map: constructor.roads, key=lambda x: x.matcher.priority ) for road in roads: - self.draw_road(road, road.matcher.border_color, 2) + road.draw(self.svg, self.flinger, road.matcher.border_color, 2) for road in roads: - self.draw_road(road, road.matcher.color) + road.draw(self.svg, self.flinger, road.matcher.color) for tree in constructor.trees: tree.draw(self.svg, self.flinger, self.scheme) @@ -160,29 +160,6 @@ class Map: progress_bar(-1, count, step=1, text="Drawing buildings") - def draw_road( - self, road: Road, color: Color, extra_width: float = 0 - ) -> None: - """Draw road as simple SVG path.""" - self.flinger.get_scale() - width: float - if road.width is not None: - width = road.width - else: - width = road.matcher.default_width - scale: float = self.flinger.get_scale(road.outers[0][0].coordinates) - path_commands: str = road.get_path(self.flinger) - path: SVGPath = SVGPath(d=path_commands) - style: dict[str, Any] = { - "fill": "none", - "stroke": color.hex, - "stroke-linecap": "round", - "stroke-linejoin": "round", - "stroke-width": scale * width + extra_width, - } - path.update(style) - self.svg.add(path) - def draw_roads(self, roads: Iterator[Road]) -> None: """Draw road as simple SVG path.""" nodes: dict[OSMNode, set[RoadPart]] = {}