Fixed tiling bug and multi map bug
This commit is contained in:
@@ -4,13 +4,17 @@ from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from math import isfinite
|
||||
from threading import RLock
|
||||
from typing import Any
|
||||
|
||||
from .commands import CommandKind, MapCommand
|
||||
from .projection import latlon_to_world, screen_to_world, world_to_latlon
|
||||
from .sizing import effective_draw_size
|
||||
from .state import DirtyFlags, MapState, mark_dirty
|
||||
from .types import LatLon, Point
|
||||
from .types import LatLon, Point, Tag
|
||||
|
||||
_drag_owner_lock = RLock()
|
||||
_drag_owner_map: Tag | None = None
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
@@ -152,6 +156,12 @@ def handle_mouse_down(state: MapState, mouse_pos: tuple[float, float], hit_rect:
|
||||
state.interaction.active_drag = False
|
||||
state.interaction.last_mouse_position = None
|
||||
return
|
||||
with _drag_owner_lock:
|
||||
global _drag_owner_map
|
||||
if _drag_owner_map is not None and _drag_owner_map != state.tag:
|
||||
return
|
||||
_drag_owner_map = state.tag
|
||||
with state.lock:
|
||||
state.interaction.active_drag = True
|
||||
state.interaction.last_mouse_position = mouse_pos
|
||||
|
||||
@@ -159,6 +169,9 @@ def handle_mouse_down(state: MapState, mouse_pos: tuple[float, float], hit_rect:
|
||||
def handle_mouse_drag(state: MapState, mouse_pos: tuple[float, float]) -> None:
|
||||
"""Update center from a mouse drag event."""
|
||||
|
||||
with _drag_owner_lock:
|
||||
if _drag_owner_map != state.tag:
|
||||
return
|
||||
with state.lock:
|
||||
if not state.interaction.active_drag:
|
||||
return
|
||||
@@ -172,6 +185,10 @@ def handle_mouse_drag(state: MapState, mouse_pos: tuple[float, float]) -> None:
|
||||
def handle_mouse_release(state: MapState) -> None:
|
||||
"""End any active drag."""
|
||||
|
||||
with _drag_owner_lock:
|
||||
global _drag_owner_map
|
||||
if _drag_owner_map == state.tag:
|
||||
_drag_owner_map = None
|
||||
with state.lock:
|
||||
state.interaction.active_drag = False
|
||||
state.interaction.last_mouse_position = None
|
||||
@@ -186,6 +203,9 @@ def handle_mouse_wheel(
|
||||
) -> None:
|
||||
"""Apply wheel zoom when the cursor is over the concrete map rectangle."""
|
||||
|
||||
with state.lock:
|
||||
if not state.is_visible:
|
||||
return
|
||||
if not hit_rect.contains(mouse_pos[0], mouse_pos[1]):
|
||||
return
|
||||
zoom_state_at_screen_point(
|
||||
@@ -202,6 +222,7 @@ def update_drag_from_button_state(
|
||||
mouse_pos: tuple[float, float],
|
||||
hit_rect: HitRect,
|
||||
is_down: bool,
|
||||
can_start: bool = True,
|
||||
) -> None:
|
||||
"""Poll left-button state and keep drag interaction moving."""
|
||||
|
||||
@@ -217,6 +238,9 @@ def update_drag_from_button_state(
|
||||
handle_mouse_drag(state, mouse_pos)
|
||||
return
|
||||
|
||||
if not can_start:
|
||||
return
|
||||
|
||||
if hit_rect.contains(mouse_pos[0], mouse_pos[1]):
|
||||
handle_mouse_down(state, mouse_pos, hit_rect)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user