mirror of
https://github.com/enzet/map-machine.git
synced 2025-06-06 04:41:54 +02:00
Issue #107: support parallel offset for ways.
This commit is contained in:
parent
88dd7f4426
commit
a16bf52f55
3 changed files with 49 additions and 6 deletions
|
@ -292,7 +292,9 @@ class Constructor:
|
||||||
line_style.style
|
line_style.style
|
||||||
)
|
)
|
||||||
new_style["stroke"] = recolor.hex
|
new_style["stroke"] = recolor.hex
|
||||||
line_style = LineStyle(new_style, line_style.priority)
|
line_style = LineStyle(
|
||||||
|
new_style, line_style.parallel_offset, line_style.priority
|
||||||
|
)
|
||||||
|
|
||||||
self.figures.append(
|
self.figures.append(
|
||||||
StyledFigure(line.tags, inners, outers, line_style)
|
StyledFigure(line.tags, inners, outers, line_style)
|
||||||
|
@ -341,7 +343,7 @@ class Constructor:
|
||||||
"stroke-width": 1.0,
|
"stroke-width": 1.0,
|
||||||
}
|
}
|
||||||
figure: StyledFigure = StyledFigure(
|
figure: StyledFigure = StyledFigure(
|
||||||
line.tags, inners, outers, LineStyle(style, 1000.0)
|
line.tags, inners, outers, LineStyle(style, 0.0, 1000.0)
|
||||||
)
|
)
|
||||||
self.figures.append(figure)
|
self.figures.append(figure)
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,33 @@ class StyledFigure(Figure):
|
||||||
super().__init__(tags, inners, outers)
|
super().__init__(tags, inners, outers)
|
||||||
self.line_style: LineStyle = line_style
|
self.line_style: LineStyle = line_style
|
||||||
|
|
||||||
|
def get_path(
|
||||||
|
self,
|
||||||
|
flinger: Flinger,
|
||||||
|
offset: np.ndarray = np.array((0.0, 0.0)),
|
||||||
|
) -> str:
|
||||||
|
"""
|
||||||
|
Get SVG path commands.
|
||||||
|
|
||||||
|
:param flinger: converter for geo coordinates
|
||||||
|
:param offset: offset vector
|
||||||
|
"""
|
||||||
|
path: str = ""
|
||||||
|
|
||||||
|
for outer_nodes in self.outers:
|
||||||
|
commands: str = get_path(
|
||||||
|
outer_nodes, offset, flinger, self.line_style.parallel_offset
|
||||||
|
)
|
||||||
|
path += f"{commands} "
|
||||||
|
|
||||||
|
for inner_nodes in self.inners:
|
||||||
|
commands: str = get_path(
|
||||||
|
inner_nodes, offset, flinger, self.line_style.parallel_offset
|
||||||
|
)
|
||||||
|
path += f"{commands} "
|
||||||
|
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
def is_clockwise(polygon: list[OSMNode]) -> bool:
|
def is_clockwise(polygon: list[OSMNode]) -> bool:
|
||||||
"""
|
"""
|
||||||
|
@ -100,8 +127,13 @@ def make_counter_clockwise(polygon: list[OSMNode]) -> list[OSMNode]:
|
||||||
return polygon if not is_clockwise(polygon) else list(reversed(polygon))
|
return polygon if not is_clockwise(polygon) else list(reversed(polygon))
|
||||||
|
|
||||||
|
|
||||||
def get_path(nodes: list[OSMNode], shift: np.ndarray, flinger: Flinger) -> str:
|
def get_path(
|
||||||
|
nodes: list[OSMNode],
|
||||||
|
shift: np.ndarray,
|
||||||
|
flinger: Flinger,
|
||||||
|
parallel_offset: float = 0.0,
|
||||||
|
) -> str:
|
||||||
"""Construct SVG path commands from nodes."""
|
"""Construct SVG path commands from nodes."""
|
||||||
return Polyline(
|
return Polyline(
|
||||||
[flinger.fling(node.coordinates) + shift for node in nodes]
|
[flinger.fling(node.coordinates) + shift for node in nodes]
|
||||||
).get_path()
|
).get_path(parallel_offset)
|
||||||
|
|
|
@ -36,6 +36,7 @@ class LineStyle:
|
||||||
"""SVG line style and its priority."""
|
"""SVG line style and its priority."""
|
||||||
|
|
||||||
style: dict[str, Union[int, float, str]]
|
style: dict[str, Union[int, float, str]]
|
||||||
|
parallel_offset: float = 0.0
|
||||||
priority: float = 0.0
|
priority: float = 0.0
|
||||||
|
|
||||||
|
|
||||||
|
@ -270,10 +271,15 @@ class WayMatcher(Matcher):
|
||||||
self.style[key] = scheme.get_color(style[key]).hex.upper()
|
self.style[key] = scheme.get_color(style[key]).hex.upper()
|
||||||
else:
|
else:
|
||||||
self.style[key] = style[key]
|
self.style[key] = style[key]
|
||||||
self.priority: int = 0
|
|
||||||
|
self.priority: float = 0.0
|
||||||
if "priority" in structure:
|
if "priority" in structure:
|
||||||
self.priority = structure["priority"]
|
self.priority = structure["priority"]
|
||||||
|
|
||||||
|
self.parallel_offset: float = 0.0
|
||||||
|
if parallel_offset := structure.get("parallel_offset"):
|
||||||
|
self.parallel_offset = parallel_offset
|
||||||
|
|
||||||
def get_style(self) -> dict[str, Any]:
|
def get_style(self) -> dict[str, Any]:
|
||||||
"""Return way SVG style."""
|
"""Return way SVG style."""
|
||||||
return self.style
|
return self.style
|
||||||
|
@ -584,7 +590,10 @@ class Scheme:
|
||||||
if not matching:
|
if not matching:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
line_styles.append(LineStyle(matcher.style, matcher.priority))
|
line_style: LineStyle = LineStyle(
|
||||||
|
matcher.style, matcher.parallel_offset, matcher.priority
|
||||||
|
)
|
||||||
|
line_styles.append(line_style)
|
||||||
|
|
||||||
return line_styles
|
return line_styles
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue