Minor improvement
This commit is contained in:
parent
338c6eebee
commit
3d717d8e7f
1 changed files with 8 additions and 5 deletions
13
map.py
13
map.py
|
|
@ -156,6 +156,7 @@ def main():
|
|||
zoom_scale: float = 0.
|
||||
|
||||
def get_map_raw_coords(lon: float, lat: float) -> tuple[int, int]:
|
||||
nonlocal zoom_scale
|
||||
return (
|
||||
int(zoom_scale * math.radians(lon)),
|
||||
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.)
|
||||
# )
|
||||
|
||||
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)
|
||||
min_x, min_y = get_map_raw_coords(bounds.minlon, bounds.minlat)
|
||||
max_x, max_y = get_map_raw_coords(bounds.maxlon, bounds.maxlat)
|
||||
|
|
@ -193,9 +194,10 @@ def main():
|
|||
node = nodes[node_id]
|
||||
new_coord = get_map_coords(node.lon, node.lat)
|
||||
# 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)
|
||||
draw.polygon(coords, fill=color, outline=outline, width=width)
|
||||
if len(coords) > 2: # noqa: PLR2004
|
||||
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):
|
||||
nonlocal bounds, draw, map_height, map_width, nodes
|
||||
|
|
@ -204,9 +206,10 @@ def main():
|
|||
node = nodes[node_id]
|
||||
new_coord = get_map_coords(node.lon, node.lat)
|
||||
# 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)
|
||||
draw.line(coords, width=width, fill=color, joint=joint)
|
||||
if len(coords) > 1:
|
||||
draw.line(coords, width=width, fill=color, joint=joint)
|
||||
|
||||
for relation in relations.values():
|
||||
if 'natural' in relation.tags and relation.tags['natural'] == 'wood':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue