Minor improvement
This commit is contained in:
parent
338c6eebee
commit
3d717d8e7f
1 changed files with 8 additions and 5 deletions
9
map.py
9
map.py
|
|
@ -156,6 +156,7 @@ def main():
|
||||||
zoom_scale: float = 0.
|
zoom_scale: float = 0.
|
||||||
|
|
||||||
def get_map_raw_coords(lon: float, lat: float) -> tuple[int, int]:
|
def get_map_raw_coords(lon: float, lat: float) -> tuple[int, int]:
|
||||||
|
nonlocal zoom_scale
|
||||||
return (
|
return (
|
||||||
int(zoom_scale * math.radians(lon)),
|
int(zoom_scale * math.radians(lon)),
|
||||||
int(zoom_scale * math.log(math.tan(math.pi / 4 + math.radians(lat) / 2)))
|
int(zoom_scale * math.log(math.tan(math.pi / 4 + math.radians(lat) / 2)))
|
||||||
|
|
@ -167,7 +168,7 @@ def main():
|
||||||
# math.degrees(2 * math.atan(math.exp(y / zoom_scale)) - math.pi / 2.)
|
# math.degrees(2 * math.atan(math.exp(y / zoom_scale)) - math.pi / 2.)
|
||||||
# )
|
# )
|
||||||
|
|
||||||
zoom_level = 1 + int(-math.log2(((bounds.maxlon - bounds.minlon) * 2 * math.pi) / map_target_width))
|
zoom_level = math.ceil(-math.log2(((bounds.maxlon - bounds.minlon) * 2 * math.pi) / map_target_width))
|
||||||
zoom_scale = (2**zoom_level * map_target_width) / (2 * math.pi)
|
zoom_scale = (2**zoom_level * map_target_width) / (2 * math.pi)
|
||||||
min_x, min_y = get_map_raw_coords(bounds.minlon, bounds.minlat)
|
min_x, min_y = get_map_raw_coords(bounds.minlon, bounds.minlat)
|
||||||
max_x, max_y = get_map_raw_coords(bounds.maxlon, bounds.maxlat)
|
max_x, max_y = get_map_raw_coords(bounds.maxlon, bounds.maxlat)
|
||||||
|
|
@ -193,8 +194,9 @@ def main():
|
||||||
node = nodes[node_id]
|
node = nodes[node_id]
|
||||||
new_coord = get_map_coords(node.lon, node.lat)
|
new_coord = get_map_coords(node.lon, node.lat)
|
||||||
# print(f'{new_coord=}')
|
# print(f'{new_coord=}')
|
||||||
if len(coords) < 2 or new_coord != coords[-1]:
|
if not coords or new_coord != coords[-1]:
|
||||||
coords.append(new_coord)
|
coords.append(new_coord)
|
||||||
|
if len(coords) > 2: # noqa: PLR2004
|
||||||
draw.polygon(coords, fill=color, outline=outline, width=width)
|
draw.polygon(coords, fill=color, outline=outline, width=width)
|
||||||
|
|
||||||
def draw_way_line(way: Way, width: int, color: tuple[int, ...] | str, joint: str | None = None):
|
def draw_way_line(way: Way, width: int, color: tuple[int, ...] | str, joint: str | None = None):
|
||||||
|
|
@ -204,8 +206,9 @@ def main():
|
||||||
node = nodes[node_id]
|
node = nodes[node_id]
|
||||||
new_coord = get_map_coords(node.lon, node.lat)
|
new_coord = get_map_coords(node.lon, node.lat)
|
||||||
# print(f'{new_coord=}')
|
# print(f'{new_coord=}')
|
||||||
if len(coords) < 2 or new_coord != coords[-1]:
|
if not coords or new_coord != coords[-1]:
|
||||||
coords.append(new_coord)
|
coords.append(new_coord)
|
||||||
|
if len(coords) > 1:
|
||||||
draw.line(coords, width=width, fill=color, joint=joint)
|
draw.line(coords, width=width, fill=color, joint=joint)
|
||||||
|
|
||||||
for relation in relations.values():
|
for relation in relations.values():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue