Fix road layers.

Draw roads layer by layer.
This commit is contained in:
Sergey Vartanov 2021-09-14 00:13:55 +03:00
parent 748b252d1e
commit 15466cb74c
3 changed files with 28 additions and 10 deletions

View file

@ -245,6 +245,10 @@ class Road(Figure):
except ValueError: except ValueError:
pass pass
self.layer: float = 0
if "layer" in tags:
self.layer = float(tags["layer"])
def draw( def draw(
self, self,
svg: Drawing, svg: Drawing,
@ -259,7 +263,10 @@ class Road(Figure):
width = self.width width = self.width
else: else:
width = self.matcher.default_width width = self.matcher.default_width
if extra_width and self.tags.get("bridge") == "yes": cap: str = "round"
if extra_width:
cap = "butt"
if self.tags.get("bridge") == "yes":
color = Color("#666666") color = Color("#666666")
scale: float = flinger.get_scale(self.outers[0][0].coordinates) scale: float = flinger.get_scale(self.outers[0][0].coordinates)
path_commands: str = self.get_path(flinger) path_commands: str = self.get_path(flinger)
@ -267,7 +274,7 @@ class Road(Figure):
style: dict[str, Any] = { style: dict[str, Any] = {
"fill": "none", "fill": "none",
"stroke": color.hex, "stroke": color.hex,
"stroke-linecap": "round", "stroke-linecap": cap,
"stroke-linejoin": "round", "stroke-linejoin": "round",
"stroke-width": scale * width + extra_width, "stroke-width": scale * width + extra_width,
} }

View file

@ -70,9 +70,14 @@ class Map:
self.svg.add(path) self.svg.add(path)
progress_bar(-1, 0, text="Drawing ways") progress_bar(-1, 0, text="Drawing ways")
roads: Iterator[Road] = sorted( layered_roads: dict[float, list[Road]] = {}
constructor.roads, key=lambda x: x.matcher.priority for road in constructor.roads:
) if road.layer not in layered_roads:
layered_roads[road.layer] = []
layered_roads[road.layer].append(road)
for layer in sorted(layered_roads.keys()):
roads = layered_roads[layer]
for road in roads: for road in roads:
road.draw(self.svg, self.flinger, road.matcher.border_color, 2) road.draw(self.svg, self.flinger, road.matcher.border_color, 2)
for road in roads: for road in roads:

View file

@ -287,6 +287,12 @@ class RoadMatcher(Matcher):
if "priority" in structure: if "priority" in structure:
self.priority = structure["priority"] self.priority = structure["priority"]
def get_priority(self, tags: dict[str, str]) -> float:
layer: float = 0
if "layer" in tags:
layer = float(tags.get("layer"))
return 1000 * layer + self.priority
class Scheme: class Scheme:
""" """