mirror of
https://github.com/enzet/map-machine.git
synced 2025-04-29 10:17:23 +02:00
Add --show-tooltips argument.
This commit is contained in:
parent
972e4798b0
commit
52301801cd
7 changed files with 65 additions and 10 deletions
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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="<string>",
|
||||
)
|
||||
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:
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue