Issue #140: put scheme inside map configuration.

Refactoring of `Scheme` and `MapConfiguration` classes.
This commit is contained in:
Sergey Vartanov 2022-08-15 10:46:25 +03:00
parent 596910fe01
commit c76e1f0301
12 changed files with 114 additions and 70 deletions

View file

@ -11,7 +11,6 @@ import yaml
from colour import Color
from map_machine.feature.direction import DirectionSet
from map_machine.map_configuration import MapConfiguration
from map_machine.osm.osm_reader import Tagged, Tags
from map_machine.pictogram.icon import (
DEFAULT_SHAPE_ID,
@ -134,22 +133,21 @@ class Matcher(Tagged):
)
def is_matched(
self, tags: Tags, configuration: Optional[MapConfiguration] = None
self, tags: Tags, country: Optional[str] = None
) -> tuple[bool, dict[str, str]]:
"""
Check whether element tags matches tag matcher.
:param tags: element tags to be matched
:param configuration: current map configuration to be matched
:param country: country of the element (to match location restrictions
if any)
"""
groups: dict[str, str] = {}
if (
configuration is not None
country is not None
and self.location_restrictions
and not match_location(
self.location_restrictions, configuration.country
)
and not match_location(self.location_restrictions, country)
):
return False, {}
@ -476,7 +474,10 @@ class Scheme:
extractor: ShapeExtractor,
tags: dict[str, Any],
processed: set[str],
configuration: MapConfiguration = MapConfiguration(),
country: Optional[str] = None,
zoom_level: float = 18,
ignore_level_matching: bool = False,
show_overlapped: bool = False,
) -> tuple[Optional[IconSet], int]:
"""
Construct icon set.
@ -484,7 +485,11 @@ class Scheme:
:param extractor: extractor with icon specifications
:param tags: OpenStreetMap element tags dictionary
:param processed: set of already processed tag keys
:param configuration: current map configuration to be matched
:param country: country to match location restrictions
:param zoom_level: current map zoom level
:param ignore_level_matching: do not check level for the icon
:param show_overlapped: get small dot instead of icon if point is
overlapped by some other points
:return (icon set, icon priority)
"""
tags_hash: str = (
@ -501,12 +506,11 @@ class Scheme:
for index, matcher in enumerate(self.node_matchers):
if not matcher.replace_shapes and main_icon:
continue
matching, groups = matcher.is_matched(tags, configuration)
matching, groups = matcher.is_matched(tags, country)
if not matching:
continue
if (
not configuration.ignore_level_matching
and not matcher.check_zoom_level(configuration.zoom_level)
if not ignore_level_matching and not matcher.check_zoom_level(
zoom_level
):
return None, 0
matcher_tags: set[str] = set(matcher.tags.keys())
@ -567,7 +571,7 @@ class Scheme:
main_icon.recolor(color)
default_icon: Optional[Icon] = None
if configuration.show_overlapped:
if show_overlapped:
small_dot_spec: ShapeSpecification = ShapeSpecification(
extractor.get_shape(DEFAULT_SMALL_SHAPE_ID),
color if color else self.get_color("default"),