From 49177bc2cc6c5b32c20bb0c4dd5e726df6a108da Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Sat, 12 Nov 2016 08:23:32 -0800 Subject: [PATCH] Better map viewport management --- src/MissionEditor/MissionEditor.qml | 189 ++++++++++++++++++++++++---- 1 file changed, 162 insertions(+), 27 deletions(-) diff --git a/src/MissionEditor/MissionEditor.qml b/src/MissionEditor/MissionEditor.qml index 95c1a5600..550cf2461 100644 --- a/src/MissionEditor/MissionEditor.qml +++ b/src/MissionEditor/MissionEditor.qml @@ -86,31 +86,114 @@ QGCView { return lon + 180.0 } - /// Fix the map viewport to the current mission items. - function fitViewportToMissionItems() { - if (_visualItems.count == 1) { + /// Fits the visible region of the map to inclues all of the specified coordinates. If no coordinates + /// are specified the map will fit to the home position + function fitMapViewportToAllCoordinates(coordList) { + if (coordList.length == 0) { editorMap.center = _visualItems.get(0).coordinate - } else { - var missionItem = _visualItems.get(0) - var north = normalizeLat(missionItem.coordinate.latitude) - var south = north - var east = normalizeLon(missionItem.coordinate.longitude) - var west = east - - for (var i=1; i<_visualItems.count; i++) { - missionItem = _visualItems.get(i) - - if (missionItem.specifiesCoordinate && !missionItem.isStandaloneCoordinate) { - var lat = normalizeLat(missionItem.coordinate.latitude) - var lon = normalizeLon(missionItem.coordinate.longitude) - - north = Math.max(north, lat) - south = Math.min(south, lat) - east = Math.max(east, lon) - west = Math.min(west, lon) - } + return + } + + // Determine the size of the inner portion of the map available for display + var toolbarHeight = qgcView.height - ScreenTools.availableHeight + var rightPanelWidth = _rightPanelWidth + var leftToolWidth = centerMapButton.x + centerMapButton.width + var availableWidth = qgcView.width - rightPanelWidth - leftToolWidth + var availableHeight = qgcView.height - toolbarHeight + + // Create the normalized lat/lon corners for the coordinate bounding rect from the list of coordinates + var north = normalizeLat(coordList[0].latitude) + var south = north + var east = normalizeLon(coordList[0].longitude) + var west = east + for (var i=1; i 2) { + for (var i=0; i