diff --git a/ground/gcs/src/plugins/opmap/opmapgadget.cpp b/ground/gcs/src/plugins/opmap/opmapgadget.cpp index a49472aed..12319b593 100644 --- a/ground/gcs/src/plugins/opmap/opmapgadget.cpp +++ b/ground/gcs/src/plugins/opmap/opmapgadget.cpp @@ -67,8 +67,12 @@ void OPMapGadget::loadConfiguration(IUAVGadgetConfiguration *config) m_widget->SetUavPic(m_config->uavSymbol()); m_widget->setZoom(m_config->zoom()); m_widget->setPosition(QPointF(m_config->longitude(), m_config->latitude())); - m_widget->setHomePosition(QPointF(m_config->longitude(), m_config->latitude())); m_widget->setOverlayOpacity(m_config->opacity()); m_widget->setDefaultWaypointAltitude(m_config->defaultWaypointAltitude()); m_widget->setDefaultWaypointVelocity(m_config->defaultWaypointVelocity()); + + if (!m_widget->applyHomeLocationOnMap()) { + // Set default HomeLocation in center of map + m_widget->setHomePosition(QPointF(m_config->longitude(), m_config->latitude())); + } } diff --git a/ground/gcs/src/plugins/opmap/opmapgadgetwidget.cpp b/ground/gcs/src/plugins/opmap/opmapgadgetwidget.cpp index 2d6cfd14a..345cd3f5d 100644 --- a/ground/gcs/src/plugins/opmap/opmapgadgetwidget.cpp +++ b/ground/gcs/src/plugins/opmap/opmapgadgetwidget.cpp @@ -916,24 +916,7 @@ void OPMapGadgetWidget::onTelemetryConnect() if (!obum) { return; } - - bool set; - double LLA[3]; - - // *********************** - // fetch the home location - - if (obum->getHomeLocation(set, LLA) < 0) { - return; // error - } - setHome(internals::PointLatLng(LLA[0], LLA[1]), LLA[2]); - - if (m_map) { - if (m_map->UAV->GetMapFollowType() != UAVMapFollowType::None) { - m_map->SetCurrentPosition(m_home_position.coord); // set the map position - } - } - // *********************** + applyHomeLocationOnMap(); } void OPMapGadgetWidget::onTelemetryDisconnect() @@ -1164,6 +1147,10 @@ void OPMapGadgetWidget::setHomePosition(QPointF pos) } m_map->Home->SetCoord(internals::PointLatLng(latitude, longitude)); + + if (!m_telemetry_connected) { + m_home_position.coord = internals::PointLatLng(latitude, longitude); + } } void OPMapGadgetWidget::setPosition(QPointF pos) @@ -2366,6 +2353,32 @@ bool OPMapGadgetWidget::getGPSPositionSensor(double &latitude, double &longitude return true; } +bool OPMapGadgetWidget::applyHomeLocationOnMap() +{ + bool set; + double LLA[3]; + + if (!obum) { + return false; + } + + // fetch the home location + if (obum->getHomeLocation(set, LLA) < 0) { + return false; // error + } + + if (m_telemetry_connected) { + setHome(internals::PointLatLng(LLA[0], LLA[1]), LLA[2]); + if (m_map) { + if (m_map->UAV->GetMapFollowType() != UAVMapFollowType::None) { + m_map->SetCurrentPosition(m_home_position.coord); // set the map position + } + } + return true; + } + return false; +} + // ************************************************************************************* void OPMapGadgetWidget::setMapFollowingMode() diff --git a/ground/gcs/src/plugins/opmap/opmapgadgetwidget.h b/ground/gcs/src/plugins/opmap/opmapgadgetwidget.h index 696a10fbc..48f034365 100644 --- a/ground/gcs/src/plugins/opmap/opmapgadgetwidget.h +++ b/ground/gcs/src/plugins/opmap/opmapgadgetwidget.h @@ -117,6 +117,7 @@ public: void setDefaultWaypointAltitude(qreal default_altitude); void setDefaultWaypointVelocity(qreal default_velocity); bool getGPSPositionSensor(double &latitude, double &longitude, double &altitude); + bool applyHomeLocationOnMap(); signals: void defaultLocationAndZoomChanged(double lng, double lat, double zoom); void overlayOpacityChanged(qreal);