Commit 2e498a66 authored by DonLakeFlyer's avatar DonLakeFlyer

Various fixes/changes to initial map positions in Fly/Plan

parent 5c7f03ac
...@@ -24,14 +24,16 @@ import QGroundControl.Vehicle 1.0 ...@@ -24,14 +24,16 @@ import QGroundControl.Vehicle 1.0
import QGroundControl.Controllers 1.0 import QGroundControl.Controllers 1.0
FlightMap { FlightMap {
id: flightMap id: flightMap
anchors.fill: parent anchors.fill: parent
mapName: _mapName mapName: _mapName
allowGCSLocationCenter: !userPanned
allowVehicleLocationCenter: !_keepVehicleCentered
property alias missionController: missionController property alias missionController: missionController
property var flightWidgets property var flightWidgets
property var rightPanelWidth 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 _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
property var _activeVehicleCoordinate: _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate() property var _activeVehicleCoordinate: _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate()
...@@ -41,45 +43,16 @@ FlightMap { ...@@ -41,45 +43,16 @@ FlightMap {
property bool _disableVehicleTracking: false property bool _disableVehicleTracking: false
property bool _keepVehicleCentered: _mainIsMap ? false : true 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 onZoomLevelChanged: QGroundControl.flightMapZoom = zoomLevel
onCenterChanged: QGroundControl.flightMapPosition = center 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 // When the user pans the map we stop responding to vehicle coordinate updates until the panRecenterTimer fires
Connections { onUserPannedChanged: {
target: gesture _disableVehicleTracking = true
panRecenterTimer.start()
onPanFinished: {
_userPanned = true
_disableVehicleTracking = true
panRecenterTimer.start()
}
onFlickFinished: {
_userPanned = true
_disableVehicleTracking = true
panRecenterTimer.start()
}
} }
function pointInRect(point, rect) { function pointInRect(point, rect) {
...@@ -118,15 +91,12 @@ FlightMap { ...@@ -118,15 +91,12 @@ FlightMap {
} }
function updateMapToVehiclePosition() { function updateMapToVehiclePosition() {
if (_activeVehicleCoordinate.isValid && !_disableVehicleTracking) { // We let FlightMap handle first vehicle position
if (firstVehiclePositionReceived && _activeVehicleCoordinate.isValid && !_disableVehicleTracking) {
if (_keepVehicleCentered) { if (_keepVehicleCentered) {
_firstVehiclePositionReceived = true
flightMap.center = _activeVehicleCoordinate flightMap.center = _activeVehicleCoordinate
} else { } else {
if (!_firstVehiclePositionReceived) { if (firstVehiclePositionReceived) {
_firstVehiclePositionReceived = true
flightMap.center = _activeVehicleCoordinate
} else if (recenterNeeded()) {
animatedMapRecenter(flightMap.center, _activeVehicleCoordinate) animatedMapRecenter(flightMap.center, _activeVehicleCoordinate)
} }
} }
...@@ -156,7 +126,15 @@ FlightMap { ...@@ -156,7 +126,15 @@ FlightMap {
MissionController { MissionController {
id: missionController id: missionController
Component.onCompleted: start(false /* editMode */) Component.onCompleted: start(false /* editMode */)
onNewItemsFromVehicle: {
var visualItem = missionController.visualItems
if (visualItems && visualItems.count != 1) {
mapFitFunctions.fitMapViewportToMissionItems()
}
}
} }
GeoFenceController { GeoFenceController {
...@@ -263,7 +241,6 @@ FlightMap { ...@@ -263,7 +241,6 @@ FlightMap {
MapFitFunctions { MapFitFunctions {
id: mapFitFunctions id: mapFitFunctions
map: _flightMap map: _flightMap
mapFitViewport: Qt.rect(leftToolWidth, _toolButtonTopMargin, flightMap.width - leftToolWidth - rightPanelWidth, flightMap.height - _toolButtonTopMargin)
usePlannedHomePosition: false usePlannedHomePosition: false
mapMissionController: missionController mapMissionController: missionController
mapGeoFenceController: geoFenceController mapGeoFenceController: geoFenceController
......
...@@ -30,12 +30,20 @@ Map { ...@@ -30,12 +30,20 @@ Map {
gesture.flickDeceleration: 3000 gesture.flickDeceleration: 3000
plugin: Plugin { name: "QGroundControl" } plugin: Plugin { name: "QGroundControl" }
property string mapName: 'defaultMap' property string mapName: 'defaultMap'
property bool isSatelliteMap: activeMapType.name.indexOf("Satellite") > -1 || activeMapType.name.indexOf("Hybrid") > -1 property bool isSatelliteMap: activeMapType.name.indexOf("Satellite") > -1 || activeMapType.name.indexOf("Hybrid") > -1
property var gcsPosition: QtPositioning.coordinate() 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 readonly property real maxZoomLevel: 20
property var _activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
property var activeVehicleCoordinate: _activeVehicle ? _activeVehicle.coordinate : QtPositioning.coordinate()
function setVisibleRegion(region) { 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 // 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 // and then you set the same visibleRegion the map will not move/scale appropriately since it thinks there
...@@ -44,6 +52,14 @@ Map { ...@@ -44,6 +52,14 @@ Map {
_map.visibleRegion = region _map.visibleRegion = region
} }
function _possiblyCenterToVehiclePosition() {
if (!firstVehiclePositionReceived && allowVehicleLocationCenter && activeVehicleCoordinate.isValid) {
firstVehiclePositionReceived = true
center = activeVehicleCoordinate
zoomLevel = QGroundControl.flightMapInitialZoom
}
}
ExclusiveGroup { id: mapTypeGroup } ExclusiveGroup { id: mapTypeGroup }
// Update ground station position // Update ground station position
...@@ -53,10 +69,23 @@ Map { ...@@ -53,10 +69,23 @@ Map {
onLastPositionUpdated: { onLastPositionUpdated: {
if (valid && lastPosition.latitude && Math.abs(lastPosition.latitude) > 0.001 && lastPosition.longitude && Math.abs(lastPosition.longitude) > 0.001) { 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) 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() { function updateActiveMapType() {
var settings = QGroundControl.settingsManager.flightMapSettings var settings = QGroundControl.settingsManager.flightMapSettings
var fullMapName = settings.mapProvider.enumStringValue + " " + settings.mapType.enumStringValue var fullMapName = settings.mapProvider.enumStringValue + " " + settings.mapType.enumStringValue
...@@ -68,7 +97,12 @@ Map { ...@@ -68,7 +97,12 @@ Map {
} }
} }
Component.onCompleted: updateActiveMapType() onActiveVehicleCoordinateChanged: _possiblyCenterToVehiclePosition()
Component.onCompleted: {
updateActiveMapType()
_possiblyCenterToVehiclePosition()
}
Connections { Connections {
target: QGroundControl.settingsManager.flightMapSettings.mapType target: QGroundControl.settingsManager.flightMapSettings.mapType
......
...@@ -65,11 +65,11 @@ ColumnLayout { ...@@ -65,11 +65,11 @@ ColumnLayout {
QGCButton { QGCButton {
text: qsTr("Current Location") text: qsTr("Current Location")
Layout.fillWidth: true Layout.fillWidth: true
enabled: _map.gcsPosition.isValid enabled: map.gcsPosition.isValid
onClicked: { onClicked: {
dropPanel.hide() dropPanel.hide()
map.center = _map.gcsPosition map.center = map.gcsPosition
} }
} }
......
...@@ -15,7 +15,6 @@ import QGroundControl 1.0 ...@@ -15,7 +15,6 @@ import QGroundControl 1.0
/// Set of functions for fitting the map viewpoer to a specific constraint /// Set of functions for fitting the map viewpoer to a specific constraint
Item { Item {
property var map property var map
property rect mapFitViewport
property bool usePlannedHomePosition ///< true: planned home position used for calculations, false: vehicle home position use for calculations property bool usePlannedHomePosition ///< true: planned home position used for calculations, false: vehicle home position use for calculations
property var mapGeoFenceController property var mapGeoFenceController
property var mapMissionController property var mapMissionController
...@@ -47,6 +46,7 @@ Item { ...@@ -47,6 +46,7 @@ Item {
/// Fits the visible region of the map to inclues all of the specified coordinates. If no coordinates /// 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() /// are specified the map will center to fitHomePosition()
function fitMapViewportToAllCoordinates(coordList) { function fitMapViewportToAllCoordinates(coordList) {
var mapFitViewport = Qt.rect(0, 0, map.width, map.height)
if (coordList.length == 0) { if (coordList.length == 0) {
map.center = fitHomePosition() map.center = fitHomePosition()
return return
...@@ -79,6 +79,9 @@ Item { ...@@ -79,6 +79,9 @@ Item {
var topLeftCoord = QtPositioning.coordinate(north - 90.0, west - 180.0) var topLeftCoord = QtPositioning.coordinate(north - 90.0, west - 180.0)
var bottomRightCoord = QtPositioning.coordinate(south - 90.0, east - 180.0) var bottomRightCoord = QtPositioning.coordinate(south - 90.0, east - 180.0)
map.setVisibleRegion(QtPositioning.rectangle(topLeftCoord, bottomRightCoord)) map.setVisibleRegion(QtPositioning.rectangle(topLeftCoord, bottomRightCoord))
// Back off on zoom level
map.zoomLevel = Math.abs(map.zoomLevel) - 1
} }
function addMissionItemCoordsForFit(coordList) { function addMissionItemCoordsForFit(coordList) {
......
...@@ -89,7 +89,6 @@ QGCView { ...@@ -89,7 +89,6 @@ QGCView {
MapFitFunctions { MapFitFunctions {
id: mapFitFunctions id: mapFitFunctions
map: editorMap map: editorMap
mapFitViewport: editorMap.centerViewport
usePlannedHomePosition: true usePlannedHomePosition: true
mapGeoFenceController: geoFenceController mapGeoFenceController: geoFenceController
mapMissionController: missionController mapMissionController: missionController
...@@ -342,9 +341,11 @@ QGCView { ...@@ -342,9 +341,11 @@ QGCView {
anchors.fill: parent anchors.fill: parent
FlightMap { FlightMap {
id: editorMap id: editorMap
anchors.fill: parent anchors.fill: parent
mapName: "MissionEditor" mapName: "MissionEditor"
allowGCSLocationCenter: true
allowVehicleLocationCenter: true
// This is the center rectangle of the map which is not obscured by tools // 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) property rect centerViewport: Qt.rect(_leftToolWidth, _toolbarHeight, editorMap.width - _leftToolWidth - _rightPanelWidth, editorMap.height - _statusHeight - _toolbarHeight)
......
...@@ -26,6 +26,7 @@ const char* QGroundControlQmlGlobal::_flightMapZoomSettingsKey = ...@@ -26,6 +26,7 @@ const char* QGroundControlQmlGlobal::_flightMapZoomSettingsKey =
QGroundControlQmlGlobal::QGroundControlQmlGlobal(QGCApplication* app) QGroundControlQmlGlobal::QGroundControlQmlGlobal(QGCApplication* app)
: QGCTool(app) : QGCTool(app)
, _flightMapInitialZoom(14.7) // About 500 meter scale
, _linkManager(NULL) , _linkManager(NULL)
, _multiVehicleManager(NULL) , _multiVehicleManager(NULL)
, _mapEngineManager(NULL) , _mapEngineManager(NULL)
...@@ -192,8 +193,8 @@ QGeoCoordinate QGroundControlQmlGlobal::flightMapPosition(void) ...@@ -192,8 +193,8 @@ QGeoCoordinate QGroundControlQmlGlobal::flightMapPosition(void)
QGeoCoordinate coord; QGeoCoordinate coord;
settings.beginGroup(_flightMapPositionSettingsGroup); settings.beginGroup(_flightMapPositionSettingsGroup);
coord.setLatitude(settings.value(_flightMapPositionLatitudeSettingsKey, 37.803784).toDouble()); coord.setLatitude(settings.value(_flightMapPositionLatitudeSettingsKey, 0).toDouble());
coord.setLongitude(settings.value(_flightMapPositionLongitudeSettingsKey, -122.462276).toDouble()); coord.setLongitude(settings.value(_flightMapPositionLongitudeSettingsKey, 0).toDouble());
return coord; return coord;
} }
...@@ -202,7 +203,8 @@ double QGroundControlQmlGlobal::flightMapZoom(void) ...@@ -202,7 +203,8 @@ double QGroundControlQmlGlobal::flightMapZoom(void)
{ {
QSettings settings; QSettings settings;
return settings.value(_flightMapZoomSettingsKey, 18).toDouble(); settings.beginGroup(_flightMapPositionSettingsGroup);
return settings.value(_flightMapZoomSettingsKey, 2).toDouble();
} }
void QGroundControlQmlGlobal::setFlightMapPosition(QGeoCoordinate& coordinate) void QGroundControlQmlGlobal::setFlightMapPosition(QGeoCoordinate& coordinate)
...@@ -222,6 +224,7 @@ void QGroundControlQmlGlobal::setFlightMapZoom(double zoom) ...@@ -222,6 +224,7 @@ void QGroundControlQmlGlobal::setFlightMapZoom(double zoom)
if (zoom != flightMapZoom()) { if (zoom != flightMapZoom()) {
QSettings settings; QSettings settings;
settings.beginGroup(_flightMapPositionSettingsGroup);
settings.setValue(_flightMapZoomSettingsKey, zoom); settings.setValue(_flightMapZoomSettingsKey, zoom);
emit flightMapZoomChanged(zoom); emit flightMapZoomChanged(zoom);
} }
......
...@@ -62,6 +62,7 @@ public: ...@@ -62,6 +62,7 @@ public:
Q_PROPERTY(QGeoCoordinate flightMapPosition READ flightMapPosition WRITE setFlightMapPosition NOTIFY flightMapPositionChanged) Q_PROPERTY(QGeoCoordinate flightMapPosition READ flightMapPosition WRITE setFlightMapPosition NOTIFY flightMapPositionChanged)
Q_PROPERTY(double flightMapZoom READ flightMapZoom WRITE setFlightMapZoom NOTIFY flightMapZoomChanged) 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 parameterFileExtension READ parameterFileExtension CONSTANT)
Q_PROPERTY(QString missionFileExtension READ missionFileExtension CONSTANT) Q_PROPERTY(QString missionFileExtension READ missionFileExtension CONSTANT)
...@@ -169,6 +170,7 @@ signals: ...@@ -169,6 +170,7 @@ signals:
void skipSetupPageChanged (); void skipSetupPageChanged ();
private: private:
double _flightMapInitialZoom;
LinkManager* _linkManager; LinkManager* _linkManager;
MultiVehicleManager* _multiVehicleManager; MultiVehicleManager* _multiVehicleManager;
QGCMapEngineManager* _mapEngineManager; QGCMapEngineManager* _mapEngineManager;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment