Skip to content

Commit fef8468

Browse files
committed
improve drag behavior
1 parent 1d74407 commit fef8468

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/local_flight_map/ui/app/data.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,9 @@ async def _process_feature(self, feature: Dict[str, Any]) -> Dict[str, Any]:
168168

169169
async with self._semaphore:
170170
try:
171-
icao24 = feature.get("properties", {}).get("icao24_code", "unknown")
172-
callsign = feature.get("properties", {}).get("callsign", "unknown")
171+
properties = feature.get("properties", {}) or {}
172+
icao24 = properties.get("icao24_code", "unknown") or "unknown"
173+
callsign = properties.get("callsign", "unknown") or "unknown"
173174
async with self._hexdb_semaphore:
174175
for result in await asyncio.gather(
175176
self._clients.hexdb_client.get_aircraft_information_from_hexdb(icao24),

src/local_flight_map/ui/app/static/js/30_draggable_bbox.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,28 @@ class DraggableBBox {
547547
}
548548
}
549549

550+
/**
551+
* Check if the bounding box is smaller than the visible map area
552+
* @returns {boolean} True if bbox is smaller than visible area in both dimensions
553+
*/
554+
isBBoxSmallerThanVisibleArea() {
555+
if (!this.rectangle || !this.map) {
556+
return false;
557+
}
558+
559+
const visibleBounds = this.map.getBounds();
560+
const bboxBounds = this.rectangle.getBounds();
561+
562+
// Compare both width and height independently
563+
const visibleHeight = visibleBounds.getNorth() - visibleBounds.getSouth();
564+
const visibleWidth = visibleBounds.getEast() - visibleBounds.getWest();
565+
const bboxHeight = bboxBounds.getNorth() - bboxBounds.getSouth();
566+
const bboxWidth = bboxBounds.getEast() - bboxBounds.getWest();
567+
568+
// Return true only if bbox is smaller in both dimensions
569+
return bboxHeight < visibleHeight && bboxWidth < visibleWidth;
570+
}
571+
550572
/**
551573
* Unified handler for drag start events (mouse and touch)
552574
* @param {L.LeafletMouseEvent|L.LeafletTouchEvent} e - The event
@@ -559,6 +581,12 @@ class DraggableBBox {
559581
}
560582

561583
try {
584+
// Check if bbox is smaller than visible area
585+
if (!this.isBBoxSmallerThanVisibleArea()) {
586+
// Allow event propagation to map if bbox is larger
587+
return;
588+
}
589+
562590
// Prevent event propagation to avoid triggering radar marker events
563591
if (e.originalEvent) {
564592
e.originalEvent.stopPropagation();
@@ -589,7 +617,7 @@ class DraggableBBox {
589617
* @param {L.LeafletMouseEvent|L.LeafletTouchEvent} e - The event
590618
*/
591619
onDragMove(e) {
592-
if (!this.isDragging) {
620+
if (!this.isDragging || !this.isBBoxSmallerThanVisibleArea()) {
593621
return;
594622
}
595623

@@ -637,7 +665,7 @@ class DraggableBBox {
637665
* @param {L.LeafletMouseEvent|L.LeafletTouchEvent} e - The event
638666
*/
639667
onDragEnd(e) {
640-
if (!this.isDragging) {
668+
if (!this.isDragging || !this.isBBoxSmallerThanVisibleArea()) {
641669
return;
642670
}
643671

0 commit comments

Comments
 (0)