mirror of
https://github.com/enzet/map-machine.git
synced 2025-07-30 14:50:09 +02:00
Issue #63: add options for MapCSS generation.
This commit is contained in:
parent
e5671fcf8f
commit
87facc7299
6 changed files with 114 additions and 65 deletions
|
@ -1,42 +0,0 @@
|
||||||
/*
|
|
||||||
Map paint style that adds icons from Röntgen icon set
|
|
||||||
*/
|
|
||||||
|
|
||||||
meta {
|
|
||||||
title: "Röntgen icons";
|
|
||||||
description: "Icons from Röntgen icon set for JOSM";
|
|
||||||
author: "Sergey Vartanov";
|
|
||||||
version: "0.1";
|
|
||||||
link: "https://github.com/enzet/Roentgen";
|
|
||||||
}
|
|
||||||
|
|
||||||
canvas {
|
|
||||||
fill-color: #FFFFFF;
|
|
||||||
}
|
|
||||||
way {
|
|
||||||
fill-opacity: 1;
|
|
||||||
text-color: black;
|
|
||||||
text-offset-y: -11;
|
|
||||||
}
|
|
||||||
relation {
|
|
||||||
fill-opacity: 1;
|
|
||||||
text-color: black;
|
|
||||||
text-offset-y: -11;
|
|
||||||
}
|
|
||||||
node {
|
|
||||||
symbol-shape: circle;
|
|
||||||
symbol-size: 1;
|
|
||||||
text: auto;
|
|
||||||
text-color: black;
|
|
||||||
text-offset-y: -11;
|
|
||||||
text-anchor-horizontal: center;
|
|
||||||
font-size: 11;
|
|
||||||
}
|
|
||||||
way[building] {
|
|
||||||
fill-color: #D8D0C8;
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
relation[building] {
|
|
||||||
fill-color: #D8D0C8;
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
17
roentgen.py
17
roentgen.py
|
@ -13,7 +13,6 @@ import numpy as np
|
||||||
import svgwrite
|
import svgwrite
|
||||||
|
|
||||||
from roentgen.workspace import workspace
|
from roentgen.workspace import workspace
|
||||||
from roentgen import server, tile
|
|
||||||
from roentgen.constructor import Constructor
|
from roentgen.constructor import Constructor
|
||||||
from roentgen.flinger import Flinger
|
from roentgen.flinger import Flinger
|
||||||
from roentgen.grid import draw_icons
|
from roentgen.grid import draw_icons
|
||||||
|
@ -219,18 +218,28 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
if options.command == "render":
|
if options.command == "render":
|
||||||
main(options)
|
main(options)
|
||||||
|
|
||||||
elif options.command == "tile":
|
elif options.command == "tile":
|
||||||
|
from roentgen import tile
|
||||||
|
|
||||||
tile.ui(options)
|
tile.ui(options)
|
||||||
|
|
||||||
elif options.command == "icons":
|
elif options.command == "icons":
|
||||||
draw_icons()
|
draw_icons()
|
||||||
elif options.command == "mapcss":
|
|
||||||
from roentgen.mapcss import write_mapcss
|
|
||||||
|
|
||||||
write_mapcss()
|
elif options.command == "mapcss":
|
||||||
|
from roentgen import mapcss
|
||||||
|
|
||||||
|
mapcss.ui(options)
|
||||||
|
|
||||||
elif options.command == "element":
|
elif options.command == "element":
|
||||||
draw_element(options)
|
draw_element(options)
|
||||||
|
|
||||||
elif options.command == "server":
|
elif options.command == "server":
|
||||||
|
from roentgen import server
|
||||||
|
|
||||||
server.ui(options)
|
server.ui(options)
|
||||||
|
|
||||||
elif options.command == "taginfo":
|
elif options.command == "taginfo":
|
||||||
from roentgen.taginfo import write_taginfo_project_file
|
from roentgen.taginfo import write_taginfo_project_file
|
||||||
|
|
||||||
|
|
|
@ -16,16 +16,68 @@ from roentgen.scheme import Scheme, Matcher
|
||||||
__author__ = "Sergey Vartanov"
|
__author__ = "Sergey Vartanov"
|
||||||
__email__ = "me@enzet.ru"
|
__email__ = "me@enzet.ru"
|
||||||
|
|
||||||
|
NODE_CONFIG: str = """
|
||||||
|
node {
|
||||||
|
symbol-shape: circle;
|
||||||
|
symbol-size: 1;
|
||||||
|
text: auto;
|
||||||
|
text-color: black;
|
||||||
|
text-offset-y: -11;
|
||||||
|
text-anchor-horizontal: center;
|
||||||
|
font-size: 11;
|
||||||
|
}"""
|
||||||
|
|
||||||
|
WAY_CONFIG: str = """
|
||||||
|
canvas {
|
||||||
|
fill-color: #FFFFFF;
|
||||||
|
}
|
||||||
|
way {
|
||||||
|
fill-opacity: 1;
|
||||||
|
text-color: black;
|
||||||
|
text-offset-y: -11;
|
||||||
|
}
|
||||||
|
relation {
|
||||||
|
fill-opacity: 1;
|
||||||
|
text-color: black;
|
||||||
|
text-offset-y: -11;
|
||||||
|
}
|
||||||
|
way[building] {
|
||||||
|
fill-color: #D8D0C8;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
relation[building] {
|
||||||
|
fill-color: #D8D0C8;
|
||||||
|
opacity: 1;
|
||||||
|
}"""
|
||||||
|
|
||||||
|
HEADER: str = """
|
||||||
|
/*
|
||||||
|
Map paint style that adds icons from Röntgen icon set
|
||||||
|
*/
|
||||||
|
|
||||||
|
meta {
|
||||||
|
title: "Röntgen icons";
|
||||||
|
description: "Icons from Röntgen icon set for JOSM";
|
||||||
|
author: "Sergey Vartanov";
|
||||||
|
version: "0.1";
|
||||||
|
link: "https://github.com/enzet/Roentgen";
|
||||||
|
}"""
|
||||||
|
|
||||||
|
|
||||||
class MapCSSWriter:
|
class MapCSSWriter:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
scheme: Scheme,
|
scheme: Scheme,
|
||||||
icon_directory_name: str,
|
icon_directory_name: str,
|
||||||
add_icons_for_lifecycle: bool,
|
add_icons: bool = True,
|
||||||
|
add_ways: bool = True,
|
||||||
|
add_icons_for_lifecycle: bool = True,
|
||||||
):
|
):
|
||||||
self.add_icons_for_lifecycle = add_icons_for_lifecycle
|
self.add_icons: bool = add_icons
|
||||||
self.icon_directory_name = icon_directory_name
|
self.add_ways: bool = add_ways
|
||||||
|
self.add_icons_for_lifecycle: bool = add_icons_for_lifecycle
|
||||||
|
self.icon_directory_name: str = icon_directory_name
|
||||||
|
print(self.add_icons, self.add_ways, self.add_icons_for_lifecycle)
|
||||||
|
|
||||||
self.point_matchers: List[Matcher] = scheme.node_matchers
|
self.point_matchers: List[Matcher] = scheme.node_matchers
|
||||||
self.line_matchers: List[Matcher] = scheme.way_matchers
|
self.line_matchers: List[Matcher] = scheme.way_matchers
|
||||||
|
@ -78,18 +130,23 @@ class MapCSSWriter:
|
||||||
"""
|
"""
|
||||||
Construct icon selectors for MapCSS 0.2 scheme.
|
Construct icon selectors for MapCSS 0.2 scheme.
|
||||||
"""
|
"""
|
||||||
with workspace.MAPCSS_PART_FILE_PATH.open() as input_file:
|
output_file.write(HEADER + "\n\n")
|
||||||
output_file.write(input_file.read())
|
|
||||||
|
|
||||||
output_file.write("\n")
|
if self.add_ways:
|
||||||
|
output_file.write(WAY_CONFIG + "\n\n")
|
||||||
|
|
||||||
for line_matcher in self.line_matchers:
|
if self.add_icons:
|
||||||
for target in ["way", "relation"]:
|
output_file.write(NODE_CONFIG + "\n\n")
|
||||||
output_file.write(self.add_selector(target, line_matcher))
|
|
||||||
|
|
||||||
for matcher in self.point_matchers:
|
if self.add_icons:
|
||||||
for target in ["node", "area"]:
|
for matcher in self.point_matchers:
|
||||||
output_file.write(self.add_selector(target, matcher))
|
for target in ["node", "area"]:
|
||||||
|
output_file.write(self.add_selector(target, matcher))
|
||||||
|
|
||||||
|
if self.add_ways:
|
||||||
|
for line_matcher in self.line_matchers:
|
||||||
|
for target in ["way", "relation"]:
|
||||||
|
output_file.write(self.add_selector(target, line_matcher))
|
||||||
|
|
||||||
if not self.add_icons_for_lifecycle:
|
if not self.add_icons_for_lifecycle:
|
||||||
return
|
return
|
||||||
|
@ -107,7 +164,7 @@ class MapCSSWriter:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def write_mapcss() -> None:
|
def ui(options) -> None:
|
||||||
"""
|
"""
|
||||||
Write MapCSS 0.2 scheme.
|
Write MapCSS 0.2 scheme.
|
||||||
"""
|
"""
|
||||||
|
@ -123,7 +180,11 @@ def write_mapcss() -> None:
|
||||||
icons_with_outline_path, color=Color("black"), outline=True
|
icons_with_outline_path, color=Color("black"), outline=True
|
||||||
)
|
)
|
||||||
mapcss_writer: MapCSSWriter = MapCSSWriter(
|
mapcss_writer: MapCSSWriter = MapCSSWriter(
|
||||||
scheme, workspace.MAPCSS_ICONS_DIRECTORY_NAME, True
|
scheme,
|
||||||
|
workspace.MAPCSS_ICONS_DIRECTORY_NAME,
|
||||||
|
options.icons,
|
||||||
|
options.ways,
|
||||||
|
options.lifecycle,
|
||||||
)
|
)
|
||||||
with workspace.get_mapcss_file_path().open("w+") as output_file:
|
with workspace.get_mapcss_file_path().open("w+") as output_file:
|
||||||
mapcss_writer.write(output_file)
|
mapcss_writer.write(output_file)
|
||||||
|
|
|
@ -31,7 +31,7 @@ def parse_options(args) -> argparse.Namespace:
|
||||||
|
|
||||||
render = subparser.add_parser("render")
|
render = subparser.add_parser("render")
|
||||||
subparser.add_parser("icons")
|
subparser.add_parser("icons")
|
||||||
subparser.add_parser("mapcss")
|
mapcss = subparser.add_parser("mapcss")
|
||||||
subparser.add_parser("taginfo")
|
subparser.add_parser("taginfo")
|
||||||
tile = subparser.add_parser("tile")
|
tile = subparser.add_parser("tile")
|
||||||
element = subparser.add_parser("element")
|
element = subparser.add_parser("element")
|
||||||
|
@ -41,6 +41,7 @@ def parse_options(args) -> argparse.Namespace:
|
||||||
add_tile_arguments(tile)
|
add_tile_arguments(tile)
|
||||||
add_server_arguments(server)
|
add_server_arguments(server)
|
||||||
add_element_arguments(element)
|
add_element_arguments(element)
|
||||||
|
add_mapcss_arguments(mapcss)
|
||||||
|
|
||||||
arguments: argparse.Namespace = parser.parse_args(args[1:])
|
arguments: argparse.Namespace = parser.parse_args(args[1:])
|
||||||
|
|
||||||
|
@ -171,6 +172,27 @@ def add_render_arguments(render) -> None:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def add_mapcss_arguments(mapcss) -> None:
|
||||||
|
mapcss.add_argument(
|
||||||
|
"--icons",
|
||||||
|
action=argparse.BooleanOptionalAction,
|
||||||
|
default=True,
|
||||||
|
help="add icons for nodes and areas",
|
||||||
|
)
|
||||||
|
mapcss.add_argument(
|
||||||
|
"--ways",
|
||||||
|
action=argparse.BooleanOptionalAction,
|
||||||
|
default=True,
|
||||||
|
help="add style for ways and relations",
|
||||||
|
)
|
||||||
|
mapcss.add_argument(
|
||||||
|
"--lifecycle",
|
||||||
|
action=argparse.BooleanOptionalAction,
|
||||||
|
default=True,
|
||||||
|
help="add icons for lifecycle tags",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def progress_bar(
|
def progress_bar(
|
||||||
number: int, total: int, length: int = 20, step: int = 1000, text: str = ""
|
number: int, total: int, length: int = 20, step: int = 1000, text: str = ""
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
|
@ -23,7 +23,6 @@ class Workspace:
|
||||||
ICONS_CONFIG_PATH: Path = Path("icons/config.json")
|
ICONS_CONFIG_PATH: Path = Path("icons/config.json")
|
||||||
GITHUB_TEST_PATH: Path = Path(".github/workflows/test.yml")
|
GITHUB_TEST_PATH: Path = Path(".github/workflows/test.yml")
|
||||||
DATA_PATH: Path = Path("data")
|
DATA_PATH: Path = Path("data")
|
||||||
MAPCSS_PART_FILE_PATH: Path = DATA_PATH / "roentgen_icons_part.mapcss"
|
|
||||||
|
|
||||||
# Generated directories and files.
|
# Generated directories and files.
|
||||||
|
|
||||||
|
@ -35,7 +34,7 @@ class Workspace:
|
||||||
|
|
||||||
self._icons_by_id_path: Path = output_path / "icons_by_id"
|
self._icons_by_id_path: Path = output_path / "icons_by_id"
|
||||||
self._icons_by_name_path: Path = output_path / "icons_by_name"
|
self._icons_by_name_path: Path = output_path / "icons_by_name"
|
||||||
self._mapcss_path: Path = output_path / "roentgen_icons_mapcss"
|
self._mapcss_path: Path = output_path / "roentgen_mapcss"
|
||||||
self._tile_path: Path = output_path / "tiles"
|
self._tile_path: Path = output_path / "tiles"
|
||||||
|
|
||||||
def get_icons_by_id_path(self) -> Path:
|
def get_icons_by_id_path(self) -> Path:
|
||||||
|
@ -56,7 +55,7 @@ class Workspace:
|
||||||
|
|
||||||
def get_mapcss_file_path(self) -> Path:
|
def get_mapcss_file_path(self) -> Path:
|
||||||
"""Directory for MapCSS files."""
|
"""Directory for MapCSS files."""
|
||||||
return self.get_mapcss_path() / "roentgen_icons.mapcss"
|
return self.get_mapcss_path() / "roentgen.mapcss"
|
||||||
|
|
||||||
def get_mapcss_icons_path(self) -> Path:
|
def get_mapcss_icons_path(self) -> Path:
|
||||||
"""Directory for icons used by MapCSS file."""
|
"""Directory for icons used by MapCSS file."""
|
||||||
|
|
|
@ -13,7 +13,7 @@ def test_mapcss() -> None:
|
||||||
"""
|
"""
|
||||||
Test MapCSS generation.
|
Test MapCSS generation.
|
||||||
"""
|
"""
|
||||||
writer: MapCSSWriter = MapCSSWriter(SCHEME, "icons", False)
|
writer: MapCSSWriter = MapCSSWriter(SCHEME, "icons")
|
||||||
matcher: NodeMatcher = NodeMatcher(
|
matcher: NodeMatcher = NodeMatcher(
|
||||||
{"tags": {"natural": "tree"}, "shapes": ["tree"]}
|
{"tags": {"natural": "tree"}, "shapes": ["tree"]}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue