mirror of
https://github.com/enzet/map-machine.git
synced 2025-06-05 20:31:51 +02:00
Change scheme initialization.
This commit is contained in:
parent
280fdd9fe0
commit
699c1e9592
11 changed files with 64 additions and 37 deletions
|
@ -20,7 +20,7 @@ from map_machine.workspace import Workspace
|
|||
|
||||
WORKSPACE: Workspace = Workspace(Path("temp"))
|
||||
|
||||
SCHEME: Scheme = Scheme(WORKSPACE.DEFAULT_SCHEME_PATH)
|
||||
SCHEME: Scheme = Scheme.from_file(WORKSPACE.DEFAULT_SCHEME_PATH)
|
||||
EXTRACTOR: ShapeExtractor = ShapeExtractor(
|
||||
WORKSPACE.ICONS_PATH, WORKSPACE.ICONS_CONFIG_PATH
|
||||
)
|
||||
|
|
|
@ -14,7 +14,7 @@ from map_machine.workspace import Workspace
|
|||
|
||||
WORKSPACE: Workspace = Workspace(Path("temp"))
|
||||
|
||||
SCHEME: Scheme = Scheme(WORKSPACE.DEFAULT_SCHEME_PATH)
|
||||
SCHEME: Scheme = Scheme.from_file(WORKSPACE.DEFAULT_SCHEME_PATH)
|
||||
EXTRACTOR: ShapeExtractor = ShapeExtractor(
|
||||
WORKSPACE.ICONS_PATH, WORKSPACE.ICONS_CONFIG_PATH
|
||||
)
|
||||
|
|
|
@ -38,7 +38,7 @@ def draw_element(options: argparse.Namespace) -> None:
|
|||
tag.split("=")[0]: tag.split("=")[1]
|
||||
for tag in tags_description.split(",")
|
||||
}
|
||||
scheme: Scheme = Scheme(workspace.DEFAULT_SCHEME_PATH)
|
||||
scheme: Scheme = Scheme.from_file(workspace.DEFAULT_SCHEME_PATH)
|
||||
extractor: ShapeExtractor = ShapeExtractor(
|
||||
workspace.ICONS_PATH, workspace.ICONS_CONFIG_PATH
|
||||
)
|
||||
|
|
|
@ -60,7 +60,9 @@ def main() -> None:
|
|||
from map_machine.scheme import Scheme
|
||||
from map_machine.doc.taginfo import write_taginfo_project_file
|
||||
|
||||
write_taginfo_project_file(Scheme(workspace.DEFAULT_SCHEME_PATH))
|
||||
write_taginfo_project_file(
|
||||
Scheme.from_file(workspace.DEFAULT_SCHEME_PATH)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -183,7 +183,7 @@ def generate_mapcss(options: argparse.Namespace) -> None:
|
|||
directory: Path = workspace.get_mapcss_path()
|
||||
icons_with_outline_path: Path = workspace.get_mapcss_icons_path()
|
||||
|
||||
scheme: Scheme = Scheme(workspace.DEFAULT_SCHEME_PATH)
|
||||
scheme: Scheme = Scheme.from_file(workspace.DEFAULT_SCHEME_PATH)
|
||||
extractor: ShapeExtractor = ShapeExtractor(
|
||||
workspace.ICONS_PATH, workspace.ICONS_CONFIG_PATH
|
||||
)
|
||||
|
|
|
@ -221,7 +221,7 @@ def render_map(arguments: argparse.Namespace) -> None:
|
|||
logging.fatal(error.message)
|
||||
sys.exit(1)
|
||||
|
||||
scheme: Scheme = Scheme(workspace.DEFAULT_SCHEME_PATH)
|
||||
scheme: Scheme = Scheme.from_file(workspace.DEFAULT_SCHEME_PATH)
|
||||
osm_data: OSMData
|
||||
|
||||
osm_data: OSMData = OSMData()
|
||||
|
|
|
@ -205,7 +205,7 @@ def draw_icons() -> None:
|
|||
Draw all possible icon shapes combinations as grid in one SVG file and as
|
||||
individual SVG files.
|
||||
"""
|
||||
scheme: Scheme = Scheme(workspace.DEFAULT_SCHEME_PATH)
|
||||
scheme: Scheme = Scheme.from_file(workspace.DEFAULT_SCHEME_PATH)
|
||||
extractor: ShapeExtractor = ShapeExtractor(
|
||||
workspace.ICONS_PATH, workspace.ICONS_CONFIG_PATH
|
||||
)
|
||||
|
|
|
@ -310,7 +310,56 @@ class Scheme:
|
|||
Specifies map colors and rules to draw icons for OpenStreetMap tags.
|
||||
"""
|
||||
|
||||
def __init__(self, file_name: Path) -> None:
|
||||
def __init__(self, content: dict[str, Any]) -> None:
|
||||
self.node_matchers: list[NodeMatcher] = []
|
||||
if "node_icons" in content:
|
||||
for group in content["node_icons"]:
|
||||
for element in group["tags"]:
|
||||
self.node_matchers.append(NodeMatcher(element, group))
|
||||
|
||||
self.colors: dict[str, str] = (
|
||||
content["colors"] if "colors" in content else {}
|
||||
)
|
||||
self.material_colors: dict[str, str] = (
|
||||
content["material_colors"] if "material_colors" in content else {}
|
||||
)
|
||||
|
||||
self.way_matchers: list[WayMatcher] = (
|
||||
[WayMatcher(x, self) for x in content["ways"]]
|
||||
if "ways" in content
|
||||
else []
|
||||
)
|
||||
self.road_matchers: list[RoadMatcher] = (
|
||||
[RoadMatcher(x, self) for x in content["roads"]]
|
||||
if "roads" in content
|
||||
else []
|
||||
)
|
||||
self.area_matchers: list[Matcher] = (
|
||||
[Matcher(x) for x in content["area_tags"]]
|
||||
if "area_tags" in content
|
||||
else []
|
||||
)
|
||||
self.keys_to_write: list[str] = (
|
||||
content["keys_to_write"] if "key_to_write" in content else []
|
||||
)
|
||||
self.prefix_to_write: list[str] = (
|
||||
content["prefix_to_write"] if "prefix_to_write" in content else []
|
||||
)
|
||||
self.keys_to_skip: list[str] = (
|
||||
content["keys_to_skip"] if "keys_to_skip" in content else []
|
||||
)
|
||||
self.prefix_to_skip: list[str] = (
|
||||
content["prefix_to_skip"] if "prefix_to_skip" in content else []
|
||||
)
|
||||
self.tags_to_skip: dict[str, str] = (
|
||||
content["tags_to_skip"] if "tags_to_skip" in content else {}
|
||||
)
|
||||
|
||||
# Storage for created icon sets.
|
||||
self.cache: dict[str, tuple[IconSet, int]] = {}
|
||||
|
||||
@classmethod
|
||||
def from_file(cls, file_name: Path) -> "Scheme":
|
||||
"""
|
||||
:param file_name: name of the scheme file with tags, colors, and tag key
|
||||
specification
|
||||
|
@ -319,31 +368,7 @@ class Scheme:
|
|||
content: dict[str, Any] = yaml.load(
|
||||
input_file.read(), Loader=yaml.FullLoader
|
||||
)
|
||||
self.node_matchers: list[NodeMatcher] = []
|
||||
for group in content["node_icons"]:
|
||||
for element in group["tags"]:
|
||||
self.node_matchers.append(NodeMatcher(element, group))
|
||||
|
||||
self.colors: dict[str, str] = content["colors"]
|
||||
self.material_colors: dict[str, str] = content["material_colors"]
|
||||
|
||||
self.way_matchers: list[WayMatcher] = [
|
||||
WayMatcher(x, self) for x in content["ways"]
|
||||
]
|
||||
self.road_matchers: list[RoadMatcher] = [
|
||||
RoadMatcher(x, self) for x in content["roads"]
|
||||
]
|
||||
self.area_matchers: list[Matcher] = [
|
||||
Matcher(x) for x in content["area_tags"]
|
||||
]
|
||||
self.keys_to_write: list[str] = content["keys_to_write"]
|
||||
self.prefix_to_write: list[str] = content["prefix_to_write"]
|
||||
self.keys_to_skip: list[str] = content["keys_to_skip"]
|
||||
self.prefix_to_skip: list[str] = content["prefix_to_skip"]
|
||||
self.tags_to_skip: dict[str, str] = content["tags_to_skip"]
|
||||
|
||||
# Storage for created icon sets.
|
||||
self.cache: dict[str, tuple[IconSet, int]] = {}
|
||||
return cls(content)
|
||||
|
||||
def get_color(self, color: str) -> Color:
|
||||
"""
|
||||
|
|
|
@ -173,7 +173,7 @@ class Tile:
|
|||
icon_extractor: ShapeExtractor = ShapeExtractor(
|
||||
workspace.ICONS_PATH, workspace.ICONS_CONFIG_PATH
|
||||
)
|
||||
scheme: Scheme = Scheme(workspace.DEFAULT_SCHEME_PATH)
|
||||
scheme: Scheme = Scheme.from_file(workspace.DEFAULT_SCHEME_PATH)
|
||||
constructor: Constructor = Constructor(
|
||||
osm_data, flinger, scheme, icon_extractor, configuration
|
||||
)
|
||||
|
@ -390,7 +390,7 @@ class Tiles:
|
|||
extractor: ShapeExtractor = ShapeExtractor(
|
||||
workspace.ICONS_PATH, workspace.ICONS_CONFIG_PATH
|
||||
)
|
||||
scheme: Scheme = Scheme(workspace.DEFAULT_SCHEME_PATH)
|
||||
scheme: Scheme = Scheme.from_file(workspace.DEFAULT_SCHEME_PATH)
|
||||
constructor: Constructor = Constructor(
|
||||
osm_data, flinger, scheme, extractor, configuration
|
||||
)
|
||||
|
|
|
@ -12,7 +12,7 @@ __email__ = "me@enzet.ru"
|
|||
|
||||
workspace: Workspace = Workspace(Path("temp"))
|
||||
|
||||
SCHEME: Scheme = Scheme(workspace.DEFAULT_SCHEME_PATH)
|
||||
SCHEME: Scheme = Scheme.from_file(workspace.DEFAULT_SCHEME_PATH)
|
||||
SHAPE_EXTRACTOR: ShapeExtractor = ShapeExtractor(
|
||||
workspace.ICONS_PATH, workspace.ICONS_CONFIG_PATH
|
||||
)
|
||||
|
|
|
@ -20,7 +20,7 @@ from map_machine.workspace import Workspace
|
|||
|
||||
workspace: Workspace = Workspace(Path("temp"))
|
||||
|
||||
SCHEME: Scheme = Scheme(workspace.DEFAULT_SCHEME_PATH)
|
||||
SCHEME: Scheme = Scheme.from_file(workspace.DEFAULT_SCHEME_PATH)
|
||||
SHAPE_EXTRACTOR: ShapeExtractor = ShapeExtractor(
|
||||
workspace.ICONS_PATH, workspace.ICONS_CONFIG_PATH
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue