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:
pass
self.layer: float = 0
if "layer" in tags:
self.layer = float(tags["layer"])
def draw(
self,
svg: Drawing,
@ -259,15 +263,18 @@ class Road(Figure):
width = self.width
else:
width = self.matcher.default_width
if extra_width and self.tags.get("bridge") == "yes":
color = Color("#666666")
cap: str = "round"
if extra_width:
cap = "butt"
if self.tags.get("bridge") == "yes":
color = Color("#666666")
scale: float = flinger.get_scale(self.outers[0][0].coordinates)
path_commands: str = self.get_path(flinger)
path: Path = Path(d=path_commands)
style: dict[str, Any] = {
"fill": "none",
"stroke": color.hex,
"stroke-linecap": "round",
"stroke-linecap": cap,
"stroke-linejoin": "round",
"stroke-width": scale * width + extra_width,
}

View file

@ -70,13 +70,18 @@ class Map:
self.svg.add(path)
progress_bar(-1, 0, text="Drawing ways")
roads: Iterator[Road] = sorted(
constructor.roads, key=lambda x: x.matcher.priority
)
for road in roads:
road.draw(self.svg, self.flinger, road.matcher.border_color, 2)
for road in roads:
road.draw(self.svg, self.flinger, road.matcher.color)
layered_roads: dict[float, list[Road]] = {}
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:
road.draw(self.svg, self.flinger, road.matcher.border_color, 2)
for road in roads:
road.draw(self.svg, self.flinger, road.matcher.color)
for tree in constructor.trees:
tree.draw(self.svg, self.flinger, self.scheme)

View file

@ -287,6 +287,12 @@ class RoadMatcher(Matcher):
if "priority" in structure:
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:
"""