Issue #107: support parallel offset for ways.

This commit is contained in:
Sergey Vartanov 2022-01-28 07:51:49 +03:00
parent 88dd7f4426
commit a16bf52f55
3 changed files with 49 additions and 6 deletions

View file

@ -292,7 +292,9 @@ class Constructor:
line_style.style
)
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(
StyledFigure(line.tags, inners, outers, line_style)
@ -341,7 +343,7 @@ class Constructor:
"stroke-width": 1.0,
}
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)

View file

@ -66,6 +66,33 @@ class StyledFigure(Figure):
super().__init__(tags, inners, outers)
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:
"""
@ -100,8 +127,13 @@ def make_counter_clockwise(polygon: list[OSMNode]) -> list[OSMNode]:
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."""
return Polyline(
[flinger.fling(node.coordinates) + shift for node in nodes]
).get_path()
).get_path(parallel_offset)

View file

@ -36,6 +36,7 @@ class LineStyle:
"""SVG line style and its priority."""
style: dict[str, Union[int, float, str]]
parallel_offset: float = 0.0
priority: float = 0.0
@ -270,10 +271,15 @@ class WayMatcher(Matcher):
self.style[key] = scheme.get_color(style[key]).hex.upper()
else:
self.style[key] = style[key]
self.priority: int = 0
self.priority: float = 0.0
if "priority" in structure:
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]:
"""Return way SVG style."""
return self.style
@ -584,7 +590,10 @@ class Scheme:
if not matching:
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