diff --git a/map_machine/constructor.py b/map_machine/constructor.py index 0155b16..31f6d9a 100644 --- a/map_machine/constructor.py +++ b/map_machine/constructor.py @@ -292,6 +292,7 @@ class Constructor: center_point, is_for_node=False, priority=priority, + add_tooltips=self.configuration.show_tooltips, ) self.points.append(point) @@ -329,6 +330,7 @@ class Constructor: center_point, is_for_node=False, priority=priority, + add_tooltips=self.configuration.show_tooltips, ) self.points.append(point) @@ -416,7 +418,13 @@ class Constructor: Icon([ShapeSpecification(dot, color)]), [], set() ) point: Point = Point( - icon_set, [], tags, processed, flung, draw_outline=False + icon_set, + [], + tags, + processed, + flung, + draw_outline=False, + add_tooltips=self.configuration.show_tooltips, ) self.points.append(point) return @@ -442,9 +450,15 @@ class Constructor: if "direction" in node.tags or "camera:direction" in node.tags: self.direction_sectors.append(DirectionSector(tags, flung)) point: Point = Point( - icon_set, labels, tags, processed, flung, - priority=priority, draw_outline=draw_outline - ) # fmt: skip + icon_set, + labels, + tags, + processed, + flung, + priority=priority, + draw_outline=draw_outline, + add_tooltips=self.configuration.show_tooltips, + ) self.points.append(point) diff --git a/map_machine/icon.py b/map_machine/icon.py index b15b925..ea6792c 100644 --- a/map_machine/icon.py +++ b/map_machine/icon.py @@ -280,7 +280,8 @@ class ShapeSpecification: :param svg: output SVG file :param point: 2D position of the shape centre - :param tags: tags to be displayed as hint + :param tags: tags to be displayed as a tooltip, if tooltip should not be + displayed, this argument should be None :param outline: draw outline for the shape :param outline_opacity: opacity of the outline """ @@ -355,7 +356,7 @@ class Icon: :param svg: output SVG file :param point: 2D position of the icon centre - :param tags: tags to be displayed as hint + :param tags: tags to be displayed as a tooltip :param outline: draw outline for the icon """ if outline: diff --git a/map_machine/map_configuration.py b/map_machine/map_configuration.py index 0a6a919..8b98474 100644 --- a/map_machine/map_configuration.py +++ b/map_machine/map_configuration.py @@ -52,6 +52,7 @@ class MapConfiguration: overlap: int = 12 level: str = "overground" seed: str = "" + show_tooltips: bool = False @classmethod def from_options( @@ -66,6 +67,7 @@ class MapConfiguration: options.overlap, options.level, options.seed, + options.show_tooltips, ) def is_wireframe(self) -> bool: diff --git a/map_machine/point.py b/map_machine/point.py index 3d5bf24..b72a36d 100644 --- a/map_machine/point.py +++ b/map_machine/point.py @@ -60,6 +60,7 @@ class Point(Tagged): priority: float = 0, is_for_node: bool = True, draw_outline: bool = True, + add_tooltips: bool = False, ) -> None: super().__init__(tags) @@ -73,6 +74,7 @@ class Point(Tagged): self.layer: float = 0 self.is_for_node: bool = is_for_node self.draw_outline: bool = draw_outline + self.add_tooltips: bool = add_tooltips self.y = 0 self.main_icon_painted: bool = False @@ -89,9 +91,12 @@ class Point(Tagged): ): return - position = self.point + np.array((0, self.y)) + position: np.ndarray = self.point + np.array((0, self.y)) + tags: Optional[dict[str, str]] = ( + self.tags if self.add_tooltips else None + ) self.main_icon_painted: bool = self.draw_point_shape( - svg, self.icon_set.main_icon, position, occupied, tags=self.tags + svg, self.icon_set.main_icon, position, occupied, tags=tags ) if self.main_icon_painted: self.y += 16 diff --git a/map_machine/scheme/default.yml b/map_machine/scheme/default.yml index 8a39fcb..39cd32a 100644 --- a/map_machine/scheme/default.yml +++ b/map_machine/scheme/default.yml @@ -1807,12 +1807,12 @@ ways: stroke-width: 1.5 - tags: {waterway: riverbank} style: - fill: none # water_color + fill: water_color stroke: water_border_color stroke-width: 1 - tags: {waterway: ditch} style: - fill: none # water_color + fill: water_color stroke: water_color stroke-width: 2 diff --git a/map_machine/ui.py b/map_machine/ui.py index 3a90676..5d1c1e9 100644 --- a/map_machine/ui.py +++ b/map_machine/ui.py @@ -16,6 +16,12 @@ BOXES_LENGTH: int = len(BOXES) COMMANDS: dict[str, list[str]] = { "render": ["render", "-b", "10.000,20.000,10.001,20.001"], + "render_with_tooltips": [ + "render", + "-b", + "10.000,20.000,10.001,20.001", + "--show-tooltips", + ], "icons": ["icons"], "mapcss": ["mapcss"], "element": ["element", "--node", "amenity=bench,material=wood"], @@ -108,6 +114,12 @@ def add_map_arguments(parser: argparse.ArgumentParser) -> None: help="seed for random", metavar="", ) + parser.add_argument( + "--show-tooltips", + help="add tooltips with tags for icons in SVG files", + action=argparse.BooleanOptionalAction, + default=False, + ) def add_tile_arguments(parser: argparse.ArgumentParser) -> None: diff --git a/tests/test_command_line.py b/tests/test_command_line.py index d180f13..3a32039 100644 --- a/tests/test_command_line.py +++ b/tests/test_command_line.py @@ -46,7 +46,28 @@ def test_render() -> None: with Path("out/map.svg").open() as output_file: root: Element = ElementTree.parse(output_file).getroot() + # 4 expected elements: `defs`, `rect` (background), `g` (outline), + # `g` (icon). assert len(root) == 4 + assert len(root[3][0]) == 0 + assert root.get("width") == "186.0" + assert root.get("height") == "198.0" + + +def test_render_with_tooltips() -> None: + """Test `render` command.""" + run( + COMMANDS["render_with_tooltips"] + ["--cache", "tests/data"], + b"INFO Writing output SVG to out/map.svg...\n", + ) + with Path("out/map.svg").open() as output_file: + root: Element = ElementTree.parse(output_file).getroot() + + # 4 expected elements: `defs`, `rect` (background), `g` (outline), + # `g` (icon). + assert len(root) == 4 + assert len(root[3][0]) == 1 + assert root[3][0][0].text == "natural: tree" assert root.get("width") == "186.0" assert root.get("height") == "198.0"