Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/buildings.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/colors.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/fitness.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/lanes.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/playground.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/power.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/surveillance.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/trees.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/viewpoints.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions map_machine/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
from map_machine.figure import StyledFigure
from map_machine.geometry.coastline import WaterPolygon, _point_in_polygon
from map_machine.geometry.crop import crop_multipolygon, crop_way
from map_machine.map_configuration import DrawingMode, MapConfiguration
from map_machine.map_configuration import (
BuildingMode,
DrawingMode,
MapConfiguration,
RoadMode,
)
from map_machine.osm.osm_reader import (
OSMData,
OSMNode,
Expand All @@ -35,7 +40,6 @@
from map_machine.pictogram.point import Point
from map_machine.scheme import LineStyle, RoadMatcher, Scheme
from map_machine.text import Label, TextConstructor
from map_machine.ui.cli import BuildingMode, RoadMode
from map_machine.util import MinMax

if TYPE_CHECKING:
Expand Down
14 changes: 14 additions & 0 deletions map_machine/doc/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from map_machine.scheme import Scheme
from map_machine.workspace import workspace

logger: logging.Logger = logging.getLogger(__name__)

doc_path: Path = Path("doc")

cache: Path = Path("cache")
Expand Down Expand Up @@ -101,6 +103,7 @@ def main(id_: str | None) -> None:
be drawn.
"""
if REMOVED and (id_ is None or id_ == "fitness"):
logger.info("fitness")
draw_around_point(
np.array((55.75277, 37.40856)),
"fitness",
Expand All @@ -109,13 +112,15 @@ def main(id_: str | None) -> None:
)

if id_ is None or id_ == "power":
logger.info("power")
draw_around_point(
np.array((52.5622, 12.94)),
"power",
configuration=MapConfiguration(SCHEME, zoom_level=15),
)

if REMOVED and (id_ is None or id_ == "playground"):
logger.info("playground")
draw_around_point(
np.array((52.47388, 13.43826)),
"playground",
Expand All @@ -127,6 +132,7 @@ def main(id_: str | None) -> None:
# - Berlin: (52.47604/13.43701), (52.47388/13.43826)*,

if id_ is None or id_ == "surveillance":
logger.info("surveillance")
draw_around_point(
np.array((52.50892, 13.3244)),
"surveillance",
Expand All @@ -138,6 +144,7 @@ def main(id_: str | None) -> None:
)

if id_ is None or id_ == "viewpoints":
logger.info("viewpoints")
draw_around_point(
np.array((52.421, 13.101)),
"viewpoints",
Expand All @@ -150,13 +157,15 @@ def main(id_: str | None) -> None:
)

if id_ is None or id_ == "buildings":
logger.info("buildings")
draw_around_point(
np.array((-26.19049, 28.05605)),
"buildings",
MapConfiguration(SCHEME, building_mode=BuildingMode.ISOMETRIC),
)

if id_ is None or id_ == "trees":
logger.info("trees")
draw_around_point(
np.array((55.751, 37.628)),
"trees",
Expand All @@ -167,6 +176,7 @@ def main(id_: str | None) -> None:
)

if id_ is None or id_ == "time":
logger.info("time")
draw_around_point(
np.array((55.7655, 37.6055)),
"time",
Expand All @@ -179,6 +189,7 @@ def main(id_: str | None) -> None:
)

if id_ is None or id_ == "author":
logger.info("author")
draw_around_point(
np.array((55.7655, 37.6055)),
"author",
Expand All @@ -192,6 +203,7 @@ def main(id_: str | None) -> None:
)

if id_ is None or id_ == "colors":
logger.info("colors")
draw_around_point(
np.array((48.87422, 2.377)),
"colors",
Expand All @@ -204,9 +216,11 @@ def main(id_: str | None) -> None:
)

if id_ is None or id_ == "lanes":
logger.info("lanes")
draw_around_point(np.array((47.61224, -122.33866)), "lanes")

if id_ is None or id_ == "indoor":
logger.info("indoor")
draw_around_point(
np.array((4.5978, -74.07507)),
"indoor",
Expand Down
1 change: 1 addition & 0 deletions map_machine/doc/taginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(self, path: Path, scheme: Scheme) -> None:
ids: list[str] = [
(shape if isinstance(shape, str) else shape["shape"])
for shape in matcher.shapes
if isinstance(shape, str) or "shape" in shape
]
icon_id: str = "___".join(ids)
if value == "*":
Expand Down
20 changes: 10 additions & 10 deletions map_machine/feature/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ def __init__(
self.default_fill: Color
self.default_stroke: Color
if self.is_construction:
self.default_fill = scheme.get_color("building_construction_color")
self.default_fill = scheme.get_color("$building_construction_color")
self.default_stroke = scheme.get_color(
"building_construction_border_color"
"$building_construction_border_color"
)
else:
self.default_fill = scheme.get_color("building_color")
self.default_stroke = scheme.get_color("building_border_color")
self.default_fill = scheme.get_color("$building_color")
self.default_stroke = scheme.get_color("$building_border_color")

self.fill: Color
self.stroke: Color
Expand All @@ -61,8 +61,8 @@ def __init__(
self.stroke = Color(self.fill)
self.stroke.set_luminance(self.fill.get_luminance() * 0.85)
else:
self.fill = scheme.get_color("building_color")
self.stroke = scheme.get_color("building_border_color")
self.fill = scheme.get_color("$building_color")
self.stroke = scheme.get_color("$building_border_color")

self.parts: list[Segment] = []

Expand All @@ -80,15 +80,15 @@ def __init__(
self.wall_default_color: Color
if self.is_construction:
self.wall_default_color = scheme.get_color(
"wall_construction_color"
"$wall_construction_color"
)
else:
self.wall_default_color = scheme.get_color("wall_color")
self.wall_default_color = scheme.get_color("$wall_color")

self.wall_color: Color = self.wall_default_color
material: str | None = tags.get("building:material")
if material and material in scheme.material_colors:
self.wall_color = Color(scheme.material_colors[material])
if material and material in scheme.variables:
self.wall_color = scheme.get_color(f"${material}")
if color := tags.get("building:colour"):
self.wall_color = scheme.get_color(color)
if color := tags.get("colour"):
Expand Down
4 changes: 2 additions & 2 deletions map_machine/feature/direction.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,15 @@ def draw(self, svg: Drawing, scheme: Scheme) -> None:
except (ValueError, TypeError):
pass
direction_radius = 50.0
direction_color = scheme.get_color("direction_camera_color")
direction_color = scheme.get_color("$direction_camera_color")
elif self.get_tag("traffic_sign") == "stop":
direction = self.get_tag("direction")
direction_radius = 25.0
direction_color = Color("red")
else:
direction = self.get_tag("direction")
direction_radius = 50.0
direction_color = scheme.get_color("direction_view_color")
direction_color = scheme.get_color("$direction_view_color")
is_revert_gradient = True

if not direction:
Expand Down
6 changes: 3 additions & 3 deletions map_machine/feature/road.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,11 +592,11 @@ def get_border_color(self) -> Color:
message: str = "Road border color is not set."
raise ValueError(message)
if self.tags.get("bridge") == "yes":
color = self.scheme.get_color("bridge_color")
color = self.scheme.get_color("$bridge_color")
if self.tags.get("ford") == "yes":
color = self.scheme.get_color("ford_color")
color = self.scheme.get_color("$ford_color")
if self.tags.get("embankment") == "yes":
color = self.scheme.get_color("embankment_color")
color = self.scheme.get_color("$embankment_color")
return color

def draw_lanes(self, svg: Drawing, color: Color | None = None) -> None:
Expand Down
6 changes: 4 additions & 2 deletions map_machine/feature/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ def draw(self, svg: Drawing, flinger: Flinger, scheme: Scheme) -> None:
else:
radius = 2.0

color: Color = scheme.get_color("evergreen_color")
color: Color = scheme.get_color("$evergreen_color")
svg.add(svg.circle(self.point, radius * scale, fill=color, opacity=0.3))

if (circumference := self.get_float("circumference")) is not None:
radius = circumference / 2.0 / np.pi
circle = svg.circle(
self.point, radius * scale, fill=scheme.get_color("trunk_color")
self.point,
radius * scale,
fill=scheme.get_color("$trunk_color"),
)
svg.add(circle)
32 changes: 24 additions & 8 deletions map_machine/map_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,41 @@ class MapConfiguration:
def from_options(
cls, scheme: Scheme, options: argparse.Namespace, zoom_level: float
) -> MapConfiguration:
"""Initialize from command-line options."""
"""Initialize from command-line options.

Scheme YAML values are the defaults. CLI options override them
when explicitly provided (i.e. not `None`).
"""

def _resolve(
cli_value: Any, # noqa: ANN401
scheme_value: Any, # noqa: ANN401
enum_cls: type[Enum] | None = None,
) -> Any: # noqa: ANN401
if cli_value is None:
return scheme_value
if enum_cls is not None:
return enum_cls(cli_value)
return cli_value

return cls(
scheme,
DrawingMode(options.mode),
BuildingMode(options.buildings),
RoadMode(options.roads),
LabelMode(options.label_mode),
_resolve(options.mode, scheme.drawing_mode, DrawingMode),
_resolve(options.buildings, scheme.building_mode, BuildingMode),
_resolve(options.roads, scheme.road_mode, RoadMode),
_resolve(options.label_mode, scheme.label_mode, LabelMode),
zoom_level,
options.overlap,
options.level,
options.seed,
options.tooltips,
options.country,
options.ignore_level_matching,
options.roofs,
options.building_colors,
_resolve(options.roofs, scheme.roofs),
_resolve(options.building_colors, scheme.building_colors),
options.show_overlapped,
show_credit=not options.hide_credit,
draw_background=options.background,
draw_background=_resolve(options.background, scheme.background),
crop_ways=options.crop,
crop_margin=options.crop_margin,
)
Expand Down
36 changes: 20 additions & 16 deletions map_machine/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@
)
from map_machine.geometry.flinger import Flinger, MercatorFlinger
from map_machine.geometry.vector import Polyline
from map_machine.map_configuration import LabelMode, MapConfiguration
from map_machine.map_configuration import (
BuildingMode,
LabelMode,
MapConfiguration,
RoadMode,
)
from map_machine.osm.osm_getter import (
NetworkError,
find_incomplete_relations,
Expand All @@ -38,7 +43,6 @@
from map_machine.osm.osm_reader import OSMData, OSMNode
from map_machine.pictogram.point import Occupied, Point
from map_machine.scheme import Scheme
from map_machine.ui.cli import BuildingMode, RoadMode
from map_machine.workspace import workspace

if TYPE_CHECKING:
Expand Down Expand Up @@ -75,7 +79,9 @@ def __init__(
self.scheme: Scheme = configuration.scheme
self.configuration: MapConfiguration = configuration

self.background_color: Color = self.scheme.get_color("background_color")
self.background_color: Color = self.scheme.get_color(
"$background_color"
)
if color := self.configuration.background_color():
self.background_color = color

Expand Down Expand Up @@ -136,27 +142,24 @@ def draw(self, constructor: Constructor) -> None:
path.update(figure.line_style.style)
self.svg.add(path)

if self.scheme.draw_trees:
if self.scheme.trees:
for tree in constructor.trees:
tree.draw(self.svg, self.flinger, self.scheme)

if self.scheme.draw_craters:
if self.scheme.craters:
for crater in constructor.craters:
crater.draw(self.svg, self.flinger)

if self.scheme.draw_buildings:
self.draw_buildings(
constructor,
use_building_colors=self.configuration.use_building_colors,
)
if self.configuration.building_mode != BuildingMode.NO:
self.draw_buildings(constructor)

if self.scheme.draw_directions:
if self.scheme.directions:
for direction_sector in constructor.direction_sectors:
direction_sector.draw(self.svg, self.scheme)

# All other points

if self.scheme.draw_nodes:
if self.scheme.nodes:
occupied: Occupied | None
if self.configuration.overlap == 0:
occupied = None
Expand Down Expand Up @@ -191,12 +194,11 @@ def draw(self, constructor: Constructor) -> None:
if self.configuration.show_credit:
self.draw_credits(constructor.flinger.size)

def draw_buildings(
self, constructor: Constructor, *, use_building_colors: bool
) -> None:
def draw_buildings(self, constructor: Constructor) -> None:
"""Draw buildings: shade, walls, and roof."""
if self.configuration.building_mode == BuildingMode.NO:
return
use_building_colors: bool = self.configuration.use_building_colors
if self.configuration.building_mode == BuildingMode.FLAT:
for building in constructor.buildings:
building.draw(
Expand Down Expand Up @@ -346,7 +348,9 @@ def render_map(arguments: argparse.Namespace) -> None:
fatal(f"Scheme `{arguments.scheme}` not found.")
sys.exit(1)
else:
scheme: Scheme = Scheme.from_file(scheme_path)
scheme: Scheme = Scheme.from_file(
scheme_path, workspace.find_scheme_path
)
if scheme is None:
fatal(f"Failed to load scheme from `{arguments.scheme}`.")
sys.exit(1)
Expand Down
13 changes: 9 additions & 4 deletions map_machine/osm/osm_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,17 @@ def verify(self) -> bool:
"""Check key and value types."""
is_well_formed: bool = True

for value, key in self.tags.items():
for key, value in self.tags.items():
if not isinstance(key, str):
logger.warning("Not string key %s.", key)
logger.warning("Non-string key `%s`.", key)
is_well_formed = False
if not isinstance(value, str):
logger.warning("Not string value %s.", value)
if isinstance(value, list):
for value_element in value:
if not isinstance(value_element, str):
logger.warning("Non-string value `%s`.", value)
is_well_formed = False
elif not isinstance(value, str):
logger.warning("Non-string value `%s`.", value)
is_well_formed = False

return is_well_formed
Expand Down
Loading