mirror of
https://github.com/enzet/map-machine.git
synced 2025-05-29 17:06:30 +02:00
Rename text; add voltage and frequency processing.
This commit is contained in:
parent
bbf96a5b33
commit
93b7883f99
2 changed files with 55 additions and 7 deletions
|
@ -5,7 +5,7 @@ import numpy as np
|
|||
import svgwrite
|
||||
from colour import Color
|
||||
|
||||
from roentgen.address import get_address
|
||||
from roentgen.text import get_address, get_text
|
||||
from roentgen.color import is_bright
|
||||
from roentgen.icon import Icon
|
||||
from roentgen.osm_reader import Tagged
|
||||
|
@ -91,6 +91,10 @@ def construct_text(
|
|||
if draw_captions == "main":
|
||||
return texts
|
||||
|
||||
for text in get_text(tags): # type: str
|
||||
if text:
|
||||
texts.append(TextStruct(text))
|
||||
|
||||
if "route_ref" in tags:
|
||||
texts.append(TextStruct(tags["route_ref"].replace(";", " ")))
|
||||
tags.pop("route_ref", None)
|
||||
|
@ -167,8 +171,8 @@ class Point(Tagged):
|
|||
if painted:
|
||||
self.y += 16
|
||||
|
||||
if not self.icon_set.extra_icons or \
|
||||
(self.icon_set.main_icon and not painted):
|
||||
if (not self.icon_set.extra_icons or
|
||||
(self.icon_set.main_icon and not painted)):
|
||||
return
|
||||
|
||||
is_place_for_extra: bool = True
|
||||
|
@ -189,6 +193,7 @@ class Point(Tagged):
|
|||
svg, shape_ids, self.point + np.array((left, self.y)),
|
||||
Color("#888888"), occupied)
|
||||
left += 16
|
||||
if self.icon_set.extra_icons:
|
||||
self.y += 16
|
||||
|
||||
def draw_point_shape(
|
||||
|
@ -260,7 +265,7 @@ class Point(Tagged):
|
|||
|
||||
if occupied:
|
||||
is_occupied: bool = False
|
||||
for i in range(-int(length / 2), int(length/ 2)):
|
||||
for i in range(-int(length / 2), int(length / 2)):
|
||||
if occupied.check((int(point[0] + i), int(point[1] - 4))):
|
||||
is_occupied = True
|
||||
break
|
||||
|
@ -290,4 +295,3 @@ class Point(Tagged):
|
|||
font_family=DEFAULT_FONT, fill=fill.hex))
|
||||
|
||||
self.y += 11
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ def get_address(tags: Dict[str, Any], draw_captions_mode: str) -> List[str]:
|
|||
"""
|
||||
address: List[str] = []
|
||||
|
||||
if draw_captions_mode != "main":
|
||||
if draw_captions_mode == "address":
|
||||
if "addr:postcode" in tags:
|
||||
address.append(tags["addr:postcode"])
|
||||
tags.pop("addr:postcode", None)
|
||||
|
@ -37,3 +37,47 @@ def get_address(tags: Dict[str, Any], draw_captions_mode: str) -> List[str]:
|
|||
tags.pop("addr:housenumber", None)
|
||||
|
||||
return address
|
||||
|
||||
|
||||
def format_voltage(value: str) -> str:
|
||||
"""
|
||||
Format voltage value to more human-readable form.
|
||||
|
||||
:param value: presumably string representation of integer, in Volts
|
||||
"""
|
||||
try:
|
||||
int_value: int = int(value)
|
||||
if int_value % 1000 == 0:
|
||||
return f"{int(int_value / 1000)} kV"
|
||||
return f"{value} V"
|
||||
except ValueError:
|
||||
return value
|
||||
|
||||
|
||||
def format_frequency(value: str) -> str:
|
||||
try:
|
||||
int_value: int = int(value)
|
||||
return f"{value} Hz"
|
||||
except ValueError:
|
||||
return value
|
||||
|
||||
|
||||
def get_text(tags: Dict[str, Any]) -> List[str]:
|
||||
|
||||
texts: List[str] = []
|
||||
|
||||
values: List[str] = []
|
||||
if "voltage:primary" in tags:
|
||||
values.append(tags["voltage:primary"])
|
||||
if "voltage:secondary" in tags:
|
||||
values.append(tags["voltage:secondary"])
|
||||
if "voltage" in tags:
|
||||
values = tags["voltage"].split(";")
|
||||
texts.append(", ".join(map(format_voltage, values)))
|
||||
|
||||
if "frequency" in tags:
|
||||
texts.append(", ".join(map(
|
||||
format_frequency, tags["frequency"].split(";"))))
|
||||
|
||||
return texts
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue