mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-30 23:40:06 +00:00 
			
		
		
		
	Add radar range circle. Web mercator projection meters are inaccurate. (~350km instead of 460km).
This commit is contained in:
		
							parent
							
								
									c1233cd984
								
							
						
					
					
						commit
						9b6582cd95
					
				
					 4 changed files with 83 additions and 1 deletions
				
			
		|  | @ -1,6 +1,7 @@ | |||
| #include "map_widget.hpp" | ||||
| 
 | ||||
| #include <scwx/qt/map/radar_layer.hpp> | ||||
| #include <scwx/qt/map/radar_range_layer.hpp> | ||||
| 
 | ||||
| #include <QApplication> | ||||
| #include <QColor> | ||||
|  | @ -66,7 +67,8 @@ void MapWidget::changeStyle() | |||
| void MapWidget::AddLayers() | ||||
| { | ||||
|    // QMapboxGL::addCustomLayer will take ownership of the QScopedPointer
 | ||||
|    QScopedPointer<QMapbox::CustomLayerHostInterface> pHost(new RadarLayer(map_)); | ||||
|    QScopedPointer<QMapbox::CustomLayerHostInterface> pHost( | ||||
|       new RadarLayer(map_)); | ||||
| 
 | ||||
|    QString before = "ferry"; | ||||
| 
 | ||||
|  | @ -82,6 +84,7 @@ void MapWidget::AddLayers() | |||
|    } | ||||
| 
 | ||||
|    map_->addCustomLayer("radar", pHost, before); | ||||
|    RadarRangeLayer::Add(map_, before); | ||||
| } | ||||
| 
 | ||||
| void MapWidget::keyPressEvent(QKeyEvent* ev) | ||||
|  |  | |||
							
								
								
									
										61
									
								
								scwx-qt/source/scwx/qt/map/radar_range_layer.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								scwx-qt/source/scwx/qt/map/radar_range_layer.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,61 @@ | |||
| #include <scwx/qt/map/radar_range_layer.hpp> | ||||
| 
 | ||||
| #include <boost/log/trivial.hpp> | ||||
| 
 | ||||
| #include <glm/glm.hpp> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| 
 | ||||
| static const std::string logPrefix_ = "[scwx::qt::map::radar_range_layer] "; | ||||
| 
 | ||||
| void RadarRangeLayer::Add(std::shared_ptr<QMapboxGL> map, const QString& before) | ||||
| { | ||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Add()"; | ||||
| 
 | ||||
|    constexpr float range = 460.0f * 1000.0f; | ||||
| 
 | ||||
|    constexpr float angleDelta  = glm::radians<float>(0.5f); | ||||
|    constexpr float angleDeltaH = angleDelta / 2.0f; | ||||
| 
 | ||||
|    const QMapbox::Coordinate      radar {38.6986, -90.6828}; | ||||
|    const QMapbox::ProjectedMeters radarMeters { | ||||
|       QMapbox::projectedMetersForCoordinate(radar)}; | ||||
| 
 | ||||
|    float angle = -angleDeltaH; | ||||
| 
 | ||||
|    QMapbox::Coordinates geometry; | ||||
| 
 | ||||
|    for (uint16_t azimuth = 0; azimuth <= 720; ++azimuth) | ||||
|    { | ||||
|       const float sinTheta = std::sinf(angle); | ||||
|       const float cosTheta = std::cosf(angle); | ||||
| 
 | ||||
|       const float x = range * sinTheta + radarMeters.second; | ||||
|       const float y = range * cosTheta + radarMeters.first; | ||||
| 
 | ||||
|       QMapbox::Coordinate point {QMapbox::coordinateForProjectedMeters({y, x})}; | ||||
| 
 | ||||
|       geometry.append(point); | ||||
| 
 | ||||
|       angle += angleDelta; | ||||
|    } | ||||
| 
 | ||||
|    QMapbox::Feature rangeCircle {QMapbox::Feature::LineStringType, | ||||
|                                  {{geometry}}}; | ||||
| 
 | ||||
|    map->addSource( | ||||
|       "rangeCircleSource", | ||||
|       {{"type", "geojson"}, {"data", QVariant::fromValue(rangeCircle)}}); | ||||
|    map->addLayer({{"id", "rangeCircleLayer"}, | ||||
|                   {"type", "line"}, | ||||
|                   {"source", "rangeCircleSource"}}, | ||||
|                  before); | ||||
|    map->setPaintProperty( | ||||
|       "rangeCircleLayer", "line-color", "rgba(128, 128, 128, 128)"); | ||||
| } | ||||
| 
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
							
								
								
									
										16
									
								
								scwx-qt/source/scwx/qt/map/radar_range_layer.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								scwx-qt/source/scwx/qt/map/radar_range_layer.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,16 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <QMapboxGL> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| 
 | ||||
| namespace RadarRangeLayer | ||||
| { | ||||
| void Add(std::shared_ptr<QMapboxGL> map, const QString& before = QString()); | ||||
| }; | ||||
| 
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat