mirror of
https://github.com/enzet/map-machine.git
synced 2025-06-11 15:21:54 +02:00
Issue #103: support credits.
This commit is contained in:
parent
2f1769ae0a
commit
9a6f8d2f87
3 changed files with 69 additions and 30 deletions
|
@ -20,6 +20,8 @@ __email__ = "me@enzet.ru"
|
||||||
|
|
||||||
PathCommands = list[Union[float, str, np.ndarray]]
|
PathCommands = list[Union[float, str, np.ndarray]]
|
||||||
|
|
||||||
|
DEFAULT_FONT: str = "Helvetica"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Style:
|
class Style:
|
||||||
|
@ -295,3 +297,30 @@ def parse_path(path: str) -> PathCommands:
|
||||||
index += 1
|
index += 1
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def draw_text(
|
||||||
|
svg: svgwrite.Drawing,
|
||||||
|
text: str,
|
||||||
|
point: np.ndarray,
|
||||||
|
size: float,
|
||||||
|
fill: Color,
|
||||||
|
anchor: str = "middle",
|
||||||
|
stroke_linejoin: str = "round",
|
||||||
|
stroke_width: float = 1.0,
|
||||||
|
stroke: Optional[Color] = None,
|
||||||
|
opacity: float = 1.0,
|
||||||
|
):
|
||||||
|
text_element = svg.text(
|
||||||
|
text,
|
||||||
|
point,
|
||||||
|
font_size=size,
|
||||||
|
text_anchor=anchor,
|
||||||
|
font_family=DEFAULT_FONT,
|
||||||
|
fill=fill.hex,
|
||||||
|
stroke_linejoin=stroke_linejoin,
|
||||||
|
stroke_width=stroke_width,
|
||||||
|
stroke=stroke.hex if stroke else "none",
|
||||||
|
opacity=opacity,
|
||||||
|
)
|
||||||
|
svg.add(text_element)
|
||||||
|
|
|
@ -15,6 +15,7 @@ from svgwrite.path import Path as SVGPath
|
||||||
from svgwrite.shapes import Rect
|
from svgwrite.shapes import Rect
|
||||||
|
|
||||||
from map_machine.constructor import Constructor
|
from map_machine.constructor import Constructor
|
||||||
|
from map_machine.drawing import draw_text
|
||||||
from map_machine.feature.road import Intersection, Road, RoadPart
|
from map_machine.feature.road import Intersection, Road, RoadPart
|
||||||
from map_machine.figure import StyledFigure
|
from map_machine.figure import StyledFigure
|
||||||
from map_machine.geometry.boundary_box import BoundaryBox
|
from map_machine.geometry.boundary_box import BoundaryBox
|
||||||
|
@ -113,6 +114,8 @@ class Map:
|
||||||
self.svg, occupied, self.configuration.label_mode
|
self.svg, occupied, self.configuration.label_mode
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.draw_credits(constructor.flinger.size)
|
||||||
|
|
||||||
def draw_buildings(self, constructor: Constructor) -> None:
|
def draw_buildings(self, constructor: Constructor) -> None:
|
||||||
"""Draw buildings: shade, walls, and roof."""
|
"""Draw buildings: shade, walls, and roof."""
|
||||||
if self.configuration.building_mode == BuildingMode.NO:
|
if self.configuration.building_mode == BuildingMode.NO:
|
||||||
|
@ -172,10 +175,32 @@ class Map:
|
||||||
intersection: Intersection = Intersection(list(parts))
|
intersection: Intersection = Intersection(list(parts))
|
||||||
intersection.draw(self.svg, True)
|
intersection.draw(self.svg, True)
|
||||||
|
|
||||||
|
def draw_credits(self, size: np.ndarray):
|
||||||
|
|
||||||
|
for text, point in (
|
||||||
|
("Rendering: © Map Machine", np.array((15, 27))),
|
||||||
|
("Data: © OpenStreetMap contributors", np.array((15, 15))),
|
||||||
|
):
|
||||||
|
for stroke_width, stroke, opacity in (
|
||||||
|
(3.0, Color("white"), 0.7),
|
||||||
|
(1.0, None, 1.0),
|
||||||
|
):
|
||||||
|
draw_text(
|
||||||
|
self.svg,
|
||||||
|
text,
|
||||||
|
size - point,
|
||||||
|
10,
|
||||||
|
Color("#888888"),
|
||||||
|
anchor="end",
|
||||||
|
stroke_width=stroke_width,
|
||||||
|
stroke=stroke,
|
||||||
|
opacity=opacity,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def render_map(arguments: argparse.Namespace) -> None:
|
def render_map(arguments: argparse.Namespace) -> None:
|
||||||
"""
|
"""
|
||||||
Map Machine entry point.
|
Map rendering entry point.
|
||||||
|
|
||||||
:param arguments: command-line arguments
|
:param arguments: command-line arguments
|
||||||
"""
|
"""
|
||||||
|
@ -257,10 +282,10 @@ def render_map(arguments: argparse.Namespace) -> None:
|
||||||
)
|
)
|
||||||
constructor.construct()
|
constructor.construct()
|
||||||
|
|
||||||
painter: Map = Map(
|
map_: Map = Map(
|
||||||
flinger=flinger, svg=svg, scheme=scheme, configuration=configuration
|
flinger=flinger, svg=svg, scheme=scheme, configuration=configuration
|
||||||
)
|
)
|
||||||
painter.draw(constructor)
|
map_.draw(constructor)
|
||||||
|
|
||||||
logging.info(f"Writing output SVG to {arguments.output_file_name}...")
|
logging.info(f"Writing output SVG to {arguments.output_file_name}...")
|
||||||
with open(arguments.output_file_name, "w", encoding="utf-8") as output_file:
|
with open(arguments.output_file_name, "w", encoding="utf-8") as output_file:
|
||||||
|
|
|
@ -7,6 +7,7 @@ import numpy as np
|
||||||
import svgwrite
|
import svgwrite
|
||||||
from colour import Color
|
from colour import Color
|
||||||
|
|
||||||
|
from map_machine.drawing import draw_text
|
||||||
from map_machine.map_configuration import LabelMode
|
from map_machine.map_configuration import LabelMode
|
||||||
from map_machine.osm.osm_reader import Tagged
|
from map_machine.osm.osm_reader import Tagged
|
||||||
from map_machine.pictogram.icon import Icon, IconSet
|
from map_machine.pictogram.icon import Icon, IconSet
|
||||||
|
@ -15,8 +16,6 @@ from map_machine.text import Label
|
||||||
__author__ = "Sergey Vartanov"
|
__author__ = "Sergey Vartanov"
|
||||||
__email__ = "me@enzet.ru"
|
__email__ = "me@enzet.ru"
|
||||||
|
|
||||||
DEFAULT_FONT: str = "Helvetica"
|
|
||||||
|
|
||||||
|
|
||||||
class Occupied:
|
class Occupied:
|
||||||
"""
|
"""
|
||||||
|
@ -238,42 +237,28 @@ class Point(Tagged):
|
||||||
svg.add(svg.rect((point[0] + i, point[1] + j), (1, 1)))
|
svg.add(svg.rect((point[0] + i, point[1] + j), (1, 1)))
|
||||||
|
|
||||||
if out_fill_2:
|
if out_fill_2:
|
||||||
text_element = svg.text(
|
draw_text(
|
||||||
|
svg,
|
||||||
text,
|
text,
|
||||||
point,
|
point,
|
||||||
font_size=size,
|
size,
|
||||||
text_anchor="middle",
|
fill=out_fill_2,
|
||||||
font_family=DEFAULT_FONT,
|
|
||||||
fill=out_fill_2.hex,
|
|
||||||
stroke_linejoin="round",
|
|
||||||
stroke_width=5.0,
|
stroke_width=5.0,
|
||||||
stroke=out_fill_2.hex,
|
stroke=out_fill_2,
|
||||||
opacity=out_opacity_2,
|
opacity=out_opacity_2,
|
||||||
)
|
)
|
||||||
svg.add(text_element)
|
|
||||||
if out_fill:
|
if out_fill:
|
||||||
text_element = svg.text(
|
draw_text(
|
||||||
|
svg,
|
||||||
text,
|
text,
|
||||||
point,
|
point,
|
||||||
font_size=size,
|
size,
|
||||||
text_anchor="middle",
|
fill,
|
||||||
font_family=DEFAULT_FONT,
|
|
||||||
fill=out_fill.hex,
|
|
||||||
stroke_linejoin="round",
|
|
||||||
stroke_width=3.0,
|
stroke_width=3.0,
|
||||||
stroke=out_fill.hex,
|
stroke=out_fill,
|
||||||
opacity=out_opacity,
|
opacity=out_opacity,
|
||||||
)
|
)
|
||||||
svg.add(text_element)
|
draw_text(svg, text, point, size, fill)
|
||||||
text_element = svg.text(
|
|
||||||
text,
|
|
||||||
point,
|
|
||||||
font_size=size,
|
|
||||||
text_anchor="middle",
|
|
||||||
font_family=DEFAULT_FONT,
|
|
||||||
fill=fill.hex,
|
|
||||||
)
|
|
||||||
svg.add(text_element)
|
|
||||||
|
|
||||||
self.y += 11
|
self.y += 11
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue