From 2e498a66321ced8fe4126068d26b5056396d31be Mon Sep 17 00:00:00 2001 From: DonLakeFlyer Date: Wed, 29 Mar 2017 11:13:19 -0700 Subject: [PATCH] Various fixes/changes to initial map positions in Fly/Plan --- src/FlightDisplay/FlightDisplayViewMap.qml | 65 +++++++------------- src/FlightMap/FlightMap.qml | 42 +++++++++++-- src/FlightMap/Widgets/CenterMapDropPanel.qml | 4 +- src/FlightMap/Widgets/MapFitFunctions.qml | 5 +- src/PlanView/PlanView.qml | 9 +-- src/QmlControls/QGroundControlQmlGlobal.cc | 9 ++- src/QmlControls/QGroundControlQmlGlobal.h | 2 + 7 files changed, 78 insertions(+), 58 deletions(-) diff --git a/src/FlightDisplay/FlightDisplayViewMap.qml b/src/FlightDisplay/FlightDisplayViewMap.qml index dfb22ad61..ba7c5494d 100644 --- a/src/FlightDisplay/FlightDisplayViewMap.qml +++ b/src/FlightDisplay/FlightDisplayViewMap.qml @@ -24,14 +24,16 @@ import QGroundControl.Vehicle 1.0 import QGroundControl.Controllers 1.0 FlightMap { - id: flightMap - anchors.fill: parent - mapName: _mapName + id: flightMap + anchors.fill: parent + mapName: _mapName + allowGCSLocationCenter: !userPanned + allowVehicleLocationCenter: !_keepVehicleCentered property alias missionController: missionController property var flightWidgets property var rightPanelWidth - property var qgcView ///< QGCView control which contains this map + property var qgcView ///< QGCView control which contains this map property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle property var _activeVehicleCoordinate: _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate() @@ -41,45 +43,16 @@ FlightMap { property bool _disableVehicleTracking: false property bool _keepVehicleCentered: _mainIsMap ? false : true - property bool _firstVehiclePositionReceived: false - property bool _userPanned: false - Component.onCompleted: { - QGroundControl.flightMapPosition = center - QGroundControl.flightMapZoom = zoomLevel - possibleCenterToGCSPosition() - } - // Track last known map position and zoom in settings + // Track last known map position and zoom from Fly view in settings onZoomLevelChanged: QGroundControl.flightMapZoom = zoomLevel onCenterChanged: QGroundControl.flightMapPosition = center - // We move the map to the gcs position id: - // - We don't have a vehicle position yet - // - The user has not futzed with the map - onGcsPositionChanged: possibleCenterToGCSPosition() - - function possibleCenterToGCSPosition() { - if (!_firstVehiclePositionReceived && !_userPanned && gcsPosition.isValid) { - center = gcsPosition - } - } - // When the user pans the map we stop responding to vehicle coordinate updates until the panRecenterTimer fires - Connections { - target: gesture - - onPanFinished: { - _userPanned = true - _disableVehicleTracking = true - panRecenterTimer.start() - } - - onFlickFinished: { - _userPanned = true - _disableVehicleTracking = true - panRecenterTimer.start() - } + onUserPannedChanged: { + _disableVehicleTracking = true + panRecenterTimer.start() } function pointInRect(point, rect) { @@ -118,15 +91,12 @@ FlightMap { } function updateMapToVehiclePosition() { - if (_activeVehicleCoordinate.isValid && !_disableVehicleTracking) { + // We let FlightMap handle first vehicle position + if (firstVehiclePositionReceived && _activeVehicleCoordinate.isValid && !_disableVehicleTracking) { if (_keepVehicleCentered) { - _firstVehiclePositionReceived = true flightMap.center = _activeVehicleCoordinate } else { - if (!_firstVehiclePositionReceived) { - _firstVehiclePositionReceived = true - flightMap.center = _activeVehicleCoordinate - } else if (recenterNeeded()) { + if (firstVehiclePositionReceived) { animatedMapRecenter(flightMap.center, _activeVehicleCoordinate) } } @@ -156,7 +126,15 @@ FlightMap { MissionController { id: missionController + Component.onCompleted: start(false /* editMode */) + + onNewItemsFromVehicle: { + var visualItem = missionController.visualItems + if (visualItems && visualItems.count != 1) { + mapFitFunctions.fitMapViewportToMissionItems() + } + } } GeoFenceController { @@ -263,7 +241,6 @@ FlightMap { MapFitFunctions { id: mapFitFunctions map: _flightMap - mapFitViewport: Qt.rect(leftToolWidth, _toolButtonTopMargin, flightMap.width - leftToolWidth - rightPanelWidth, flightMap.height - _toolButtonTopMargin) usePlannedHomePosition: false mapMissionController: missionController mapGeoFenceController: geoFenceController diff --git a/src/FlightMap/FlightMap.qml b/src/FlightMap/FlightMap.qml index 4b4c290a3..014387b53 100644 --- a/src/FlightMap/FlightMap.qml +++ b/src/FlightMap/FlightMap.qml @@ -30,12 +30,20 @@ Map { gesture.flickDeceleration: 3000 plugin: Plugin { name: "QGroundControl" } - property string mapName: 'defaultMap' - property bool isSatelliteMap: activeMapType.name.indexOf("Satellite") > -1 || activeMapType.name.indexOf("Hybrid") > -1 - property var gcsPosition: QtPositioning.coordinate() + property string mapName: 'defaultMap' + property bool isSatelliteMap: activeMapType.name.indexOf("Satellite") > -1 || activeMapType.name.indexOf("Hybrid") > -1 + property var gcsPosition: QtPositioning.coordinate() + property bool userPanned: false ///< true: the user has manually panned the map + property bool allowGCSLocationCenter: false ///< true: map will center/zoom to gcs location one time + property bool allowVehicleLocationCenter: false ///< true: map will center/zoom to vehicle location one time + property bool firstGCSPositionReceived: false ///< true: first gcs position update was responded to + property bool firstVehiclePositionReceived: false ///< true: first vehicle position update was responded to readonly property real maxZoomLevel: 20 + property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle + property var activeVehicleCoordinate: _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate() + function setVisibleRegion(region) { // This works around a bug on Qt where if you set a visibleRegion and then the user moves or zooms the map // and then you set the same visibleRegion the map will not move/scale appropriately since it thinks there @@ -44,6 +52,14 @@ Map { _map.visibleRegion = region } + function _possiblyCenterToVehiclePosition() { + if (!firstVehiclePositionReceived && allowVehicleLocationCenter && activeVehicleCoordinate.isValid) { + firstVehiclePositionReceived = true + center = activeVehicleCoordinate + zoomLevel = QGroundControl.flightMapInitialZoom + } + } + ExclusiveGroup { id: mapTypeGroup } // Update ground station position @@ -53,10 +69,23 @@ Map { onLastPositionUpdated: { if (valid && lastPosition.latitude && Math.abs(lastPosition.latitude) > 0.001 && lastPosition.longitude && Math.abs(lastPosition.longitude) > 0.001) { gcsPosition = QtPositioning.coordinate(lastPosition.latitude,lastPosition.longitude) + if (!firstGCSPositionReceived && !firstVehiclePositionReceived && allowGCSLocationCenter) { + firstGCSPositionReceived = true + center = gcsPosition + zoomLevel = QGroundControl.flightMapInitialZoom + } } } } + // We track whether the user has panned or not to correctly handle automatic map positioning + Connections { + target: gesture + + onPanFinished: userPanned = true + onFlickFinished: userPanned = true + } + function updateActiveMapType() { var settings = QGroundControl.settingsManager.flightMapSettings var fullMapName = settings.mapProvider.enumStringValue + " " + settings.mapType.enumStringValue @@ -68,7 +97,12 @@ Map { } } - Component.onCompleted: updateActiveMapType() + onActiveVehicleCoordinateChanged: _possiblyCenterToVehiclePosition() + + Component.onCompleted: { + updateActiveMapType() + _possiblyCenterToVehiclePosition() + } Connections { target: QGroundControl.settingsManager.flightMapSettings.mapType diff --git a/src/FlightMap/Widgets/CenterMapDropPanel.qml b/src/FlightMap/Widgets/CenterMapDropPanel.qml index 2868ee5ac..90dd02b3b 100644 --- a/src/FlightMap/Widgets/CenterMapDropPanel.qml +++ b/src/FlightMap/Widgets/CenterMapDropPanel.qml @@ -65,11 +65,11 @@ ColumnLayout { QGCButton { text: qsTr("Current Location") Layout.fillWidth: true - enabled: _map.gcsPosition.isValid + enabled: map.gcsPosition.isValid onClicked: { dropPanel.hide() - map.center = _map.gcsPosition + map.center = map.gcsPosition } } diff --git a/src/FlightMap/Widgets/MapFitFunctions.qml b/src/FlightMap/Widgets/MapFitFunctions.qml index 676df4503..cac5d32e0 100644 --- a/src/FlightMap/Widgets/MapFitFunctions.qml +++ b/src/FlightMap/Widgets/MapFitFunctions.qml @@ -15,7 +15,6 @@ import QGroundControl 1.0 /// Set of functions for fitting the map viewpoer to a specific constraint Item { property var map - property rect mapFitViewport property bool usePlannedHomePosition ///< true: planned home position used for calculations, false: vehicle home position use for calculations property var mapGeoFenceController property var mapMissionController @@ -47,6 +46,7 @@ Item { /// Fits the visible region of the map to inclues all of the specified coordinates. If no coordinates /// are specified the map will center to fitHomePosition() function fitMapViewportToAllCoordinates(coordList) { + var mapFitViewport = Qt.rect(0, 0, map.width, map.height) if (coordList.length == 0) { map.center = fitHomePosition() return @@ -79,6 +79,9 @@ Item { var topLeftCoord = QtPositioning.coordinate(north - 90.0, west - 180.0) var bottomRightCoord = QtPositioning.coordinate(south - 90.0, east - 180.0) map.setVisibleRegion(QtPositioning.rectangle(topLeftCoord, bottomRightCoord)) + + // Back off on zoom level + map.zoomLevel = Math.abs(map.zoomLevel) - 1 } function addMissionItemCoordsForFit(coordList) { diff --git a/src/PlanView/PlanView.qml b/src/PlanView/PlanView.qml index eeefe1734..1f01d417c 100644 --- a/src/PlanView/PlanView.qml +++ b/src/PlanView/PlanView.qml @@ -89,7 +89,6 @@ QGCView { MapFitFunctions { id: mapFitFunctions map: editorMap - mapFitViewport: editorMap.centerViewport usePlannedHomePosition: true mapGeoFenceController: geoFenceController mapMissionController: missionController @@ -342,9 +341,11 @@ QGCView { anchors.fill: parent FlightMap { - id: editorMap - anchors.fill: parent - mapName: "MissionEditor" + id: editorMap + anchors.fill: parent + mapName: "MissionEditor" + allowGCSLocationCenter: true + allowVehicleLocationCenter: true // This is the center rectangle of the map which is not obscured by tools property rect centerViewport: Qt.rect(_leftToolWidth, _toolbarHeight, editorMap.width - _leftToolWidth - _rightPanelWidth, editorMap.height - _statusHeight - _toolbarHeight) diff --git a/src/QmlControls/QGroundControlQmlGlobal.cc b/src/QmlControls/QGroundControlQmlGlobal.cc index ad15a3b78..4856844c2 100644 --- a/src/QmlControls/QGroundControlQmlGlobal.cc +++ b/src/QmlControls/QGroundControlQmlGlobal.cc @@ -26,6 +26,7 @@ const char* QGroundControlQmlGlobal::_flightMapZoomSettingsKey = QGroundControlQmlGlobal::QGroundControlQmlGlobal(QGCApplication* app) : QGCTool(app) + , _flightMapInitialZoom(14.7) // About 500 meter scale , _linkManager(NULL) , _multiVehicleManager(NULL) , _mapEngineManager(NULL) @@ -192,8 +193,8 @@ QGeoCoordinate QGroundControlQmlGlobal::flightMapPosition(void) QGeoCoordinate coord; settings.beginGroup(_flightMapPositionSettingsGroup); - coord.setLatitude(settings.value(_flightMapPositionLatitudeSettingsKey, 37.803784).toDouble()); - coord.setLongitude(settings.value(_flightMapPositionLongitudeSettingsKey, -122.462276).toDouble()); + coord.setLatitude(settings.value(_flightMapPositionLatitudeSettingsKey, 0).toDouble()); + coord.setLongitude(settings.value(_flightMapPositionLongitudeSettingsKey, 0).toDouble()); return coord; } @@ -202,7 +203,8 @@ double QGroundControlQmlGlobal::flightMapZoom(void) { QSettings settings; - return settings.value(_flightMapZoomSettingsKey, 18).toDouble(); + settings.beginGroup(_flightMapPositionSettingsGroup); + return settings.value(_flightMapZoomSettingsKey, 2).toDouble(); } void QGroundControlQmlGlobal::setFlightMapPosition(QGeoCoordinate& coordinate) @@ -222,6 +224,7 @@ void QGroundControlQmlGlobal::setFlightMapZoom(double zoom) if (zoom != flightMapZoom()) { QSettings settings; + settings.beginGroup(_flightMapPositionSettingsGroup); settings.setValue(_flightMapZoomSettingsKey, zoom); emit flightMapZoomChanged(zoom); } diff --git a/src/QmlControls/QGroundControlQmlGlobal.h b/src/QmlControls/QGroundControlQmlGlobal.h index eb7394dc1..7890513ca 100644 --- a/src/QmlControls/QGroundControlQmlGlobal.h +++ b/src/QmlControls/QGroundControlQmlGlobal.h @@ -62,6 +62,7 @@ public: Q_PROPERTY(QGeoCoordinate flightMapPosition READ flightMapPosition WRITE setFlightMapPosition NOTIFY flightMapPositionChanged) Q_PROPERTY(double flightMapZoom READ flightMapZoom WRITE setFlightMapZoom NOTIFY flightMapZoomChanged) + Q_PROPERTY(double flightMapInitialZoom MEMBER _flightMapInitialZoom CONSTANT) ///< Zoom level to use when either gcs or vehicle shows up for first time Q_PROPERTY(QString parameterFileExtension READ parameterFileExtension CONSTANT) Q_PROPERTY(QString missionFileExtension READ missionFileExtension CONSTANT) @@ -169,6 +170,7 @@ signals: void skipSetupPageChanged (); private: + double _flightMapInitialZoom; LinkManager* _linkManager; MultiVehicleManager* _multiVehicleManager; QGCMapEngineManager* _mapEngineManager; -- 2.22.0