forked from organicmaps/organicmaps
Fix types getting in Framework::GetAddressInfo.
This commit is contained in:
parent
f5b0a6b756
commit
41359f557a
3 changed files with 44 additions and 18 deletions
|
@ -322,6 +322,29 @@ namespace
|
|||
return my::between_s(r.first, r.second, m_scale);
|
||||
}
|
||||
|
||||
static void GetReadableTypes(search::Engine const * eng, int8_t lang,
|
||||
feature::TypesHolder const & types,
|
||||
Framework::AddressInfo & info)
|
||||
{
|
||||
// add types for POI
|
||||
size_t const count = types.Size();
|
||||
for (size_t i = 0; i < count; ++i)
|
||||
{
|
||||
uint32_t type = types[i];
|
||||
|
||||
string s;
|
||||
if (!eng->GetNameByType(type, lang, s))
|
||||
{
|
||||
// Try to use common type truncation if no match found.
|
||||
ftype::TruncValue(type, 2);
|
||||
(void)eng->GetNameByType(type, lang, s);
|
||||
}
|
||||
|
||||
if (!s.empty())
|
||||
info.m_types.push_back(s);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
DoGetAddressInfo(m2::PointD const & pt, int scale, TypeChecker const & checker,
|
||||
double (&arrRadius) [3])
|
||||
|
@ -357,13 +380,7 @@ namespace
|
|||
{
|
||||
info.m_name = m_cont[i].m_name;
|
||||
|
||||
// add types for POI
|
||||
size_t const count = m_cont[i].m_types.Size();
|
||||
info.m_types.resize(count);
|
||||
for (size_t j = 0; j < count; ++j)
|
||||
{
|
||||
eng->GetNameByType(m_cont[i].m_types[j], lang, info.m_types[j]);
|
||||
}
|
||||
GetReadableTypes(eng, lang, m_cont[i].m_types, info);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -536,6 +553,7 @@ string Framework::AddressInfo::FormatTypes() const
|
|||
string result;
|
||||
for (size_t i = 0; i < m_types.size(); ++i)
|
||||
{
|
||||
ASSERT ( !m_types.empty(), () );
|
||||
if (!result.empty())
|
||||
result += ' ';
|
||||
result += m_types[i];
|
||||
|
|
|
@ -340,34 +340,37 @@ namespace qt
|
|||
else if (e->button() == Qt::RightButton)
|
||||
{
|
||||
// show feature types
|
||||
QPoint const & pt = e->pos();
|
||||
QPoint const & qp = e->pos();
|
||||
m2::PointD const pt(qp.x(), qp.y());
|
||||
QMenu menu;
|
||||
|
||||
// Get POI under cursor or nearest address by point.
|
||||
Framework::AddressInfo info;
|
||||
m2::PointD dummy;
|
||||
if (m_framework->GetVisiblePOI(m2::PointD(pt.x(), pt.y()), dummy, info))
|
||||
if (m_framework->GetVisiblePOI(pt, dummy, info))
|
||||
{
|
||||
add_string(menu, "POI");
|
||||
}
|
||||
else
|
||||
{
|
||||
vector<string> types;
|
||||
m_framework->GetFeatureTypes(m2::PointD(pt.x(), pt.y()), types);
|
||||
|
||||
for (size_t i = 0; i < types.size(); ++i)
|
||||
add_string(menu, types[i]);
|
||||
|
||||
m_framework->GetAddressInfo(m_framework->PtoG(m2::PointD(pt.x(), pt.y())), info);
|
||||
m_framework->GetAddressInfo(m_framework->PtoG(pt), info);
|
||||
}
|
||||
|
||||
// Get feature types under cursor.
|
||||
vector<string> types;
|
||||
m_framework->GetFeatureTypes(pt, types);
|
||||
for (size_t i = 0; i < types.size(); ++i)
|
||||
add_string(menu, types[i]);
|
||||
|
||||
(void)menu.addSeparator();
|
||||
|
||||
// Format address and types.
|
||||
if (!info.m_name.empty())
|
||||
add_string(menu, info.m_name);
|
||||
add_string(menu, info.FormatAddress());
|
||||
add_string(menu, info.FormatTypes());
|
||||
|
||||
menu.exec(pt);
|
||||
menu.exec(qp);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -374,9 +374,14 @@ uint32_t PreResult2::GetBestType(set<uint32_t> const * pPrefferedTypes) const
|
|||
}
|
||||
|
||||
if (t == 0)
|
||||
{
|
||||
t = m_types.GetBestType();
|
||||
|
||||
ftype::TruncValue(t, 2);
|
||||
// Do type truncate (2-level is enough for search results) only for
|
||||
// non-preffered types (types from categories leave original).
|
||||
ftype::TruncValue(t, 2);
|
||||
}
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue