forked from mapsme/omim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruler.cpp
64 lines (51 loc) · 1.38 KB
/
ruler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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