Change scheme initialization.

This commit is contained in:
Sergey Vartanov 2021-12-04 22:21:38 +03:00
parent 280fdd9fe0
commit 699c1e9592
11 changed files with 64 additions and 37 deletions

View file

@ -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
)

View file

@ -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
)

View file

@ -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
)

View file

@ -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__":

View file

@ -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
)

View file

@ -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()

View file

@ -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
)

View file

@ -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:
"""

View file

@ -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
)

View file

@ -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
)

View file

@ -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
)