Improve projection for desired size
This commit is contained in:
parent
a1e75ed87b
commit
338c6eebee
1 changed files with 7 additions and 13 deletions
14
map.py
14
map.py
|
|
@ -167,20 +167,14 @@ 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.)
|
||||||
# )
|
# )
|
||||||
|
|
||||||
map_width = 0
|
zoom_level = 1 + int(-math.log2(((bounds.maxlon - bounds.minlon) * 2 * math.pi) / map_target_width))
|
||||||
map_height = 0
|
zoom_scale = (2**zoom_level * map_target_width) / (2 * math.pi)
|
||||||
min_x = 0
|
|
||||||
max_y = 0
|
|
||||||
for zoom_level in range(50):
|
|
||||||
zoom_scale = 2**zoom_level / 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)
|
||||||
map_width = max_x - min_x
|
map_width = max_x - min_x
|
||||||
if map_width >= map_target_width:
|
map_height = max_y - min_y
|
||||||
map_height = abs(max_y - min_y)
|
|
||||||
break
|
|
||||||
|
|
||||||
assert map_width > 0 and 0 < map_height < map_width * 3
|
assert map_width > 0 and 0 < map_height < map_width * 10
|
||||||
|
|
||||||
def get_map_coords(lon: float, lat: float) -> tuple[int, int]:
|
def get_map_coords(lon: float, lat: float) -> tuple[int, int]:
|
||||||
nonlocal min_x, max_y
|
nonlocal min_x, max_y
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue