mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 06:50:05 +00:00 
			
		
		
		
	Synchronize map movements
This commit is contained in:
		
							parent
							
								
									372848c25f
								
							
						
					
					
						commit
						dd452a0e2c
					
				
					 3 changed files with 108 additions and 4 deletions
				
			
		|  | @ -54,6 +54,13 @@ public: | ||||||
|    std::vector<float>           elevationCuts_; |    std::vector<float>           elevationCuts_; | ||||||
| 
 | 
 | ||||||
|    bool resizeElevationButtons_; |    bool resizeElevationButtons_; | ||||||
|  | 
 | ||||||
|  | public slots: | ||||||
|  |    void UpdateMapParameters(double latitude, | ||||||
|  |                             double longitude, | ||||||
|  |                             double zoom, | ||||||
|  |                             double bearing, | ||||||
|  |                             double pitch); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| MainWindow::MainWindow(QWidget* parent) : | MainWindow::MainWindow(QWidget* parent) : | ||||||
|  | @ -203,6 +210,11 @@ void MainWindowImpl::ConfigureMapLayout() | ||||||
|          if (maps_.at(mapIndex) == nullptr) |          if (maps_.at(mapIndex) == nullptr) | ||||||
|          { |          { | ||||||
|             maps_[mapIndex] = new map::MapWidget(settings_); |             maps_[mapIndex] = new map::MapWidget(settings_); | ||||||
|  | 
 | ||||||
|  |             connect(maps_[mapIndex], | ||||||
|  |                     &map::MapWidget::MapParametersChanged, | ||||||
|  |                     this, | ||||||
|  |                     &MainWindowImpl::UpdateMapParameters); | ||||||
|          } |          } | ||||||
| 
 | 
 | ||||||
|          hs->addWidget(maps_[mapIndex]); |          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) | void MainWindowImpl::UpdateRadarProductSettings(map::MapWidget* mapWidget) | ||||||
| { | { | ||||||
|    float              currentElevation = mapWidget->GetElevation(); |    float              currentElevation = mapWidget->GetElevation(); | ||||||
|  |  | ||||||
|  | @ -17,6 +17,8 @@ | ||||||
| #include <QMouseEvent> | #include <QMouseEvent> | ||||||
| #include <QString> | #include <QString> | ||||||
| 
 | 
 | ||||||
|  | #include <boost/log/trivial.hpp> | ||||||
|  | 
 | ||||||
| namespace scwx | namespace scwx | ||||||
| { | { | ||||||
| namespace qt | namespace qt | ||||||
|  | @ -24,6 +26,8 @@ namespace qt | ||||||
| namespace map | namespace map | ||||||
| { | { | ||||||
| 
 | 
 | ||||||
|  | static const std::string logPrefix_ = "[scwx::qt::map::map_widget] "; | ||||||
|  | 
 | ||||||
| typedef std::pair<std::string, std::string> MapStyle; | typedef std::pair<std::string, std::string> MapStyle; | ||||||
| 
 | 
 | ||||||
| // clang-format off
 | // clang-format off
 | ||||||
|  | @ -38,11 +42,15 @@ static const MapStyle satelliteStreets { "mapbox://styles/mapbox/satellite-stree | ||||||
| static const std::array<MapStyle, 6> mapboxStyles_ = { | static const std::array<MapStyle, 6> mapboxStyles_ = { | ||||||
|    {streets, outdoors, light, dark, satellite, satelliteStreets}}; |    {streets, outdoors, light, dark, satellite, satelliteStreets}}; | ||||||
| 
 | 
 | ||||||
| class MapWidgetImpl | class MapWidgetImpl : public QObject | ||||||
| { | { | ||||||
|  |    Q_OBJECT | ||||||
|  | 
 | ||||||
| public: | public: | ||||||
|    explicit MapWidgetImpl(const QMapboxGLSettings& settings) : |    explicit MapWidgetImpl(MapWidget*               widget, | ||||||
|  |                           const QMapboxGLSettings& settings) : | ||||||
|        gl_(), |        gl_(), | ||||||
|  |        widget_ {widget}, | ||||||
|        settings_(settings), |        settings_(settings), | ||||||
|        map_(), |        map_(), | ||||||
|        radarProductManager_ {std::make_shared<manager::RadarProductManager>()}, |        radarProductManager_ {std::make_shared<manager::RadarProductManager>()}, | ||||||
|  | @ -56,8 +64,11 @@ public: | ||||||
|    } |    } | ||||||
|    ~MapWidgetImpl() = default; |    ~MapWidgetImpl() = default; | ||||||
| 
 | 
 | ||||||
|  |    bool UpdateStoredMapParameters(); | ||||||
|  | 
 | ||||||
|    gl::OpenGLFunctions gl_; |    gl::OpenGLFunctions gl_; | ||||||
| 
 | 
 | ||||||
|  |    MapWidget*                 widget_; | ||||||
|    QMapboxGLSettings          settings_; |    QMapboxGLSettings          settings_; | ||||||
|    std::shared_ptr<QMapboxGL> map_; |    std::shared_ptr<QMapboxGL> map_; | ||||||
| 
 | 
 | ||||||
|  | @ -72,10 +83,19 @@ public: | ||||||
|    uint8_t currentStyleIndex_; |    uint8_t currentStyleIndex_; | ||||||
| 
 | 
 | ||||||
|    uint64_t frameDraws_; |    uint64_t frameDraws_; | ||||||
|  | 
 | ||||||
|  |    double prevLatitude_; | ||||||
|  |    double prevLongitude_; | ||||||
|  |    double prevZoom_; | ||||||
|  |    double prevBearing_; | ||||||
|  |    double prevPitch_; | ||||||
|  | 
 | ||||||
|  | public slots: | ||||||
|  |    void Update(); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| MapWidget::MapWidget(const QMapboxGLSettings& settings) : | MapWidget::MapWidget(const QMapboxGLSettings& settings) : | ||||||
|     p(std::make_unique<MapWidgetImpl>(settings)) |     p(std::make_unique<MapWidgetImpl>(this, settings)) | ||||||
| { | { | ||||||
|    setFocusPolicy(Qt::StrongFocus); |    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() | qreal MapWidget::pixelRatio() | ||||||
| { | { | ||||||
|    return devicePixelRatioF(); |    return devicePixelRatioF(); | ||||||
|  | @ -313,10 +341,14 @@ void MapWidget::initializeGL() | ||||||
|    p->gl_.initializeOpenGLFunctions(); |    p->gl_.initializeOpenGLFunctions(); | ||||||
| 
 | 
 | ||||||
|    p->map_.reset(new QMapboxGL(nullptr, p->settings_, size(), pixelRatio())); |    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.
 |    // Set default location to KLSX.
 | ||||||
|    p->map_->setCoordinateZoom(QMapbox::Coordinate(38.6986, -90.6828), 11); |    p->map_->setCoordinateZoom(QMapbox::Coordinate(38.6986, -90.6828), 11); | ||||||
|  |    p->UpdateStoredMapParameters(); | ||||||
| 
 | 
 | ||||||
|    QString styleUrl = qgetenv("MAPBOX_STYLE_URL"); |    QString styleUrl = qgetenv("MAPBOX_STYLE_URL"); | ||||||
|    if (styleUrl.isEmpty()) |    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 map
 | ||||||
| } // namespace qt
 | } // namespace qt
 | ||||||
| } // namespace scwx
 | } // namespace scwx
 | ||||||
|  | 
 | ||||||
|  | #include "map_widget.moc" | ||||||
|  |  | ||||||
|  | @ -35,6 +35,11 @@ public: | ||||||
|    std::vector<float> GetElevationCuts() const; |    std::vector<float> GetElevationCuts() const; | ||||||
|    void               SelectElevation(float elevation); |    void               SelectElevation(float elevation); | ||||||
|    void               SelectRadarProduct(common::Level2Product product); |    void               SelectRadarProduct(common::Level2Product product); | ||||||
|  |    void               SetMapParameters(double latitude, | ||||||
|  |                                        double longitude, | ||||||
|  |                                        double zoom, | ||||||
|  |                                        double bearing, | ||||||
|  |                                        double pitch); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|    void  changeStyle(); |    void  changeStyle(); | ||||||
|  | @ -58,6 +63,11 @@ private slots: | ||||||
|    void mapChanged(QMapboxGL::MapChange); |    void mapChanged(QMapboxGL::MapChange); | ||||||
| 
 | 
 | ||||||
| signals: | signals: | ||||||
|  |    void MapParametersChanged(double latitude, | ||||||
|  |                              double longitude, | ||||||
|  |                              double zoom, | ||||||
|  |                              double bearing, | ||||||
|  |                              double pitch); | ||||||
|    void RadarSweepUpdated(); |    void RadarSweepUpdated(); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat