Skip to content

Tile Display Issue in TkinterMapView (Offline Maps) #159

Description

@562466

File: map_widget.py
Problem:
When caching offline map tiles, the library uses unsafe key generation by concatenating zoom, x, and y without separators:

# Broken code (map_widget.py)
def get_tile_image_from_cache(self, zoom: int, x: int, y: int):
    if f"{zoom}{x}{y}" not in self.tile_image_cache:  # ← Collision risk!
        return False
    return self.tile_image_cache[f"{zoom}{x}{y}"]

This causes cache collisions for coordinates like (1, 10) → "110" and (11, 0) → "110", rendering wrong tiles in offline mode.

Solution:
Added separators (|) to ensure unique keys:

# Fixed code
def get_tile_image_from_cache(self, zoom: int, x: int, y: int):
    if f"{zoom}|{x}|{y}" not in self.tile_image_cache:
        return False
    return self.tile_image_cache[f"{zoom}|{x}|{y}"]

Why It Works:
Keys now distinguish "1|10" vs "11|0"

Tested with: TkinterMapView 1.29

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions