diff --git a/map_machine/constructor.py b/map_machine/constructor.py index 59fc77c..c86b57e 100644 --- a/map_machine/constructor.py +++ b/map_machine/constructor.py @@ -525,7 +525,7 @@ class Constructor: def get_sorted_figures(self) -> list[StyledFigure]: """Get all figures sorted by priority.""" - return sorted(self.figures, key=lambda x: x.line_style.priority) + return sorted(self.figures) def check_level_number(tags: Tags, level: float) -> bool: diff --git a/map_machine/figure.py b/map_machine/figure.py index 654b48a..820d32e 100644 --- a/map_machine/figure.py +++ b/map_machine/figure.py @@ -91,6 +91,27 @@ class StyledFigure(Figure): return path + def get_layer(self) -> float: + """ + Get figure layer value or 0 if it is not specified. + + TODO: support values separated by "," or ";". + """ + try: + if "layer" in self.tags: + return float(self.tags["layer"]) + except ValueError: + return 0.0 + return 0.0 + + def __lt__(self, other: "StyledFigure") -> bool: + """Compare figures based on priority and layer.""" + if self.get_layer() != other.get_layer(): + print(self.get_layer() < other.get_layer()) + return self.get_layer() < other.get_layer() + + return self.line_style.priority < other.line_style.priority + def is_clockwise(polygon: list[OSMNode]) -> bool: """