forked from organicmaps/organicmaps
[ios] Replace bookmark with similar coordinates when adding new one
This commit is contained in:
parent
4528100f65
commit
728f25600b
2 changed files with 40 additions and 7 deletions
|
@ -17,6 +17,19 @@
|
|||
|
||||
void BookmarkCategory::AddBookmark(Bookmark const & bm)
|
||||
{
|
||||
// Replace existing bookmark if coordinates are (almost) the same
|
||||
double const eps = my::sq(1.0 * MercatorBounds::degreeInMetres);
|
||||
for (size_t i = 0; i < m_bookmarks.size(); ++i)
|
||||
{
|
||||
Bookmark const * oldBookmark = m_bookmarks[i];
|
||||
if (eps >= bm.GetOrg().SquareLength(oldBookmark->GetOrg()))
|
||||
{
|
||||
m_bookmarks[i] = new Bookmark(bm);
|
||||
delete oldBookmark;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
m_bookmarks.push_back(new Bookmark(bm));
|
||||
}
|
||||
|
||||
|
|
|
@ -177,17 +177,37 @@ UNIT_TEST(Bookmarks_Getting)
|
|||
fm.AddBookmark("cat3", Bookmark(m2::PointD(41, 40), "3", "placemark-red"));
|
||||
|
||||
BookmarkAndCategory res = fm.GetBookmark(pixC, 1.0);
|
||||
TEST_NOT_EQUAL(res.second, -1, ());
|
||||
TEST(!res.first.empty(), ());
|
||||
TEST_EQUAL(res.second, 1, ());
|
||||
TEST(IsValid(res), ());
|
||||
TEST_EQUAL(res.second, 0, ());
|
||||
TEST_EQUAL(res.first, "cat2" , ());
|
||||
|
||||
res = fm.GetBookmark(m2::PointD(0, 0));
|
||||
TEST(res.first.empty(), ());
|
||||
TEST_EQUAL(res.second, -1, ());
|
||||
TEST(!IsValid(res), ());
|
||||
res = fm.GetBookmark(m2::PointD(800, 400));
|
||||
TEST(res.first.empty(), ());
|
||||
TEST_EQUAL(res.second, -1, ());
|
||||
TEST(!IsValid(res), ());
|
||||
|
||||
res = fm.GetBookmark(m2::PointD(41, 40));
|
||||
TEST(IsValid(res), ());
|
||||
TEST_EQUAL(res.first, "cat3", ());
|
||||
Bookmark const * bm = fm.GetBmCategory(res.first)->GetBookmark(res.second);
|
||||
TEST_EQUAL(bm->GetName(), "3", ());
|
||||
TEST_EQUAL(bm->GetType(), "placemark-red", ());
|
||||
|
||||
// This one should replace previous bookmark
|
||||
fm.AddBookmark("cat3", Bookmark(m2::PointD(41, 40), "4", "placemark-blue"));
|
||||
|
||||
res = fm.GetBookmark(m2::PointD(41, 40));
|
||||
TEST(IsValid(res), ());
|
||||
BookmarkCategory * cat = fm.GetBmCategory(res.first);
|
||||
TEST(cat, ());
|
||||
bm = cat->GetBookmark(res.second);
|
||||
TEST_EQUAL(bm->GetName(), "4", ());
|
||||
TEST_EQUAL(bm->GetType(), "placemark-blue", ());
|
||||
|
||||
TEST_EQUAL(cat->GetBookmarksCount(), 1, ());
|
||||
|
||||
cat->DeleteBookmark(0);
|
||||
TEST_EQUAL(cat->GetBookmarksCount(), 0, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(Bookmarks_AddressInfo)
|
||||
|
|
Loading…
Add table
Reference in a new issue