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
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
......
......@@ -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
......
......@@ -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
}
}
......
......@@ -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) {
......
......@@ -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)
......
......@@ -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);
}
......
......@@ -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;
......
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