Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update map_widget.py: pacific cutoff issue #141

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
31 changes: 29 additions & 2 deletions tkintermapview/map_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ def _fit_bounding_box(self, position_top_left: Tuple[float, float], position_bot
def set_position(self, deg_x, deg_y, text=None, marker=False, **kwargs) -> CanvasPositionMarker:
""" set new middle position of map in decimal coordinates """

# Handle wrapping around the 180th meridian
if deg_x > 180:
deg_x -= 360
elif deg_x < -180:
deg_x += 360

# convert given decimal coordinates to OSM coordinates and set corner positions accordingly
current_tile_position = decimal_to_osm(deg_x, deg_y, round(self.zoom))
self.upper_left_tile_pos = (current_tile_position[0] - ((self.width / 2) / self.tile_size),
Expand All @@ -326,7 +332,7 @@ def set_position(self, deg_x, deg_y, text=None, marker=False, **kwargs) -> Canva
# self.draw_move() enough?

return marker_object

def set_address(self, address_string: str, marker: bool = False, text: str = None, **kwargs) -> CanvasPositionMarker:
""" Function uses geocode service of OpenStreetMap (Nominatim).
https://geocoder.readthedocs.io/providers/OpenStreetMap.html """
Expand Down Expand Up @@ -726,6 +732,14 @@ def draw_move(self, called_after_zoom: bool = False):
del self.canvas_tile_array[-1][y]
del self.canvas_tile_array[-1]

# Handle wrapping around the 180th meridian
for row in self.canvas_tile_array:
for tile in row:
if tile.tile_name_position[0] > 2 ** round(self.zoom):
tile.tile_name_position = (tile.tile_name_position[0] - 2 ** round(self.zoom), tile.tile_name_position[1])
elif tile.tile_name_position[0] < 0:
tile.tile_name_position = (tile.tile_name_position[0] + 2 ** round(self.zoom), tile.tile_name_position[1])

# draw all canvas tiles
for x_pos in range(len(self.canvas_tile_array)):
for y_pos in range(len(self.canvas_tile_array[0])):
Expand Down Expand Up @@ -758,6 +772,12 @@ def draw_zoom(self):

tile_name_position = upper_left_x + x_pos, upper_left_y + y_pos

# Handle wrapping around the 180th meridian
if tile_name_position[0] > 2 ** round(self.zoom):
tile_name_position = (tile_name_position[0] - 2 ** round(self.zoom), tile_name_position[1])
elif tile_name_position[0] < 0:
tile_name_position = (tile_name_position[0] + 2 ** round(self.zoom), tile_name_position[1])

image = self.get_tile_image_from_cache(round(self.zoom), *tile_name_position)
if image is False:
image = self.not_loaded_tile_image
Expand All @@ -771,6 +791,7 @@ def draw_zoom(self):

self.draw_move(called_after_zoom=True)


def mouse_move(self, event):
# calculate moving difference from last mouse position
mouse_move_x = self.last_mouse_down_position[0] - event.x
Expand Down Expand Up @@ -917,9 +938,15 @@ def check_map_border_crossing(self):
if self.lower_right_tile_pos[1] > 2 ** round(self.zoom):
diff_y -= self.lower_right_tile_pos[1] - (2 ** round(self.zoom))

# Handle wrapping around the 180th meridian
if self.upper_left_tile_pos[0] > 2 ** round(self.zoom):
self.upper_left_tile_pos = (self.upper_left_tile_pos[0] - 2 ** round(self.zoom), self.upper_left_tile_pos[1])
if self.lower_right_tile_pos[0] < 0:
self.lower_right_tile_pos = (self.lower_right_tile_pos[0] + 2 ** round(self.zoom), self.lower_right_tile_pos[1])

self.upper_left_tile_pos = self.upper_left_tile_pos[0] + diff_x, self.upper_left_tile_pos[1] + diff_y
self.lower_right_tile_pos = self.lower_right_tile_pos[0] + diff_x, self.lower_right_tile_pos[1] + diff_y

def button_zoom_in(self):
# zoom into middle of map
self.set_zoom(self.zoom + 1, relative_pointer_x=0.5, relative_pointer_y=0.5)
Expand Down