mirror of
https://github.com/enzet/map-machine.git
synced 2025-05-22 13:36:26 +02:00
Issue #45: support width tag for roads.
Compute road width from width=* tag if specified.
This commit is contained in:
parent
3abd2a1769
commit
4b88b64f86
3 changed files with 37 additions and 30 deletions
|
@ -192,6 +192,13 @@ class Road(Figure):
|
|||
super().__init__(tags, inners, outers)
|
||||
self.matcher: RoadMatcher = matcher
|
||||
|
||||
self.width: Optional[float] = None
|
||||
if "width" in tags:
|
||||
try:
|
||||
self.width = float(tags["width"])
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
def line_center(nodes: List[OSMNode], flinger: Flinger) -> np.array:
|
||||
"""
|
||||
|
|
|
@ -11,7 +11,7 @@ from svgwrite.path import Path
|
|||
from svgwrite.shapes import Rect
|
||||
|
||||
from roentgen import ui
|
||||
from roentgen.constructor import Building, Constructor, Segment
|
||||
from roentgen.constructor import Building, Constructor, Segment, Road
|
||||
from roentgen.direction import DirectionSet, Sector
|
||||
from roentgen.flinger import Flinger
|
||||
from roentgen.icon import ShapeExtractor
|
||||
|
@ -78,31 +78,9 @@ class Painter:
|
|||
constructor.roads, key=lambda x: x.matcher.priority
|
||||
)
|
||||
for road in roads:
|
||||
path_commands: str = road.get_path(self.flinger)
|
||||
path = Path(d=path_commands)
|
||||
path.update({
|
||||
"fill": "none",
|
||||
"stroke": road.matcher.border_color.hex,
|
||||
"stroke-linecap": "round",
|
||||
"stroke-linejoin": "round",
|
||||
"stroke-width":
|
||||
road.matcher.default_width
|
||||
* self.flinger.get_scale(road.outers[0][0].coordinates) + 2
|
||||
})
|
||||
self.svg.add(path)
|
||||
self.draw_road(road, road.matcher.border_color, 2)
|
||||
for road in roads:
|
||||
path_commands: str = road.get_path(self.flinger)
|
||||
path = Path(d=path_commands)
|
||||
path.update({
|
||||
"fill": "none",
|
||||
"stroke": road.matcher.color.hex,
|
||||
"stroke-linecap": "round",
|
||||
"stroke-linejoin": "round",
|
||||
"stroke-width":
|
||||
road.matcher.default_width
|
||||
* self.flinger.get_scale(road.outers[0][0].coordinates)
|
||||
})
|
||||
self.svg.add(path)
|
||||
self.draw_road(road, road.matcher.color)
|
||||
|
||||
# Trees
|
||||
|
||||
|
@ -291,6 +269,26 @@ class Painter:
|
|||
|
||||
ui.progress_bar(-1, len(nodes), step=10, text="Drawing nodes")
|
||||
|
||||
def draw_road(
|
||||
self, road: Road, color: Color, extra_width: float = 0
|
||||
) -> None:
|
||||
self.flinger.get_scale()
|
||||
if road.width is not None:
|
||||
width = road.width
|
||||
else:
|
||||
width = road.matcher.default_width
|
||||
scale = self.flinger.get_scale(road.outers[0][0].coordinates)
|
||||
path_commands: str = road.get_path(self.flinger)
|
||||
path = Path(d=path_commands)
|
||||
path.update({
|
||||
"fill": "none",
|
||||
"stroke": color.hex,
|
||||
"stroke-linecap": "round",
|
||||
"stroke-linejoin": "round",
|
||||
"stroke-width": scale * width + extra_width
|
||||
})
|
||||
self.svg.add(path)
|
||||
|
||||
|
||||
def check_level_number(tags: Dict[str, Any], level: float):
|
||||
"""
|
||||
|
|
|
@ -149,14 +149,14 @@ class NodeMatcher(Matcher):
|
|||
|
||||
|
||||
class WayMatcher(Matcher):
|
||||
def __init__(self, structure: Dict[str, Any], colors):
|
||||
def __init__(self, structure: Dict[str, Any], scheme: "Scheme"):
|
||||
super().__init__(structure)
|
||||
self.style: Dict[str, Any] = {"fill": "none"}
|
||||
if "style" in structure:
|
||||
style: Dict[str, Any] = structure["style"]
|
||||
for key in style:
|
||||
if str(style[key]).endswith("_color"):
|
||||
self.style[key] = colors[style[key]]
|
||||
self.style[key] = scheme.get_color(style[key])
|
||||
else:
|
||||
self.style[key] = style[key]
|
||||
self.priority = 0
|
||||
|
@ -165,9 +165,11 @@ class WayMatcher(Matcher):
|
|||
|
||||
|
||||
class RoadMatcher(Matcher):
|
||||
def __init__(self, structure: Dict[str, Any], scheme):
|
||||
def __init__(self, structure: Dict[str, Any], scheme: "Scheme"):
|
||||
super().__init__(structure)
|
||||
self.border_color: Color = Color(scheme.get_color(structure["border_color"]))
|
||||
self.border_color: Color = Color(
|
||||
scheme.get_color(structure["border_color"])
|
||||
)
|
||||
self.color: Color = Color("white")
|
||||
if "color" in structure:
|
||||
self.color = Color(scheme.get_color(structure["color"]))
|
||||
|
@ -200,7 +202,7 @@ class Scheme:
|
|||
self.colors: Dict[str, str] = content["colors"]
|
||||
|
||||
self.way_matchers: List[WayMatcher] = [
|
||||
WayMatcher(x, self.colors) for x in content["ways"]
|
||||
WayMatcher(x, self) for x in content["ways"]
|
||||
]
|
||||
self.road_matchers: List[RoadMatcher] = [
|
||||
RoadMatcher(x, self) for x in content["roads"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue