forked from organicmaps/organicmaps
[map] Refactored work of bookmark
This commit is contained in:
parent
989154cb73
commit
3c0bac96e9
4 changed files with 44 additions and 20 deletions
|
@ -180,14 +180,14 @@ protected:
|
|||
UserMark * AllocateUserMark(m2::PointD const & ptOrg) override;
|
||||
};
|
||||
|
||||
/// <category index, bookmark index>
|
||||
typedef pair<int, int> BookmarkAndCategory;
|
||||
inline BookmarkAndCategory MakeEmptyBookmarkAndCategory()
|
||||
struct BookmarkAndCategory
|
||||
{
|
||||
return BookmarkAndCategory(int(-1), int(-1));
|
||||
}
|
||||
BookmarkAndCategory() = default;
|
||||
BookmarkAndCategory(int bookmarkIndex, int categoryIndex) : m_bookmarkIndex(bookmarkIndex),
|
||||
m_categoryIndex(categoryIndex) {}
|
||||
|
||||
inline bool IsValid(BookmarkAndCategory const & bmc)
|
||||
{
|
||||
return (bmc.first >= 0 && bmc.second >= 0);
|
||||
}
|
||||
bool IsValid() const { return m_bookmarkIndex >= 0 && m_categoryIndex >= 0; };
|
||||
|
||||
int m_bookmarkIndex = -1;
|
||||
int m_categoryIndex = -1;
|
||||
};
|
||||
|
|
|
@ -683,8 +683,15 @@ bool Framework::DeleteBmCategory(size_t index)
|
|||
void Framework::FillBookmarkInfo(Bookmark const & bmk, BookmarkAndCategory const & bac, place_page::Info & info) const
|
||||
{
|
||||
FillPointInfo(bmk.GetPivot(), string(), info);
|
||||
info.m_countryId = m_infoGetter->GetRegionCountryId(info.GetMercator());
|
||||
|
||||
info.m_bac = bac;
|
||||
info.m_bookmarkCategoryName = GetBmCategory(bac.first)->GetName();
|
||||
BookmarkCategory * cat = GetBmCategory(bac.m_categoryIndex);
|
||||
info.m_bookmarkCategoryName = cat->GetName();
|
||||
BookmarkData const & data = static_cast<Bookmark const *>(cat->GetUserMark(bac.m_bookmarkIndex))->GetData();
|
||||
info.m_bookmarkTitle = data.GetName();
|
||||
info.m_bookmarkColorName = data.GetType();
|
||||
info.m_bookmarkDescription = data.GetDescription();
|
||||
}
|
||||
|
||||
void Framework::FillFeatureInfo(FeatureID const & fid, place_page::Info & info) const
|
||||
|
@ -801,7 +808,7 @@ void Framework::ShowBookmark(BookmarkAndCategory const & bnc)
|
|||
{
|
||||
StopLocationFollow();
|
||||
|
||||
Bookmark const * mark = static_cast<Bookmark const *>(GetBmCategory(bnc.first)->GetUserMark(bnc.second));
|
||||
Bookmark const * mark = static_cast<Bookmark const *>(GetBmCategory(bnc.m_categoryIndex)->GetUserMark(bnc.m_bookmarkIndex));
|
||||
|
||||
double scale = mark->GetScale();
|
||||
if (scale == -1.0)
|
||||
|
@ -1901,31 +1908,31 @@ bool Framework::GetFeatureByID(FeatureID const & fid, FeatureType & ft) const
|
|||
|
||||
BookmarkAndCategory Framework::FindBookmark(UserMark const * mark) const
|
||||
{
|
||||
BookmarkAndCategory empty = MakeEmptyBookmarkAndCategory();
|
||||
BookmarkAndCategory result = empty;
|
||||
BookmarkAndCategory empty;
|
||||
BookmarkAndCategory result;
|
||||
ASSERT_LESS_OR_EQUAL(GetBmCategoriesCount(), numeric_limits<int>::max(), ());
|
||||
for (size_t i = 0; i < GetBmCategoriesCount(); ++i)
|
||||
{
|
||||
if (mark->GetContainer() == GetBmCategory(i))
|
||||
{
|
||||
result.first = static_cast<int>(i);
|
||||
result.m_categoryIndex = static_cast<int>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT(result.first != empty.first, ());
|
||||
BookmarkCategory const * cat = GetBmCategory(result.first);
|
||||
ASSERT(result.m_categoryIndex != empty.m_categoryIndex, ());
|
||||
BookmarkCategory const * cat = GetBmCategory(result.m_categoryIndex);
|
||||
ASSERT_LESS_OR_EQUAL(cat->GetUserMarkCount(), numeric_limits<int>::max(), ());
|
||||
for (size_t i = 0; i < cat->GetUserMarkCount(); ++i)
|
||||
{
|
||||
if (mark == cat->GetUserMark(i))
|
||||
{
|
||||
result.second = static_cast<int>(i);
|
||||
result.m_bookmarkIndex = static_cast<int>(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT(result != empty, ());
|
||||
ASSERT(result.IsValid(), ());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include "indexer/feature_utils.hpp"
|
||||
#include "indexer/osm_editor.hpp"
|
||||
|
||||
#include "platform/measurement_utils.hpp"
|
||||
|
||||
namespace place_page
|
||||
{
|
||||
char const * const Info::kSubtitleSeparator = " • ";
|
||||
|
@ -12,7 +14,7 @@ char const * const Info::kEmptyRatingSymbol = "-";
|
|||
char const * const Info::kPricingSymbol = "$";
|
||||
|
||||
bool Info::IsFeature() const { return m_featureID.IsValid(); }
|
||||
bool Info::IsBookmark() const { return m_bac != MakeEmptyBookmarkAndCategory(); }
|
||||
bool Info::IsBookmark() const { return m_bac.IsValid(); }
|
||||
bool Info::IsMyPosition() const { return m_isMyPosition; }
|
||||
bool Info::IsSponsoredHotel() const { return m_isSponsoredHotel; }
|
||||
bool Info::IsHotel() const { return m_isHotel; }
|
||||
|
@ -103,6 +105,12 @@ string Info::FormatStars() const
|
|||
return stars;
|
||||
}
|
||||
|
||||
string Info::GetFormattedCoordinate(bool isDMS) const
|
||||
{
|
||||
auto const ll = GetLatLon();
|
||||
return isDMS ? measurement_utils::FormatLatLon(ll.lat, ll.lon) : measurement_utils::FormatLatLonAsDMS(ll.lat, ll.lon, 2);
|
||||
}
|
||||
|
||||
string Info::GetCustomName() const { return m_customName; }
|
||||
BookmarkAndCategory Info::GetBookmarkAndCategory() const { return m_bac; }
|
||||
string Info::GetBookmarkCategoryName() const { return m_bookmarkCategoryName; }
|
||||
|
|
|
@ -54,6 +54,9 @@ public:
|
|||
/// @returns empty string or GetStars() count of ★ symbol.
|
||||
string FormatStars() const;
|
||||
|
||||
/// @returns coordinate in DMS format if isDMS is true
|
||||
string GetFormattedCoordinate(bool isDMS) const;
|
||||
|
||||
string GetCustomName() const;
|
||||
BookmarkAndCategory GetBookmarkAndCategory() const;
|
||||
string GetBookmarkCategoryName() const;
|
||||
|
@ -72,9 +75,15 @@ public:
|
|||
/// Comes from API, shared links etc.
|
||||
string m_customName;
|
||||
/// If not empty, bookmark is bound to this place page.
|
||||
BookmarkAndCategory m_bac = MakeEmptyBookmarkAndCategory();
|
||||
BookmarkAndCategory m_bac;
|
||||
/// Bookmark category name. Empty, if it's not bookmark;
|
||||
string m_bookmarkCategoryName;
|
||||
/// Bookmark title. Empty, if it's not bookmark;
|
||||
string m_bookmarkTitle;
|
||||
/// Bookmark color name. Empty, if it's not bookmark;
|
||||
string m_bookmarkColorName;
|
||||
/// Bookmark description. Empty, if it's not bookmark;
|
||||
string m_bookmarkDescription;
|
||||
/// Api ID passed for the selected object. It's automatically included in api url below.
|
||||
string m_apiId;
|
||||
/// [Deep] link to open when "Back" button is pressed in a Place Page.
|
||||
|
|
Loading…
Add table
Reference in a new issue