mirror of
https://github.com/enzet/map-machine.git
synced 2025-05-02 19:56:39 +02:00
parent
a082722b6d
commit
6e38ca5aa8
5 changed files with 38 additions and 41 deletions
|
@ -39,7 +39,7 @@ from map_machine.pictogram.icon import (
|
||||||
)
|
)
|
||||||
from map_machine.pictogram.point import Point
|
from map_machine.pictogram.point import Point
|
||||||
from map_machine.scheme import LineStyle, RoadMatcher, Scheme
|
from map_machine.scheme import LineStyle, RoadMatcher, Scheme
|
||||||
from map_machine.text import Label
|
from map_machine.text import Label, TextConstructor
|
||||||
from map_machine.ui.cli import BuildingMode
|
from map_machine.ui.cli import BuildingMode
|
||||||
from map_machine.util import MinMax
|
from map_machine.util import MinMax
|
||||||
|
|
||||||
|
@ -171,6 +171,7 @@ class Constructor:
|
||||||
self.scheme: Scheme = scheme
|
self.scheme: Scheme = scheme
|
||||||
self.extractor: ShapeExtractor = extractor
|
self.extractor: ShapeExtractor = extractor
|
||||||
self.configuration: MapConfiguration = configuration
|
self.configuration: MapConfiguration = configuration
|
||||||
|
self.text_constructor: TextConstructor = TextConstructor(self.scheme)
|
||||||
|
|
||||||
if self.configuration.level == "all":
|
if self.configuration.level == "all":
|
||||||
self.check_level = lambda x: True
|
self.check_level = lambda x: True
|
||||||
|
@ -315,8 +316,10 @@ class Constructor:
|
||||||
self.extractor, line.tags, processed, self.configuration
|
self.extractor, line.tags, processed, self.configuration
|
||||||
)
|
)
|
||||||
if icon_set is not None:
|
if icon_set is not None:
|
||||||
labels: list[Label] = self.scheme.construct_text(
|
labels: list[Label] = self.text_constructor.construct_text(
|
||||||
line.tags, processed, self.configuration.label_mode
|
line.tags,
|
||||||
|
processed,
|
||||||
|
self.configuration.label_mode,
|
||||||
)
|
)
|
||||||
point: Point = Point(
|
point: Point = Point(
|
||||||
icon_set,
|
icon_set,
|
||||||
|
@ -355,7 +358,7 @@ class Constructor:
|
||||||
self.extractor, line.tags, processed, self.configuration
|
self.extractor, line.tags, processed, self.configuration
|
||||||
)
|
)
|
||||||
if icon_set is not None:
|
if icon_set is not None:
|
||||||
labels: list[Label] = self.scheme.construct_text(
|
labels: list[Label] = self.text_constructor.construct_text(
|
||||||
line.tags, processed, self.configuration.label_mode
|
line.tags, processed, self.configuration.label_mode
|
||||||
)
|
)
|
||||||
point: Point = Point(
|
point: Point = Point(
|
||||||
|
@ -497,7 +500,7 @@ class Constructor:
|
||||||
if icon_set is None:
|
if icon_set is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
labels: list[Label] = self.scheme.construct_text(
|
labels: list[Label] = self.text_constructor.construct_text(
|
||||||
tags, processed, self.configuration.label_mode
|
tags, processed, self.configuration.label_mode
|
||||||
)
|
)
|
||||||
self.scheme.process_ignored(tags, processed)
|
self.scheme.process_ignored(tags, processed)
|
||||||
|
|
|
@ -13,7 +13,7 @@ from map_machine.map_configuration import LabelMode
|
||||||
from map_machine.pictogram.icon import ShapeExtractor
|
from map_machine.pictogram.icon import ShapeExtractor
|
||||||
from map_machine.pictogram.point import Point
|
from map_machine.pictogram.point import Point
|
||||||
from map_machine.scheme import LineStyle, Scheme
|
from map_machine.scheme import LineStyle, Scheme
|
||||||
from map_machine.text import Label
|
from map_machine.text import Label, TextConstructor
|
||||||
from map_machine.workspace import workspace
|
from map_machine.workspace import workspace
|
||||||
|
|
||||||
__author__ = "Sergey Vartanov"
|
__author__ = "Sergey Vartanov"
|
||||||
|
@ -45,7 +45,10 @@ def draw_element(options: argparse.Namespace) -> None:
|
||||||
processed: set[str] = set()
|
processed: set[str] = set()
|
||||||
icon, _ = scheme.get_icon(extractor, tags, processed)
|
icon, _ = scheme.get_icon(extractor, tags, processed)
|
||||||
is_for_node: bool = target == "node"
|
is_for_node: bool = target == "node"
|
||||||
labels: list[Label] = scheme.construct_text(tags, processed, LabelMode.ALL)
|
text_constructor: TextConstructor = TextConstructor(scheme)
|
||||||
|
labels: list[Label] = text_constructor.construct_text(
|
||||||
|
tags, processed, LabelMode.ALL
|
||||||
|
)
|
||||||
point: Point = Point(
|
point: Point = Point(
|
||||||
icon,
|
icon,
|
||||||
labels,
|
labels,
|
||||||
|
|
|
@ -13,7 +13,7 @@ import yaml
|
||||||
from colour import Color
|
from colour import Color
|
||||||
|
|
||||||
from map_machine.feature.direction import DirectionSet
|
from map_machine.feature.direction import DirectionSet
|
||||||
from map_machine.map_configuration import MapConfiguration, LabelMode
|
from map_machine.map_configuration import MapConfiguration
|
||||||
from map_machine.osm.osm_reader import Tagged, Tags
|
from map_machine.osm.osm_reader import Tagged, Tags
|
||||||
from map_machine.pictogram.icon import (
|
from map_machine.pictogram.icon import (
|
||||||
DEFAULT_SHAPE_ID,
|
DEFAULT_SHAPE_ID,
|
||||||
|
@ -24,7 +24,6 @@ from map_machine.pictogram.icon import (
|
||||||
ShapeSpecification,
|
ShapeSpecification,
|
||||||
DEFAULT_SMALL_SHAPE_ID,
|
DEFAULT_SMALL_SHAPE_ID,
|
||||||
)
|
)
|
||||||
from map_machine.text import Label, TextConstructor
|
|
||||||
|
|
||||||
__author__ = "Sergey Vartanov"
|
__author__ = "Sergey Vartanov"
|
||||||
__email__ = "me@enzet.ru"
|
__email__ = "me@enzet.ru"
|
||||||
|
@ -365,12 +364,6 @@ class Scheme:
|
||||||
# Storage for created icon sets.
|
# Storage for created icon sets.
|
||||||
self.cache: dict[str, tuple[IconSet, int]] = {}
|
self.cache: dict[str, tuple[IconSet, int]] = {}
|
||||||
|
|
||||||
self.text_constructor: TextConstructor = TextConstructor(
|
|
||||||
self.get_color("text_color"),
|
|
||||||
self.get_color("text_main_color"),
|
|
||||||
self.get_color("text_outline_color"),
|
|
||||||
)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_file(cls, file_name: Path) -> "Scheme":
|
def from_file(cls, file_name: Path) -> "Scheme":
|
||||||
"""
|
"""
|
||||||
|
@ -624,25 +617,6 @@ class Scheme:
|
||||||
return matcher
|
return matcher
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def construct_text(
|
|
||||||
self, tags: Tags, processed: set[str], label_mode: LabelMode
|
|
||||||
) -> list[Label]:
|
|
||||||
"""Construct labels for not processed tags."""
|
|
||||||
texts: list[Label] = self.text_constructor.construct_text(
|
|
||||||
tags, processed, label_mode
|
|
||||||
)
|
|
||||||
|
|
||||||
for tag in tags:
|
|
||||||
if self.is_writable(tag, tags[tag]) and tag not in processed:
|
|
||||||
texts.append(
|
|
||||||
Label(
|
|
||||||
tags[tag],
|
|
||||||
self.get_color("text_color"),
|
|
||||||
self.get_color("text_outline_color"),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return texts
|
|
||||||
|
|
||||||
def is_area(self, tags: Tags) -> bool:
|
def is_area(self, tags: Tags) -> bool:
|
||||||
"""Check whether way described by tags is area."""
|
"""Check whether way described by tags is area."""
|
||||||
for matcher in self.area_matchers:
|
for matcher in self.area_matchers:
|
||||||
|
|
|
@ -8,6 +8,7 @@ from colour import Color
|
||||||
|
|
||||||
from map_machine.map_configuration import LabelMode
|
from map_machine.map_configuration import LabelMode
|
||||||
from map_machine.osm.osm_reader import Tags
|
from map_machine.osm.osm_reader import Tags
|
||||||
|
from map_machine.scheme import Scheme
|
||||||
|
|
||||||
__author__ = "Sergey Vartanov"
|
__author__ = "Sergey Vartanov"
|
||||||
__email__ = "me@enzet.ru"
|
__email__ = "me@enzet.ru"
|
||||||
|
@ -72,10 +73,13 @@ def format_frequency(value: str) -> str:
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TextConstructor:
|
class TextConstructor:
|
||||||
|
def __init__(self, scheme: Scheme) -> None:
|
||||||
default_color: Color
|
self.scheme: Scheme = scheme
|
||||||
main_color: Color
|
self.default_color: Color = self.scheme.get_color("text_color")
|
||||||
default_out_color: Color
|
self.main_color: Color = self.scheme.get_color("text_main_color")
|
||||||
|
self.default_out_color: Color = self.scheme.get_color(
|
||||||
|
"text_outline_color"
|
||||||
|
)
|
||||||
|
|
||||||
def label(self, text: str, size: float = DEFAULT_FONT_SIZE):
|
def label(self, text: str, size: float = DEFAULT_FONT_SIZE):
|
||||||
return Label(
|
return Label(
|
||||||
|
@ -114,7 +118,10 @@ class TextConstructor:
|
||||||
return texts
|
return texts
|
||||||
|
|
||||||
def construct_text(
|
def construct_text(
|
||||||
self, tags: Tags, processed: set[str], label_mode: LabelMode
|
self,
|
||||||
|
tags: Tags,
|
||||||
|
processed: set[str],
|
||||||
|
label_mode: LabelMode,
|
||||||
) -> list[Label]:
|
) -> list[Label]:
|
||||||
"""Construct list of labels from OSM tags."""
|
"""Construct list of labels from OSM tags."""
|
||||||
|
|
||||||
|
@ -192,4 +199,13 @@ class TextConstructor:
|
||||||
texts.append(self.label(f"↕ {tags['height']} m"))
|
texts.append(self.label(f"↕ {tags['height']} m"))
|
||||||
processed.add("height")
|
processed.add("height")
|
||||||
|
|
||||||
|
for tag in tags:
|
||||||
|
if self.scheme.is_writable(tag, tags[tag]) and tag not in processed:
|
||||||
|
texts.append(
|
||||||
|
Label(
|
||||||
|
tags[tag],
|
||||||
|
self.default_color,
|
||||||
|
self.default_out_color,
|
||||||
|
)
|
||||||
|
)
|
||||||
return texts
|
return texts
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Test label generation for nodes.
|
Test label generation for nodes.
|
||||||
"""
|
"""
|
||||||
from map_machine.map_configuration import LabelMode
|
from map_machine.map_configuration import LabelMode
|
||||||
from map_machine.text import Label
|
from map_machine.text import Label, TextConstructor
|
||||||
from tests import SCHEME
|
from tests import SCHEME
|
||||||
|
|
||||||
__author__ = "Sergey Vartanov"
|
__author__ = "Sergey Vartanov"
|
||||||
|
@ -12,7 +12,8 @@ __email__ = "me@enzet.ru"
|
||||||
def construct_labels(tags: dict[str, str]) -> list[Label]:
|
def construct_labels(tags: dict[str, str]) -> list[Label]:
|
||||||
"""Construct labels from OSM node tags."""
|
"""Construct labels from OSM node tags."""
|
||||||
processed: set[str] = set()
|
processed: set[str] = set()
|
||||||
return SCHEME.construct_text(tags, processed, LabelMode.ALL)
|
text_constructor: TextConstructor = TextConstructor(SCHEME)
|
||||||
|
return text_constructor.construct_text(tags, processed, LabelMode.ALL)
|
||||||
|
|
||||||
|
|
||||||
def test_1_label() -> None:
|
def test_1_label() -> None:
|
||||||
|
|
Loading…
Add table
Reference in a new issue