diff --git a/scwx-qt/source/scwx/qt/main/main_window.cpp b/scwx-qt/source/scwx/qt/main/main_window.cpp index 4b2d99ad..f16b191f 100644 --- a/scwx-qt/source/scwx/qt/main/main_window.cpp +++ b/scwx-qt/source/scwx/qt/main/main_window.cpp @@ -54,6 +54,13 @@ public: std::vector elevationCuts_; bool resizeElevationButtons_; + +public slots: + void UpdateMapParameters(double latitude, + double longitude, + double zoom, + double bearing, + double pitch); }; MainWindow::MainWindow(QWidget* parent) : @@ -203,6 +210,11 @@ void MainWindowImpl::ConfigureMapLayout() if (maps_.at(mapIndex) == nullptr) { maps_[mapIndex] = new map::MapWidget(settings_); + + connect(maps_[mapIndex], + &map::MapWidget::MapParametersChanged, + this, + &MainWindowImpl::UpdateMapParameters); } hs->addWidget(maps_[mapIndex]); @@ -278,6 +290,15 @@ void MainWindowImpl::UpdateElevationSelection(float elevation) } } +void MainWindowImpl::UpdateMapParameters( + double latitude, double longitude, double zoom, double bearing, double pitch) +{ + for (map::MapWidget* map : maps_) + { + map->SetMapParameters(latitude, longitude, zoom, bearing, pitch); + } +} + void MainWindowImpl::UpdateRadarProductSettings(map::MapWidget* mapWidget) { float currentElevation = mapWidget->GetElevation(); diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index 2ff8b743..43256599 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -17,6 +17,8 @@ #include #include +#include + namespace scwx { namespace qt @@ -24,6 +26,8 @@ namespace qt namespace map { +static const std::string logPrefix_ = "[scwx::qt::map::map_widget] "; + typedef std::pair MapStyle; // clang-format off @@ -38,11 +42,15 @@ static const MapStyle satelliteStreets { "mapbox://styles/mapbox/satellite-stree static const std::array mapboxStyles_ = { {streets, outdoors, light, dark, satellite, satelliteStreets}}; -class MapWidgetImpl +class MapWidgetImpl : public QObject { + Q_OBJECT + public: - explicit MapWidgetImpl(const QMapboxGLSettings& settings) : + explicit MapWidgetImpl(MapWidget* widget, + const QMapboxGLSettings& settings) : gl_(), + widget_ {widget}, settings_(settings), map_(), radarProductManager_ {std::make_shared()}, @@ -56,8 +64,11 @@ public: } ~MapWidgetImpl() = default; + bool UpdateStoredMapParameters(); + gl::OpenGLFunctions gl_; + MapWidget* widget_; QMapboxGLSettings settings_; std::shared_ptr map_; @@ -72,10 +83,19 @@ public: uint8_t currentStyleIndex_; uint64_t frameDraws_; + + double prevLatitude_; + double prevLongitude_; + double prevZoom_; + double prevBearing_; + double prevPitch_; + +public slots: + void Update(); }; MapWidget::MapWidget(const QMapboxGLSettings& settings) : - p(std::make_unique(settings)) + p(std::make_unique(this, settings)) { setFocusPolicy(Qt::StrongFocus); @@ -151,6 +171,14 @@ void MapWidget::SelectRadarProduct(common::Level2Product product) } } +void MapWidget::SetMapParameters( + double latitude, double longitude, double zoom, double bearing, double pitch) +{ + p->map_->setCoordinateZoom({latitude, longitude}, zoom); + p->map_->setBearing(bearing); + p->map_->setPitch(pitch); +} + qreal MapWidget::pixelRatio() { return devicePixelRatioF(); @@ -313,10 +341,14 @@ void MapWidget::initializeGL() p->gl_.initializeOpenGLFunctions(); p->map_.reset(new QMapboxGL(nullptr, p->settings_, size(), pixelRatio())); - connect(p->map_.get(), SIGNAL(needsRendering()), this, SLOT(update())); + connect(p->map_.get(), + &QMapboxGL::needsRendering, + p.get(), + &MapWidgetImpl::Update); // Set default location to KLSX. p->map_->setCoordinateZoom(QMapbox::Coordinate(38.6986, -90.6828), 11); + p->UpdateStoredMapParameters(); QString styleUrl = qgetenv("MAPBOX_STYLE_URL"); if (styleUrl.isEmpty()) @@ -349,6 +381,47 @@ void MapWidget::mapChanged(QMapboxGL::MapChange mapChange) } } +void MapWidgetImpl::Update() +{ + widget_->update(); + + if (UpdateStoredMapParameters()) + { + emit widget_->MapParametersChanged( + prevLatitude_, prevLongitude_, prevZoom_, prevBearing_, prevPitch_); + } +} + +bool MapWidgetImpl::UpdateStoredMapParameters() +{ + bool changed = false; + + double newLatitude = map_->latitude(); + double newLongitude = map_->longitude(); + double newZoom = map_->zoom(); + double newBearing = map_->bearing(); + double newPitch = map_->pitch(); + + if (prevLatitude_ != newLatitude || // + prevLongitude_ != newLongitude || // + prevZoom_ != newZoom || // + prevBearing_ != newBearing || // + prevPitch_ != newPitch) + { + prevLatitude_ = newLatitude; + prevLongitude_ = newLongitude; + prevZoom_ = newZoom; + prevBearing_ = newBearing; + prevPitch_ = newPitch; + + changed = true; + } + + return changed; +} + } // namespace map } // namespace qt } // namespace scwx + +#include "map_widget.moc" diff --git a/scwx-qt/source/scwx/qt/map/map_widget.hpp b/scwx-qt/source/scwx/qt/map/map_widget.hpp index 385f586a..71a4a538 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.hpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.hpp @@ -35,6 +35,11 @@ public: std::vector GetElevationCuts() const; void SelectElevation(float elevation); void SelectRadarProduct(common::Level2Product product); + void SetMapParameters(double latitude, + double longitude, + double zoom, + double bearing, + double pitch); private: void changeStyle(); @@ -58,6 +63,11 @@ private slots: void mapChanged(QMapboxGL::MapChange); signals: + void MapParametersChanged(double latitude, + double longitude, + double zoom, + double bearing, + double pitch); void RadarSweepUpdated(); };