forked from organicmaps/organicmaps
Draw road's number.
This commit is contained in:
parent
23545cbab5
commit
a2a53df74d
6 changed files with 73 additions and 26 deletions
|
@ -379,6 +379,8 @@ public:
|
|||
uint32_t GetPopulation() const;
|
||||
double GetPopulationDrawRank() const;
|
||||
|
||||
string GetRoadNumber() const { return m_Params.ref; }
|
||||
|
||||
/// @name Statistic functions.
|
||||
//@{
|
||||
void ParseBeforeStatistic() const
|
||||
|
|
|
@ -11,19 +11,19 @@ namespace di
|
|||
{
|
||||
class PathInfo
|
||||
{
|
||||
mutable double m_length;
|
||||
double m_fullL;
|
||||
double m_offset;
|
||||
|
||||
public:
|
||||
vector<m2::PointD> m_path;
|
||||
|
||||
// -1.0 means "not" initialized
|
||||
PathInfo(double offset = -1.0) : m_length(-1.0), m_offset(offset) {}
|
||||
PathInfo(double offset = -1.0) : m_fullL(-1.0), m_offset(offset) {}
|
||||
|
||||
void swap(PathInfo & r)
|
||||
{
|
||||
m_path.swap(r.m_path);
|
||||
std::swap(m_length, r.m_length);
|
||||
std::swap(m_fullL, r.m_fullL);
|
||||
std::swap(m_offset, r.m_offset);
|
||||
}
|
||||
|
||||
|
@ -34,20 +34,11 @@ namespace di
|
|||
|
||||
size_t size() const { return m_path.size(); }
|
||||
|
||||
void SetLength(double len) { m_length = len; }
|
||||
|
||||
double GetLength() const
|
||||
void SetFullLength(double len) { m_fullL = len; }
|
||||
double GetFullLength() const
|
||||
{
|
||||
// m_length not initialized - calculate it
|
||||
//if (m_length < 0.0)
|
||||
//{
|
||||
// m_length = 0.0;
|
||||
// for (size_t i = 1; i < m_path.size(); ++i)
|
||||
// m_length += m_path[i-1].Length(m_path[i]);
|
||||
//}
|
||||
|
||||
ASSERT ( m_length > 0.0, (m_length) );
|
||||
return m_length;
|
||||
ASSERT ( m_fullL > 0.0, (m_fullL) );
|
||||
return m_fullL;
|
||||
}
|
||||
|
||||
double GetOffset() const
|
||||
|
@ -56,6 +47,29 @@ namespace di
|
|||
return m_offset;
|
||||
}
|
||||
|
||||
bool GetSmPoint(double part, m2::PointD & pt) const
|
||||
{
|
||||
double sum = -GetFullLength() * part + m_offset;
|
||||
if (sum > 0.0) return false;
|
||||
|
||||
for (size_t i = 1; i < m_path.size(); ++i)
|
||||
{
|
||||
double const l = m_path[i-1].Length(m_path[i]);
|
||||
sum += l;
|
||||
if (sum >= 0.0)
|
||||
{
|
||||
double const factor = (l - sum) / l;
|
||||
ASSERT_GREATER_OR_EQUAL ( factor, 0.0, () );
|
||||
|
||||
pt.x = factor * (m_path[i].x - m_path[i-1].x) + m_path[i-1].x;
|
||||
pt.y = factor * (m_path[i].y - m_path[i-1].y) + m_path[i-1].y;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
m2::RectD GetLimitRect() const
|
||||
{
|
||||
m2::RectD rect;
|
||||
|
|
|
@ -85,7 +85,7 @@ void path_points::best_filtration(m2::PointD const & pt)
|
|||
m2::PointD prev = m_prev;
|
||||
m2::PointD curr = pt;
|
||||
|
||||
double segLen = curr.Length(prev);
|
||||
double const segLen = curr.Length(prev);
|
||||
|
||||
if ((m_startLength != 0) && (m_endLength != 0))
|
||||
{
|
||||
|
@ -123,7 +123,7 @@ void path_points::best_filtration(m2::PointD const & pt)
|
|||
}
|
||||
}
|
||||
|
||||
m_length += m_prev.Length(pt);
|
||||
m_length += segLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -145,7 +145,8 @@ void path_points::operator() (m2::PointD const & p)
|
|||
bool path_points::IsExist()
|
||||
{
|
||||
// finally, assign whole length to every cutted path
|
||||
for_each(m_points.begin(), m_points.end(), bind(&di::PathInfo::SetLength, _1, m_length));
|
||||
for_each(m_points.begin(), m_points.end(),
|
||||
bind(&di::PathInfo::SetFullLength, _1, m_length));
|
||||
|
||||
EndPL();
|
||||
return base_type::IsExist();
|
||||
|
|
|
@ -202,8 +202,8 @@ void DrawerYG::drawArea(vector<m2::PointD> const & pts, rule_ptr_t pRule, int de
|
|||
namespace
|
||||
{
|
||||
double const min_text_height_filtered = 2;
|
||||
double const min_text_height = 12; // 8
|
||||
// double const min_text_height_mask = 9.99; // 10
|
||||
double const min_text_height = 12; // 8
|
||||
//double const min_text_height_mask = 9.99; // 10
|
||||
}
|
||||
|
||||
uint8_t DrawerYG::get_text_font_size(rule_ptr_t pRule) const
|
||||
|
@ -258,7 +258,7 @@ bool DrawerYG::drawPathText(di::PathInfo const & info, string const & name, uint
|
|||
&info.m_path[0],
|
||||
info.m_path.size(),
|
||||
name,
|
||||
info.GetLength(),
|
||||
info.GetFullLength(),
|
||||
info.GetOffset(),
|
||||
yg::EPosCenter,
|
||||
yg::maxDepth);
|
||||
|
@ -276,6 +276,7 @@ void DrawerYG::SetVisualScale(double visualScale)
|
|||
|
||||
void DrawerYG::SetScale(int level)
|
||||
{
|
||||
m_level = level;
|
||||
m_scale = scales::GetM2PFactor(level);
|
||||
}
|
||||
|
||||
|
@ -283,8 +284,7 @@ void DrawerYG::Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size
|
|||
{
|
||||
buffer_vector<di::DrawRule, 8> pathRules;
|
||||
|
||||
/// separating path rules from other
|
||||
|
||||
// separating path rules from other
|
||||
for (unsigned i = 0; i < count; ++i)
|
||||
{
|
||||
rule_ptr_t pRule = rules[i].m_rule;
|
||||
|
@ -301,8 +301,35 @@ void DrawerYG::Draw(di::DrawInfo const * pInfo, di::DrawRule const * rules, size
|
|||
|
||||
if (!pathRules.empty())
|
||||
{
|
||||
bool const isNumber = !pInfo->m_road.empty() && m_level >= 12;
|
||||
|
||||
for (list<di::PathInfo>::const_iterator i = pInfo->m_pathes.begin(); i != pInfo->m_pathes.end(); ++i)
|
||||
{
|
||||
drawPath(i->m_path, pathRules.data(), pathRules.size());
|
||||
|
||||
int const textHeight = 12;
|
||||
m2::PointD pt;
|
||||
double const length = i->GetFullLength();
|
||||
if (isNumber && (length >= (pInfo->m_road.size() + 2)*textHeight))
|
||||
{
|
||||
size_t const count = size_t(length / 1000.0) + 2;
|
||||
|
||||
for (size_t j = 1; j < count; ++j)
|
||||
{
|
||||
if (i->GetSmPoint(double(j) / double(count), pt))
|
||||
{
|
||||
yg::FontDesc fontDesc(
|
||||
false,
|
||||
textHeight,
|
||||
yg::Color(150, 75, 0, 255), // brown
|
||||
true,
|
||||
yg::Color(255, 255, 255, 255));
|
||||
|
||||
m_pScreen->drawText(fontDesc, pt, yg::EPosCenter, 0.0, pInfo->m_road, yg::maxDepth, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned i = 0; i < count; ++i)
|
||||
|
|
|
@ -32,13 +32,14 @@ namespace di
|
|||
class DrawInfo
|
||||
{
|
||||
public:
|
||||
DrawInfo(string const & name, double rank) : m_name(name), m_rank(rank) {}
|
||||
DrawInfo(string const & name, string const & road, double rank)
|
||||
: m_name(name), m_road(road), m_rank(rank) {}
|
||||
|
||||
list<di::PathInfo> m_pathes;
|
||||
list<di::AreaInfo> m_areas;
|
||||
m2::PointD m_point;
|
||||
|
||||
string m_name;
|
||||
string m_name, m_road;
|
||||
double m_rank;
|
||||
};
|
||||
|
||||
|
@ -60,6 +61,7 @@ class DrawerYG
|
|||
|
||||
double m_scale;
|
||||
double m_visualScale;
|
||||
int m_level;
|
||||
|
||||
shared_ptr<yg::gl::Screen> m_pScreen;
|
||||
shared_ptr<yg::Skin> m_pSkin;
|
||||
|
|
|
@ -163,6 +163,7 @@ namespace fwork
|
|||
|
||||
shared_ptr<di::DrawInfo> ptr(
|
||||
new di::DrawInfo(f.GetPreferredDrawableName(languages::GetCurrentPriorities()),
|
||||
f.GetRoadNumber(),
|
||||
m_zoom > 5 ? f.GetPopulationDrawRank() : 0.0));
|
||||
|
||||
DrawerYG * pDrawer = GetDrawer();
|
||||
|
|
Loading…
Add table
Reference in a new issue