diff --git a/src/GUI/gui.py b/src/GUI/gui.py index fd73dbd..8841847 100644 --- a/src/GUI/gui.py +++ b/src/GUI/gui.py @@ -146,7 +146,7 @@ class ToggleSwitch(QWidget): class ControlStationUI(QMainWindow): planning_finished = pyqtSignal(object) - VERSION = '2.7.0' + VERSION = '2.7.1' FONT_SCALE_MIN = 70 FONT_SCALE_MAX = 180 FONT_SCALE_DEFAULT = 100 diff --git a/src/GUI/map_layout.py b/src/GUI/map_layout.py index 72a7915..7485585 100644 --- a/src/GUI/map_layout.py +++ b/src/GUI/map_layout.py @@ -377,6 +377,8 @@ class DroneMap: var clickStartPos = null; var lastManualMapMoveAt = 0; var autoCenteringMap = false; + const autoFollowPanThresholdRatio = 0.25; + var lastAutoFollowPanAt = 0; function markManualMapMove() { if (!autoCenteringMap) { @@ -385,6 +387,42 @@ class DroneMap: } map.on('dragstart drag dragend zoomstart zoomend', markManualMapMove); + + function isOutsideAutoFollowWindow(latlng) { + if (!latlng) { + return false; + } + + var size = map.getSize(); + if (!size || size.x <= 0 || size.y <= 0) { + return false; + } + + var centerPoint = map.latLngToContainerPoint(map.getCenter()); + var targetPoint = map.latLngToContainerPoint(latlng); + var dx = Math.abs(targetPoint.x - centerPoint.x); + var dy = Math.abs(targetPoint.y - centerPoint.y); + + return dx >= size.x * autoFollowPanThresholdRatio || + dy >= size.y * autoFollowPanThresholdRatio; + } + + function autoFollowPanTo(latlng) { + if (!isOutsideAutoFollowWindow(latlng)) { + return; + } + if (Date.now() - lastManualMapMoveAt < 1000) { + return; + } + if (Date.now() - lastAutoFollowPanAt < 250) { + return; + } + + lastAutoFollowPanAt = Date.now(); + autoCenteringMap = true; + map.panTo(latlng, {animate: true}); + setTimeout(() => { autoCenteringMap = false; }, 300); + } // 路徑標記變量 (跟隨模式用) var routePoints = []; @@ -738,13 +776,8 @@ class DroneMap: setInterval(() => { if (focusedId && markers[focusedId]) { - if (Date.now() - lastManualMapMoveAt < 1000) { - return; - } var latlng = markers[focusedId].getLatLng(); - autoCenteringMap = true; - map.panTo(latlng); - setTimeout(() => { autoCenteringMap = false; }, 300); + autoFollowPanTo(latlng); } }, 1000); @@ -760,6 +793,9 @@ class DroneMap: .setLatLng([lat, lon]) .setRotationAngle(heading); idLabels[id].setLatLng([lat, lon]); + if (id === focusedId) { + autoFollowPanTo(markers[id].getLatLng()); + } } else { initTrajectory(id); addTrajectoryPoint(id, lat, lon);