forked from organicmaps/organicmaps
Add Framework::GetBookmark for touch point.
This commit is contained in:
parent
4304679d8c
commit
88c21a3626
3 changed files with 52 additions and 0 deletions
|
@ -205,6 +205,32 @@ void Framework::GetBookmark(size_t index, Bookmark & bm) const
|
|||
bm = *it;
|
||||
}
|
||||
|
||||
size_t Framework::GetBookmark(m2::PointD pt, Bookmark & bm) const
|
||||
{
|
||||
// Get the global rect of touching area.
|
||||
int const sm = 20 * GetPlatform().VisualScale();
|
||||
m2::RectD rect(PtoG(m2::PointD(pt.x - sm, pt.y - sm)), PtoG(m2::PointD(pt.x + sm, pt.y + sm)));
|
||||
|
||||
size_t bestInd = static_cast<size_t>(-1);
|
||||
double minD = numeric_limits<double>::max();
|
||||
|
||||
size_t ind = 0;
|
||||
for (list<Bookmark>::const_iterator it = m_bookmarks.begin(); it != m_bookmarks.end(); ++it, ++ind)
|
||||
{
|
||||
if (rect.IsPointInside(it->GetOrg()))
|
||||
{
|
||||
double const d = rect.Center().SquareLength(it->GetOrg());
|
||||
if (d < minD)
|
||||
{
|
||||
bm = *it;
|
||||
bestInd = ind;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bestInd;
|
||||
}
|
||||
|
||||
void Framework::RemoveBookmark(size_t index)
|
||||
{
|
||||
if (index >= m_bookmarks.size())
|
||||
|
|
|
@ -127,6 +127,12 @@ public:
|
|||
void AddBookmark(m2::PointD const & pt, string const & name);
|
||||
inline size_t BookmarksCount() const { return m_bookmarks.size(); }
|
||||
void GetBookmark(size_t index, Bookmark & bm) const;
|
||||
|
||||
/// Get bookmark by touch.
|
||||
/// @param[in] pixPt Coordinates of touch point in pixels.
|
||||
/// @return Index of bookmark (-1, if bookmark wasn't found).
|
||||
size_t GetBookmark(m2::PointD pixPt, Bookmark & bm) const;
|
||||
|
||||
void RemoveBookmark(size_t index);
|
||||
void ClearBookmarks();
|
||||
|
||||
|
|
|
@ -99,3 +99,23 @@ UNIT_TEST(Bookmarks_ExportKML)
|
|||
|
||||
CheckBookmarks(fm);
|
||||
}
|
||||
|
||||
UNIT_TEST(Bookmarks_Getting)
|
||||
{
|
||||
Framework fm;
|
||||
fm.OnSize(800, 400);
|
||||
fm.ShowRect(m2::RectD(0, 0, 80, 40));
|
||||
|
||||
m2::PointD const pixC = fm.GtoP(m2::PointD(40, 20));
|
||||
|
||||
// This is not correct because Framework::OnSize doesn't work until SetRenderPolicy is called.
|
||||
//TEST(m2::AlmostEqual(m2::PointD(400, 200), pixC), (pixC));
|
||||
|
||||
fm.AddBookmark(m2::PointD(38, 20), "1");
|
||||
fm.AddBookmark(m2::PointD(41, 20), "2");
|
||||
fm.AddBookmark(m2::PointD(41, 40), "3");
|
||||
|
||||
Bookmark bm;
|
||||
TEST_EQUAL(fm.GetBookmark(pixC, bm), 1, ());
|
||||
TEST_EQUAL(bm.GetName(), "2", ());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue