Close #105: add style for construction.

This commit is contained in:
Sergey Vartanov 2022-01-23 07:27:09 +03:00
parent f912fa61b2
commit f719fc3577
2 changed files with 28 additions and 16 deletions

View file

@ -1,7 +1,7 @@
""" """
Buildings on the map. Buildings on the map.
""" """
from typing import Any, Optional from typing import Optional
import numpy as np import numpy as np
from colour import Color 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.flinger import Flinger
from map_machine.geometry.vector import Segment from map_machine.geometry.vector import Segment
from map_machine.osm.osm_reader import OSMNode 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_HEIGHT_SCALE: float = 2.5
BUILDING_MINIMAL_HEIGHT: float = 8.0 BUILDING_MINIMAL_HEIGHT: float = 8.0
@ -33,11 +33,17 @@ class Building(Figure):
) -> None: ) -> None:
super().__init__(tags, inners, outers) super().__init__(tags, inners, outers)
style: dict[str, Any] = { self.is_construction: bool = tags.get("building") == "construction"
"fill": scheme.get_color("building_color").hex,
"stroke": scheme.get_color("building_border_color").hex, if self.is_construction:
} self.fill: Color = scheme.get_color("building_construction_color")
self.line_style: LineStyle = LineStyle(style) 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] = [] self.parts: list[Segment] = []
for nodes in self.inners + self.outers: for nodes in self.inners + self.outers:
@ -77,9 +83,12 @@ class Building(Figure):
def draw(self, svg: Drawing, flinger: Flinger) -> None: def draw(self, svg: Drawing, flinger: Flinger) -> None:
"""Draw simple building shape.""" """Draw simple building shape."""
path: Path = Path(d=self.get_path(flinger)) path: Path = Path(
path.update(self.line_style.style) d=self.get_path(flinger),
path.update({"stroke-linejoin": "round"}) stroke=self.stroke,
fill=self.fill,
stroke_linejoin="round",
)
svg.add(path) svg.add(path)
def draw_shade(self, building_shade: Group, flinger: Flinger) -> None: 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)) shift_2: np.ndarray = np.array((scale * self.height, 0.0))
commands: str = self.get_path(flinger, shift_1) commands: str = self.get_path(flinger, shift_1)
path: Path = Path( 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) building_shade.add(path)
for nodes in self.inners + self.outers: 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: def draw_roof(self, svg: Drawing, flinger: Flinger, scale: float) -> None:
"""Draw building roof.""" """Draw building roof."""
path: Path = Path( 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) svg.add(path)

View file

@ -37,8 +37,10 @@ colors:
allotments_color: "#D0E0D0" allotments_color: "#D0E0D0"
beach_color: "#F0E0C0" beach_color: "#F0E0C0"
boundary_color: "#880088" boundary_color: "#880088"
building_border_color: "#E0D0C0" # "AAAAAA" building_border_color: "#E0D0C0"
building_color: "#F8F0E8" # "D0D0C0" building_color: "#F8F0E8"
building_construction_border_color: "#C4C0BC"
building_construction_color: "#D4D0CC"
construction_color: "#CCCCCC" construction_color: "#CCCCCC"
cycle_color: "#4444EE" cycle_color: "#4444EE"
desert_color: "#F0E0D0" desert_color: "#F0E0D0"