From f719fc35775c6f12b2cb5857aa7d0ae8e8dda227 Mon Sep 17 00:00:00 2001 From: Sergey Vartanov Date: Sun, 23 Jan 2022 07:27:09 +0300 Subject: [PATCH] Close #105: add style for construction. --- map_machine/feature/building.py | 38 +++++++++++++++++++++------------ map_machine/scheme/default.yml | 6 ++++-- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/map_machine/feature/building.py b/map_machine/feature/building.py index f274a1d..8101163 100644 --- a/map_machine/feature/building.py +++ b/map_machine/feature/building.py @@ -1,7 +1,7 @@ """ Buildings on the map. """ -from typing import Any, Optional +from typing import Optional import numpy as np from colour import Color @@ -14,7 +14,7 @@ from map_machine.figure import Figure from map_machine.geometry.flinger import Flinger from map_machine.geometry.vector import Segment from map_machine.osm.osm_reader import OSMNode -from map_machine.scheme import Scheme, LineStyle +from map_machine.scheme import Scheme BUILDING_HEIGHT_SCALE: float = 2.5 BUILDING_MINIMAL_HEIGHT: float = 8.0 @@ -33,11 +33,17 @@ class Building(Figure): ) -> None: super().__init__(tags, inners, outers) - style: dict[str, Any] = { - "fill": scheme.get_color("building_color").hex, - "stroke": scheme.get_color("building_border_color").hex, - } - self.line_style: LineStyle = LineStyle(style) + self.is_construction: bool = tags.get("building") == "construction" + + if self.is_construction: + self.fill: Color = scheme.get_color("building_construction_color") + self.stroke: Color = scheme.get_color( + "building_construction_border_color" + ) + else: + self.fill: Color = scheme.get_color("building_color") + self.stroke: Color = scheme.get_color("building_border_color") + self.parts: list[Segment] = [] for nodes in self.inners + self.outers: @@ -77,9 +83,12 @@ class Building(Figure): def draw(self, svg: Drawing, flinger: Flinger) -> None: """Draw simple building shape.""" - path: Path = Path(d=self.get_path(flinger)) - path.update(self.line_style.style) - path.update({"stroke-linejoin": "round"}) + path: Path = Path( + d=self.get_path(flinger), + stroke=self.stroke, + fill=self.fill, + stroke_linejoin="round", + ) svg.add(path) def draw_shade(self, building_shade: Group, flinger: Flinger) -> None: @@ -89,7 +98,7 @@ class Building(Figure): shift_2: np.ndarray = np.array((scale * self.height, 0.0)) commands: str = self.get_path(flinger, shift_1) path: Path = Path( - d=commands, fill="#000000", stroke="#000000", stroke_width=1.0 + commands, fill="#000000", stroke="#000000", stroke_width=1.0 ) building_shade.add(path) for nodes in self.inners + self.outers: @@ -148,8 +157,9 @@ class Building(Figure): def draw_roof(self, svg: Drawing, flinger: Flinger, scale: float) -> None: """Draw building roof.""" path: Path = Path( - d=self.get_path(flinger, np.array([0.0, -self.height * scale])) + d=self.get_path(flinger, np.array([0.0, -self.height * scale])), + stroke=self.stroke, + fill="none" if self.is_construction else self.fill, + stroke_linejoin="round", ) - path.update(self.line_style.style) - path.update({"stroke-linejoin": "round"}) svg.add(path) diff --git a/map_machine/scheme/default.yml b/map_machine/scheme/default.yml index 6bfaf13..6fc6297 100644 --- a/map_machine/scheme/default.yml +++ b/map_machine/scheme/default.yml @@ -37,8 +37,10 @@ colors: allotments_color: "#D0E0D0" beach_color: "#F0E0C0" boundary_color: "#880088" - building_border_color: "#E0D0C0" # "AAAAAA" - building_color: "#F8F0E8" # "D0D0C0" + building_border_color: "#E0D0C0" + building_color: "#F8F0E8" + building_construction_border_color: "#C4C0BC" + building_construction_color: "#D4D0CC" construction_color: "#CCCCCC" cycle_color: "#4444EE" desert_color: "#F0E0D0"