mirror of
https://github.com/enzet/map-machine.git
synced 2025-05-23 14:06:23 +02:00
Issue #10: support priority for icons.
This commit is contained in:
parent
fd70aa8f01
commit
081a6e5455
3 changed files with 27 additions and 13 deletions
|
@ -340,11 +340,15 @@ class Constructor:
|
|||
if (line.get_tag("area") == "yes" or
|
||||
is_cycle(outers[0]) and line.get_tag("area") != "no" and
|
||||
self.scheme.is_area(line.tags)):
|
||||
icon_set: IconSet = self.scheme.get_icon(
|
||||
|
||||
priority: int
|
||||
icon_set: IconSet
|
||||
icon_set, priority = self.scheme.get_icon(
|
||||
self.icon_extractor, line.tags, for_="line")
|
||||
|
||||
self.nodes.append(Point(
|
||||
icon_set, line.tags, center_point, center_coordinates,
|
||||
is_for_node=False))
|
||||
is_for_node=False, priority=priority))
|
||||
|
||||
if not line_styles:
|
||||
if DEBUG:
|
||||
|
@ -353,11 +357,15 @@ class Constructor:
|
|||
"stroke-width": 1}
|
||||
self.figures.append(Figure(
|
||||
line.tags, inners, outers, LineStyle(style, 1000)))
|
||||
icon_set: IconSet = self.scheme.get_icon(
|
||||
|
||||
priority: int
|
||||
icon_set: IconSet
|
||||
icon_set, priority = self.scheme.get_icon(
|
||||
self.icon_extractor, line.tags)
|
||||
|
||||
self.nodes.append(Point(
|
||||
icon_set, line.tags, center_point, center_coordinates,
|
||||
is_for_node=False))
|
||||
is_for_node=False, priority=priority))
|
||||
|
||||
def construct_relations(self) -> None:
|
||||
"""
|
||||
|
@ -410,7 +418,9 @@ class Constructor:
|
|||
if not self.check_level(tags):
|
||||
continue
|
||||
|
||||
icon_set: IconSet = self.scheme.get_icon(self.icon_extractor, tags)
|
||||
priority: int
|
||||
icon_set: IconSet
|
||||
icon_set, priority = self.scheme.get_icon(self.icon_extractor, tags)
|
||||
|
||||
if self.mode in ["time", "user-coloring"]:
|
||||
if not tags:
|
||||
|
@ -421,7 +431,8 @@ class Constructor:
|
|||
if self.mode == "time":
|
||||
icon_set.color = get_time_color(node.timestamp, self.map_.time)
|
||||
|
||||
self.nodes.append(Point(icon_set, tags, flung, node.coordinates))
|
||||
self.nodes.append(Point(
|
||||
icon_set, tags, flung, node.coordinates, priority=priority))
|
||||
|
||||
missing_tags.update(
|
||||
f"{key}: {tags[key]}" for key in tags
|
||||
|
|
|
@ -230,7 +230,7 @@ class Painter:
|
|||
occupied = Occupied(
|
||||
self.flinger.size[0], self.flinger.size[1], self.overlap)
|
||||
|
||||
nodes = sorted(constructor.nodes, key=lambda x: x.layer)
|
||||
nodes = sorted(constructor.nodes, key=lambda x: -x.priority)
|
||||
for index, node in enumerate(nodes): # type: int, Point
|
||||
if (node.get_tag("natural") == "tree" and
|
||||
("diameter_crown" in node.tags or
|
||||
|
|
|
@ -8,7 +8,7 @@ import yaml
|
|||
|
||||
from colour import Color
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Dict, List, Optional, Set, Union
|
||||
from typing import Any, Dict, List, Optional, Set, Union, Tuple
|
||||
|
||||
from roentgen.icon import DEFAULT_SHAPE_ID, IconExtractor, Icon
|
||||
|
||||
|
@ -104,7 +104,7 @@ class Scheme:
|
|||
self.prefix_to_skip: List[str] = content["prefix_to_skip"]
|
||||
|
||||
# Storage for created icon sets.
|
||||
self.cache: Dict[str, IconSet] = {}
|
||||
self.cache: Dict[str, Tuple[IconSet, int]] = {}
|
||||
|
||||
def get_color(self, color: str) -> Color:
|
||||
"""
|
||||
|
@ -156,7 +156,7 @@ class Scheme:
|
|||
|
||||
def get_icon(
|
||||
self, icon_extractor: IconExtractor, tags: Dict[str, Any],
|
||||
for_: str = "node") -> IconSet:
|
||||
for_: str = "node") -> Tuple[IconSet, int]:
|
||||
"""
|
||||
Construct icon set.
|
||||
|
||||
|
@ -172,11 +172,14 @@ class Scheme:
|
|||
extra_icon_ids: List[List[str]] = []
|
||||
processed: Set[str] = set()
|
||||
fill: Color = DEFAULT_COLOR
|
||||
priority: int = 0
|
||||
|
||||
for matcher in self.icons: # type: Dict[str, Any]
|
||||
for index, matcher in enumerate(self.icons):
|
||||
# type: (int, Dict[str, Any])
|
||||
matched: bool = is_matched(matcher, tags)
|
||||
if not matched:
|
||||
continue
|
||||
priority = len(self.icons) - index
|
||||
if "draw" in matcher and not matcher["draw"]:
|
||||
processed |= set(matcher["tags"].keys())
|
||||
if "icon" in matcher:
|
||||
|
@ -229,9 +232,9 @@ class Scheme:
|
|||
returned: IconSet = IconSet(
|
||||
main_icon, extra_icons, fill, processed, is_default)
|
||||
|
||||
self.cache[tags_hash] = returned
|
||||
self.cache[tags_hash] = returned, priority
|
||||
|
||||
return returned
|
||||
return returned, priority
|
||||
|
||||
def get_style(self, tags: Dict[str, Any], scale):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue