mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 22:30:06 +00:00
Extract utility geographic and maplibre functions
This commit is contained in:
parent
1a411af3bc
commit
1c39464228
6 changed files with 83 additions and 21 deletions
|
|
@ -192,6 +192,7 @@ set(HDR_UTIL source/scwx/qt/util/color.hpp
|
|||
source/scwx/qt/util/font_buffer.hpp
|
||||
source/scwx/qt/util/geographic_lib.hpp
|
||||
source/scwx/qt/util/json.hpp
|
||||
source/scwx/qt/util/maplibre.hpp
|
||||
source/scwx/qt/util/streams.hpp
|
||||
source/scwx/qt/util/texture_atlas.hpp
|
||||
source/scwx/qt/util/q_file_buffer.hpp
|
||||
|
|
@ -203,6 +204,7 @@ set(SRC_UTIL source/scwx/qt/util/color.cpp
|
|||
source/scwx/qt/util/font_buffer.cpp
|
||||
source/scwx/qt/util/geographic_lib.cpp
|
||||
source/scwx/qt/util/json.cpp
|
||||
source/scwx/qt/util/maplibre.cpp
|
||||
source/scwx/qt/util/texture_atlas.cpp
|
||||
source/scwx/qt/util/q_file_buffer.cpp
|
||||
source/scwx/qt/util/q_file_input_stream.cpp
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include <scwx/qt/map/radar_product_layer.hpp>
|
||||
#include <scwx/qt/gl/shader_program.hpp>
|
||||
#include <scwx/qt/util/maplibre.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
|
||||
#include <execution>
|
||||
|
|
@ -31,9 +32,6 @@ static constexpr uint32_t MAX_DATA_MOMENT_GATES = 1840;
|
|||
static const std::string logPrefix_ = "scwx::qt::map::radar_product_layer";
|
||||
static const auto logger_ = scwx::util::Logger::Create(logPrefix_);
|
||||
|
||||
static glm::vec2
|
||||
LatLongToScreenCoordinate(const QMapLibreGL::Coordinate& coordinate);
|
||||
|
||||
class RadarProductLayerImpl
|
||||
{
|
||||
public:
|
||||
|
|
@ -287,7 +285,7 @@ void RadarProductLayer::Render(
|
|||
|
||||
gl.glUniform2fv(p->uMapScreenCoordLocation_,
|
||||
1,
|
||||
glm::value_ptr(LatLongToScreenCoordinate(
|
||||
glm::value_ptr(util::maplibre::LatLongToScreenCoordinate(
|
||||
{params.latitude, params.longitude})));
|
||||
|
||||
gl.glUniformMatrix4fv(
|
||||
|
|
@ -355,22 +353,6 @@ void RadarProductLayer::UpdateColorTable()
|
|||
gl.glUniform1f(p->uDataMomentScaleLocation_, scale);
|
||||
}
|
||||
|
||||
static glm::vec2
|
||||
LatLongToScreenCoordinate(const QMapLibreGL::Coordinate& coordinate)
|
||||
{
|
||||
static constexpr double RAD2DEG_D = 180.0 / M_PI;
|
||||
|
||||
double latitude = std::clamp(
|
||||
coordinate.first, -mbgl::util::LATITUDE_MAX, mbgl::util::LATITUDE_MAX);
|
||||
glm::vec2 screen {
|
||||
mbgl::util::LONGITUDE_MAX + coordinate.second,
|
||||
-(mbgl::util::LONGITUDE_MAX -
|
||||
RAD2DEG_D *
|
||||
std::log(std::tan(M_PI / 4.0 +
|
||||
latitude * M_PI / mbgl::util::DEGREES_MAX)))};
|
||||
return screen;
|
||||
}
|
||||
|
||||
} // namespace map
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
|
|
|
|||
|
|
@ -18,6 +18,17 @@ const ::GeographicLib::Geodesic& DefaultGeodesic()
|
|||
return geodesic_;
|
||||
}
|
||||
|
||||
boost::units::quantity<boost::units::si::length>
|
||||
GetDistance(double lat1, double lon1, double lat2, double lon2)
|
||||
{
|
||||
double distance;
|
||||
util::GeographicLib::DefaultGeodesic().Inverse(
|
||||
lat1, lon1, lat2, lon2, distance);
|
||||
|
||||
return static_cast<boost::units::quantity<boost::units::si::length>>(
|
||||
distance * boost::units::si::meter_base_unit::unit_type());
|
||||
}
|
||||
|
||||
} // namespace GeographicLib
|
||||
} // namespace util
|
||||
} // namespace qt
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <GeographicLib/Geodesic.hpp>
|
||||
#include <boost/units/quantity.hpp>
|
||||
#include <boost/units/systems/si/length.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
|
|
@ -14,10 +16,23 @@ namespace GeographicLib
|
|||
/**
|
||||
* Get the default geodesic for the WGS84 ellipsoid.
|
||||
*
|
||||
* return WGS84 ellipsoid geodesic
|
||||
* @return WGS84 ellipsoid geodesic
|
||||
*/
|
||||
const ::GeographicLib::Geodesic& DefaultGeodesic();
|
||||
|
||||
/**
|
||||
* Get the distance between two points.
|
||||
*
|
||||
* @param [in] lat1 latitude of point 1 (degrees)
|
||||
* @param [in] lon1 longitude of point 1 (degrees)
|
||||
* @param [in] lat2 latitude of point 2 (degrees)
|
||||
* @param [in] lon2 longitude of point 2 (degrees)
|
||||
*
|
||||
* @return distance between point 1 and point 2
|
||||
*/
|
||||
boost::units::quantity<boost::units::si::length>
|
||||
GetDistance(double lat1, double lon1, double lat2, double lon2);
|
||||
|
||||
} // namespace GeographicLib
|
||||
} // namespace util
|
||||
} // namespace qt
|
||||
|
|
|
|||
32
scwx-qt/source/scwx/qt/util/maplibre.cpp
Normal file
32
scwx-qt/source/scwx/qt/util/maplibre.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include <scwx/qt/util/maplibre.hpp>
|
||||
|
||||
#include <mbgl/util/constants.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
namespace maplibre
|
||||
{
|
||||
|
||||
glm::vec2 LatLongToScreenCoordinate(const QMapLibreGL::Coordinate& coordinate)
|
||||
{
|
||||
static constexpr double RAD2DEG_D = 180.0 / M_PI;
|
||||
|
||||
double latitude = std::clamp(
|
||||
coordinate.first, -mbgl::util::LATITUDE_MAX, mbgl::util::LATITUDE_MAX);
|
||||
glm::vec2 screen {
|
||||
mbgl::util::LONGITUDE_MAX + coordinate.second,
|
||||
-(mbgl::util::LONGITUDE_MAX -
|
||||
RAD2DEG_D *
|
||||
std::log(std::tan(M_PI / 4.0 +
|
||||
latitude * M_PI / mbgl::util::DEGREES_MAX)))};
|
||||
return screen;
|
||||
}
|
||||
|
||||
} // namespace maplibre
|
||||
} // namespace util
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
20
scwx-qt/source/scwx/qt/util/maplibre.hpp
Normal file
20
scwx-qt/source/scwx/qt/util/maplibre.hpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
|
||||
#include <QMapLibreGL/types.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
namespace maplibre
|
||||
{
|
||||
|
||||
glm::vec2 LatLongToScreenCoordinate(const QMapLibreGL::Coordinate& coordinate);
|
||||
|
||||
} // namespace maplibre
|
||||
} // namespace util
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
Loading…
Add table
Add a link
Reference in a new issue