mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 13:23:59 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
64
qt/ruler.cpp
Normal file
64
qt/ruler.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
#include "qt/ruler.hpp"
|
||||
|
||||
#include "geometry/mercator.hpp"
|
||||
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
|
||||
namespace qt
|
||||
{
|
||||
bool Ruler::IsActive() { return m_isActive; }
|
||||
|
||||
void Ruler::SetActive(bool status)
|
||||
{
|
||||
m_isActive = status;
|
||||
if (!m_isActive)
|
||||
{
|
||||
m_polyline.clear();
|
||||
m_sumDistanceM = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
void Ruler::AddPoint(m2::PointD const & point)
|
||||
{
|
||||
m_pointsPair[0] = m_pointsPair[1];
|
||||
m_pointsPair[1] = mercator::ToLatLon(point);
|
||||
m_polyline.insert(m_polyline.begin(), point);
|
||||
if (IsValidPolyline())
|
||||
SetDistance();
|
||||
}
|
||||
|
||||
void Ruler::DrawLine(df::DrapeApi & drapeApi)
|
||||
{
|
||||
if (!IsValidPolyline())
|
||||
return;
|
||||
|
||||
static dp::Color const lightGreyColor = dp::Color(102, 102, 102, 210);
|
||||
|
||||
drapeApi.RemoveLine(m_id);
|
||||
SetId();
|
||||
drapeApi.AddLine(
|
||||
m_id, df::DrapeApiLineData(m_polyline, lightGreyColor).Width(7.0f).ShowPoints(true).ShowId());
|
||||
}
|
||||
|
||||
void Ruler::EraseLine(df::DrapeApi & drapeApi) { drapeApi.RemoveLine(m_id); }
|
||||
|
||||
bool Ruler::IsValidPolyline() { return m_polyline.size() > 1; }
|
||||
|
||||
void Ruler::SetDistance()
|
||||
{
|
||||
m_sumDistanceM += oblate_spheroid::GetDistance(m_pointsPair[0], m_pointsPair[1]);
|
||||
}
|
||||
|
||||
void Ruler::SetId()
|
||||
{
|
||||
std::ostringstream curValStream;
|
||||
curValStream << std::fixed << std::setprecision(1);
|
||||
if (m_sumDistanceM >= 1000.0)
|
||||
curValStream << m_sumDistanceM / 1000.0 << " km";
|
||||
else
|
||||
curValStream << m_sumDistanceM << " m";
|
||||
|
||||
m_id = curValStream.str();
|
||||
}
|
||||
} // namespace qt
|
||||
Reference in New Issue
Block a user