From e63127adc9257afcad5ef13570a6b48d78405a97 Mon Sep 17 00:00:00 2001 From: Lorenz Meier Date: Mon, 19 May 2014 16:44:36 +0200 Subject: [PATCH] Map: Use sensible defaults to init map close to vehicle position --- src/ui/map/QGCMapWidget.cc | 29 +++++++++++++++++++++-------- src/ui/map/QGCMapWidget.h | 1 + 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/ui/map/QGCMapWidget.cc b/src/ui/map/QGCMapWidget.cc index 5f5ba3697..f98ba0043 100644 --- a/src/ui/map/QGCMapWidget.cc +++ b/src/ui/map/QGCMapWidget.cc @@ -16,6 +16,7 @@ QGCMapWidget::QGCMapWidget(QWidget *parent) : trailInterval(2.0f), followUAVID(0), mapInitialized(false), + mapPositionInitialized(false), homeAltitude(0), uas(NULL) { @@ -174,7 +175,6 @@ void QGCMapWidget::mouseReleaseEvent(QMouseEvent *event) if (firingWaypointChange) { firingWaypointChange = NULL; } - qDebug() << "MOUSE RELEASED"; } QGCMapWidget::~QGCMapWidget() @@ -192,6 +192,9 @@ void QGCMapWidget::showEvent(QShowEvent* event) // Pass on to parent widget OPMapWidget::showEvent(event); + // Connect map updates to the adapter slots + connect(this, SIGNAL(WPValuesChanged(WayPointItem*)), this, SLOT(handleMapWaypointEdit(WayPointItem*))); + connect(UASManager::instance(), SIGNAL(UASCreated(UASInterface*)), this, SLOT(addUAS(UASInterface*)), Qt::UniqueConnection); connect(UASManager::instance(), SIGNAL(activeUASSet(UASInterface*)), this, SLOT(activeUASSet(UASInterface*)), Qt::UniqueConnection); connect(UASManager::instance(), SIGNAL(homePositionChanged(double,double,double)), this, SLOT(updateHomePosition(double,double,double))); @@ -217,16 +220,15 @@ void QGCMapWidget::showEvent(QShowEvent* event) setFrameStyle(QFrame::NoFrame); // no border frame setBackgroundBrush(QBrush(Qt::black)); // tile background - // Set current home position + if (!UASManager::instance()->getActiveUAS()) { + SetCurrentPosition(pos_lat_lon); // set the map position to default + } + + // Set home updateHomePosition(UASManager::instance()->getHomeLatitude(), UASManager::instance()->getHomeLongitude(), UASManager::instance()->getHomeAltitude()); // Set currently selected system activeUASSet(UASManager::instance()->getActiveUAS()); - - // Connect map updates to the adapter slots - connect(this, SIGNAL(WPValuesChanged(WayPointItem*)), this, SLOT(handleMapWaypointEdit(WayPointItem*))); - - SetCurrentPosition(pos_lat_lon); // set the map position setFocus(); // Start timer @@ -387,6 +389,16 @@ void QGCMapWidget::activeUASSet(UASInterface* uas) connect(currWPManager, SIGNAL(waypointEditableChanged(int, Waypoint*)), this, SLOT(updateWaypoint(int,Waypoint*))); connect(this, SIGNAL(waypointCreated(Waypoint*)), currWPManager, SLOT(addWaypointEditable(Waypoint*))); connect(this, SIGNAL(waypointChanged(Waypoint*)), currWPManager, SLOT(notifyOfChangeEditable(Waypoint*))); + + if (!mapPositionInitialized) { + internals::PointLatLng pos_lat_lon = internals::PointLatLng(uas->getLatitude(), uas->getLongitude()); + SetCurrentPosition(pos_lat_lon); + + // Zoom in + SetZoom(13); + + mapPositionInitialized = true; + } } else { @@ -568,6 +580,7 @@ void QGCMapWidget::showGoToDialog() void QGCMapWidget::updateHomePosition(double latitude, double longitude, double altitude) { + qDebug() << "HOME SET TO: " << latitude << longitude << altitude; Home->SetCoord(internals::PointLatLng(latitude, longitude)); Home->SetAltitude(altitude); homeAltitude = altitude; @@ -578,7 +591,7 @@ void QGCMapWidget::updateHomePosition(double latitude, double longitude, double void QGCMapWidget::goHome() { SetCurrentPosition(Home->Coord()); - SetZoom(18); //zoom to "large RC park" size + SetZoom(17); } /** diff --git a/src/ui/map/QGCMapWidget.h b/src/ui/map/QGCMapWidget.h index 2f169a9ef..8b41d8439 100644 --- a/src/ui/map/QGCMapWidget.h +++ b/src/ui/map/QGCMapWidget.h @@ -167,6 +167,7 @@ protected: float trailInterval; ///< Time or distance between trail items int followUAVID; ///< Which UAV should be tracked? bool mapInitialized; ///< Map initialized? + bool mapPositionInitialized; ///< The position on the map has a reasonable value? float homeAltitude; ///< Home altitude QPoint mousePressPos; ///< Mouse position when the button is released. QPoint contextMousePressPos; ///< Mouse position when context menu activated. -- 2.22.0