forked from organicmaps/organicmaps
[search] Take into account empty My Position in distance calculating
This commit is contained in:
parent
5c717bb9ed
commit
578010dcc0
6 changed files with 40 additions and 28 deletions
|
@ -21,8 +21,7 @@ namespace impl
|
|||
|
||||
IntermediateResult::IntermediateResult(m2::RectD const & viewportRect, m2::PointD const & pos,
|
||||
FeatureType const & f,
|
||||
string const & displayName,
|
||||
string const & fileName)
|
||||
string const & displayName, string const & fileName)
|
||||
: m_types(f),
|
||||
m_str(displayName),
|
||||
m_rect(f.GetLimitRect(-2)),
|
||||
|
@ -39,12 +38,8 @@ IntermediateResult::IntermediateResult(m2::RectD const & viewportRect, m2::Point
|
|||
m_region.SetPoint(f.GetCenter());
|
||||
}
|
||||
|
||||
// get common params
|
||||
m2::PointD const center = m_rect.Center();
|
||||
m_distance = ResultDistance(pos, center);
|
||||
m_direction = ResultDirection(pos, center);
|
||||
m_searchRank = feature::GetSearchRank(m_types, center, f.GetPopulation());
|
||||
m_viewportDistance = ViewportDistance(viewportRect, center);
|
||||
CalcCommonParams(viewportRect, pos);
|
||||
m_searchRank = feature::GetSearchRank(m_types, m_rect.Center(), f.GetPopulation());
|
||||
}
|
||||
|
||||
IntermediateResult::IntermediateResult(m2::RectD const & viewportRect, m2::PointD const & pos,
|
||||
|
@ -54,17 +49,35 @@ IntermediateResult::IntermediateResult(m2::RectD const & viewportRect, m2::Point
|
|||
MercatorBounds::LonToX(lon + precision), MercatorBounds::LatToY(lat + precision)),
|
||||
m_resultType(RESULT_LATLON), m_searchRank(0)
|
||||
{
|
||||
// get common params
|
||||
m2::PointD const center = m_rect.Center();
|
||||
m_distance = ResultDistance(pos, center);
|
||||
m_direction = ResultDirection(pos, center);
|
||||
m_viewportDistance = ViewportDistance(viewportRect, center);
|
||||
CalcCommonParams(viewportRect, pos);
|
||||
|
||||
// get region info
|
||||
m_region.SetPoint(m2::PointD(MercatorBounds::LonToX(lon),
|
||||
MercatorBounds::LatToY(lat)));
|
||||
}
|
||||
|
||||
void IntermediateResult::CalcCommonParams(m2::RectD const & viewportRect, m2::PointD const & pos)
|
||||
{
|
||||
m2::PointD const center = m_rect.Center();
|
||||
|
||||
// Check if point is valid (see Query::empty_pos_value).
|
||||
if (pos.x > -500 && pos.y > -500)
|
||||
{
|
||||
ASSERT ( my::between_s(-180.0, 180.0, pos.x), (pos.x) );
|
||||
ASSERT ( my::between_s(-180.0, 180.0, pos.y), (pos.y) );
|
||||
|
||||
m_distance = ResultDistance(pos, center);
|
||||
m_direction = ResultDirection(pos, center);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_distance = -1.0;
|
||||
m_direction = -1.0;
|
||||
}
|
||||
|
||||
m_viewportDistance = ViewportDistance(viewportRect, center);
|
||||
}
|
||||
|
||||
IntermediateResult::IntermediateResult(string const & name, int penalty)
|
||||
: m_str(name), m_completionString(name + " "),
|
||||
// Categories should always be first
|
||||
|
|
|
@ -24,6 +24,8 @@ namespace impl
|
|||
|
||||
class IntermediateResult
|
||||
{
|
||||
void CalcCommonParams(m2::RectD const & viewportRect, m2::PointD const & pos);
|
||||
|
||||
public:
|
||||
enum ResultType
|
||||
{
|
||||
|
|
|
@ -20,15 +20,7 @@ namespace search
|
|||
|
||||
inline void SetNearMeMode(bool b)
|
||||
{
|
||||
if (b)
|
||||
{
|
||||
m_mode = NearMe;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_mode = All;
|
||||
m_validPos = false;
|
||||
}
|
||||
m_mode = (b ? NearMe : All);
|
||||
}
|
||||
|
||||
inline void SetPosition(double lat, double lon)
|
||||
|
@ -40,6 +32,7 @@ namespace search
|
|||
|
||||
inline bool IsNearMeMode() const
|
||||
{
|
||||
// this mode is valid only with correct My Position
|
||||
return (m_mode == NearMe && m_validPos);
|
||||
}
|
||||
|
||||
|
|
|
@ -134,7 +134,10 @@ void Engine::SearchAsync()
|
|||
// Initialize query.
|
||||
bool const isNearMe = params.IsNearMeMode();
|
||||
m_pQuery->SetViewport(isNearMe ? GetViewportRect(params.m_lat, params.m_lon, 20000) : viewport);
|
||||
m_pQuery->SetPosition(isNearMe ? GetViewportXY(params.m_lat, params.m_lon) : m_viewport.Center());
|
||||
if (isNearMe)
|
||||
m_pQuery->SetPosition(GetViewportXY(params.m_lat, params.m_lon));
|
||||
else
|
||||
m_pQuery->NullPosition();
|
||||
|
||||
Results res;
|
||||
try
|
||||
|
|
|
@ -35,7 +35,7 @@ Query::Query(Index const * pIndex,
|
|||
m_pInfoGetter(pInfoGetter),
|
||||
m_preferredLanguage(StringUtf8Multilang::GetLangIndex("en")),
|
||||
m_viewport(m2::RectD::GetEmptyRect()), m_viewportExtended(m2::RectD::GetEmptyRect()),
|
||||
m_position(-1000000, -1000000), // initialize as empty point
|
||||
m_position(empty_pos_value, empty_pos_value),
|
||||
m_bOffsetsCacheIsValid(false)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -48,11 +48,12 @@ public:
|
|||
~Query();
|
||||
|
||||
void SetViewport(m2::RectD const & viewport);
|
||||
inline void SetPosition(m2::PointD const & pos) { m_position = pos; }
|
||||
void SetPreferredLanguage(string const & lang);
|
||||
|
||||
inline m2::PointD GetPosition() const { return m_position; }
|
||||
inline m2::RectD GetViewport() const { return m_viewport; }
|
||||
static const int empty_pos_value = -1000;
|
||||
inline void SetPosition(m2::PointD const & pos) { m_position = pos; }
|
||||
inline void NullPosition() { m_position = m2::PointD(empty_pos_value, empty_pos_value); }
|
||||
|
||||
void SetPreferredLanguage(string const & lang);
|
||||
|
||||
void Search(string const & query, Results & res, unsigned int resultsNeeded = 10);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue