mirror of
https://github.com/enzet/map-machine.git
synced 2025-07-15 15:45:47 +02:00
Rename element
command to draw
.
And add node drawing.
This commit is contained in:
parent
6dd9bc27e8
commit
692997f54a
7 changed files with 33 additions and 29 deletions
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 436 KiB After Width: | Height: | Size: 436 KiB |
|
@ -154,7 +154,7 @@ class MapMachineMoire(Default, ABC):
|
||||||
elif command == "map":
|
elif command == "map":
|
||||||
cli.add_map_arguments(parser)
|
cli.add_map_arguments(parser)
|
||||||
elif command == "element":
|
elif command == "element":
|
||||||
cli.add_element_arguments(parser)
|
cli.add_draw_arguments(parser)
|
||||||
elif command == "mapcss":
|
elif command == "mapcss":
|
||||||
cli.add_mapcss_arguments(parser)
|
cli.add_mapcss_arguments(parser)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
import sys
|
import argparse
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from map_machine.element.grid import Grid
|
from map_machine.element.grid import Grid
|
||||||
from map_machine.osm.osm_reader import Tags, OSMNode
|
from map_machine.osm.osm_reader import Tags, OSMNode
|
||||||
|
|
||||||
|
|
||||||
def draw_node():
|
def draw_node(tags: Tags, path: Path):
|
||||||
pass
|
grid: Grid = Grid(x_step=0.0003, show_credit=False, margin=0.5)
|
||||||
|
grid.add_node(tags, 0, 0)
|
||||||
|
grid.draw(path)
|
||||||
|
|
||||||
|
|
||||||
def draw_way():
|
def draw_way():
|
||||||
|
@ -24,13 +26,15 @@ def draw_area(tags: Tags, path: Path):
|
||||||
node,
|
node,
|
||||||
]
|
]
|
||||||
grid.add_way(tags, nodes)
|
grid.add_way(tags, nodes)
|
||||||
|
|
||||||
grid.draw(path)
|
grid.draw(path)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def draw_element(options: argparse.Namespace):
|
||||||
tags: str = sys.argv[1]
|
|
||||||
path: str = sys.argv[2]
|
tags_description: Tags = {
|
||||||
draw_area(
|
x.split("=")[0]: x.split("=")[1] for x in options.tags.split(",")
|
||||||
{x.split("=")[0]: x.split("=")[1] for x in tags.split(",")}, Path(path)
|
}
|
||||||
)
|
if options.type == "area":
|
||||||
|
draw_area(tags_description, Path(options.output_file))
|
||||||
|
elif options.type == "node":
|
||||||
|
draw_node(tags_description, Path(options.output_file))
|
||||||
|
|
|
@ -58,8 +58,8 @@ def main() -> None:
|
||||||
|
|
||||||
mapcss.generate_mapcss(arguments)
|
mapcss.generate_mapcss(arguments)
|
||||||
|
|
||||||
elif arguments.command == "element":
|
elif arguments.command == "draw":
|
||||||
from map_machine.element.node import draw_element
|
from map_machine.element.element import draw_element
|
||||||
|
|
||||||
draw_element(arguments)
|
draw_element(arguments)
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ COMMAND_LINES: dict[str, list[str]] = {
|
||||||
],
|
],
|
||||||
"icons": ["icons"],
|
"icons": ["icons"],
|
||||||
"mapcss": ["mapcss"],
|
"mapcss": ["mapcss"],
|
||||||
"element": ["element", "--node", "amenity=bench,material=wood"],
|
"draw": ["draw", "node", "amenity=bench,material=wood"],
|
||||||
"tile": ["tile", "--coordinates", "50.000,40.000"],
|
"tile": ["tile", "--coordinates", "50.000,40.000"],
|
||||||
}
|
}
|
||||||
COMMANDS: list[str] = [
|
COMMANDS: list[str] = [
|
||||||
|
@ -85,9 +85,9 @@ def parse_arguments(args: list[str]) -> argparse.Namespace:
|
||||||
help="run tile server",
|
help="run tile server",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
add_element_arguments(
|
add_draw_arguments(
|
||||||
subparser.add_parser(
|
subparser.add_parser(
|
||||||
"element",
|
"draw",
|
||||||
description="Draw map element separately.",
|
description="Draw map element separately.",
|
||||||
help="draw OSM element: node, way, relation",
|
help="draw OSM element: node, way, relation",
|
||||||
)
|
)
|
||||||
|
@ -274,11 +274,11 @@ def add_server_arguments(parser: argparse.ArgumentParser) -> None:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def add_element_arguments(parser: argparse.ArgumentParser) -> None:
|
def add_draw_arguments(parser: argparse.ArgumentParser) -> None:
|
||||||
"""Add arguments for element command."""
|
"""Add arguments for element command."""
|
||||||
parser.add_argument("-n", "--node")
|
parser.add_argument("type")
|
||||||
parser.add_argument("-w", "--way")
|
parser.add_argument("tags")
|
||||||
parser.add_argument("-r", "--relation")
|
parser.add_argument("-o", "--output-file", default="out/element.svg")
|
||||||
|
|
||||||
|
|
||||||
def add_render_arguments(parser: argparse.ArgumentParser) -> None:
|
def add_render_arguments(parser: argparse.ArgumentParser) -> None:
|
||||||
|
|
|
@ -68,7 +68,7 @@ def completion_commands() -> str:
|
||||||
cli.add_tile_arguments(parser)
|
cli.add_tile_arguments(parser)
|
||||||
cli.add_map_arguments(parser)
|
cli.add_map_arguments(parser)
|
||||||
elif command == "element":
|
elif command == "element":
|
||||||
cli.add_element_arguments(parser)
|
cli.add_draw_arguments(parser)
|
||||||
elif command == "mapcss":
|
elif command == "mapcss":
|
||||||
cli.add_mapcss_arguments(parser)
|
cli.add_mapcss_arguments(parser)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -111,21 +111,21 @@ def test_mapcss() -> None:
|
||||||
assert (out_path / "icons" / "LICENSE").is_file()
|
assert (out_path / "icons" / "LICENSE").is_file()
|
||||||
|
|
||||||
|
|
||||||
def test_element() -> None:
|
def test_draw() -> None:
|
||||||
"""Test `element` command."""
|
"""Test `draw` command."""
|
||||||
run(
|
run(
|
||||||
COMMAND_LINES["element"],
|
COMMAND_LINES["draw"],
|
||||||
b"INFO Element is written to out/element.svg.\n",
|
LOG + b"INFO Map is drawn to out/element.svg.\n",
|
||||||
)
|
)
|
||||||
assert (OUTPUT_PATH / "element.svg").is_file()
|
assert (OUTPUT_PATH / "element.svg").is_file()
|
||||||
|
|
||||||
|
|
||||||
def test_unwrapped_element() -> None:
|
def test_unwrapped_draw() -> None:
|
||||||
"""Test `element` command from inside the project."""
|
"""Test `element` command from inside the project."""
|
||||||
arguments: argparse.Namespace = parse_arguments(
|
arguments: argparse.Namespace = parse_arguments(
|
||||||
["map_machine"] + COMMAND_LINES["element"]
|
["map_machine"] + COMMAND_LINES["draw"]
|
||||||
)
|
)
|
||||||
from map_machine.element.node import draw_element
|
from map_machine.element.element import draw_element
|
||||||
|
|
||||||
draw_element(arguments)
|
draw_element(arguments)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue