forked from organicmaps/organicmaps
[bookmarks] Added description field
This commit is contained in:
parent
8bd758a698
commit
990ad2780c
3 changed files with 31 additions and 35 deletions
|
@ -128,6 +128,7 @@ namespace bookmark_impl
|
|||
|
||||
string m_name;
|
||||
string m_type;
|
||||
string m_description;
|
||||
|
||||
m2::PointD m_org;
|
||||
double m_scale;
|
||||
|
@ -135,6 +136,7 @@ namespace bookmark_impl
|
|||
void Reset()
|
||||
{
|
||||
m_name.clear();
|
||||
m_description.clear();
|
||||
m_org = m2::PointD(-1000, -1000);
|
||||
m_type.clear();
|
||||
m_scale = -1.0;
|
||||
|
@ -170,31 +172,6 @@ namespace bookmark_impl
|
|||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
void TryResolveName(string const & s)
|
||||
{
|
||||
if (m_name.empty())
|
||||
{
|
||||
// "CosmosVDC" has only description in placemark.
|
||||
size_t i1 = s.find("<a");
|
||||
if (i1 != string::npos)
|
||||
{
|
||||
i1 = s.find(">", i1);
|
||||
if (i1 != string::npos)
|
||||
{
|
||||
++i1;
|
||||
size_t const i2 = s.find("</a>", i1);
|
||||
if (i2 != string::npos)
|
||||
{
|
||||
m_name = s.substr(i1, i2-i1);
|
||||
strings::Trim(m_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public:
|
||||
KMLParser(BookmarkCategory & cat) : m_category(cat)
|
||||
{
|
||||
|
@ -215,7 +192,7 @@ namespace bookmark_impl
|
|||
|
||||
if (tag == "Placemark" && MakeValid())
|
||||
{
|
||||
m_category.AddBookmarkImpl(Bookmark(m_org, m_name, m_type), m_scale);
|
||||
m_category.AddBookmarkImpl(Bookmark(m_org, m_name, m_type, m_description), m_scale);
|
||||
Reset();
|
||||
}
|
||||
m_tags.pop_back();
|
||||
|
@ -242,8 +219,11 @@ namespace bookmark_impl
|
|||
{
|
||||
if (currTag == "name")
|
||||
m_name = value;
|
||||
//else if (currTag == "description")
|
||||
// TryResolveName(value);
|
||||
else if (currTag == "description")
|
||||
{
|
||||
LOG(LINFO, (value));
|
||||
m_description = value;
|
||||
}
|
||||
else if (currTag == "styleUrl")
|
||||
m_type = GetSupportedBMType(value);
|
||||
}
|
||||
|
@ -375,12 +355,22 @@ void BookmarkCategory::SaveToKML(ostream & s)
|
|||
{
|
||||
Bookmark const * bm = m_bookmarks[i];
|
||||
s << " <Placemark>\n";
|
||||
|
||||
// Use CDATA if we have special symbols in the name
|
||||
s << " <name>";
|
||||
if (ShouldUseCDATA(bm->GetName()))
|
||||
s << " <name><![CDATA[" << bm->GetName() << "]]></name>\n";
|
||||
s << "<![CDATA[" << bm->GetName() << "]]>";
|
||||
else
|
||||
s << " <name>" << bm->GetName() << "</name>\n";
|
||||
s << bm->GetName();
|
||||
s << "</name>\n";
|
||||
|
||||
if (!bm->GetDescription().empty())
|
||||
{
|
||||
s << " <description>";
|
||||
if (ShouldUseCDATA(bm->GetDescription()))
|
||||
s << "<![CDATA[" << bm->GetDescription() << "]]>";
|
||||
else
|
||||
s << bm->GetDescription();
|
||||
s << "</description>\n";
|
||||
}
|
||||
|
||||
s << " <styleUrl>#" << bm->GetType() << "</styleUrl>\n"
|
||||
<< " <Point>\n"
|
||||
|
|
|
@ -14,18 +14,21 @@ class Bookmark
|
|||
{
|
||||
m2::PointD m_org;
|
||||
string m_name;
|
||||
string m_description;
|
||||
string m_type; ///< Now it stores bookmark color (category style).
|
||||
double m_scale; ///< Viewport scale. -1.0 - is a default value (no scale set).
|
||||
|
||||
public:
|
||||
Bookmark() {}
|
||||
Bookmark(m2::PointD const & org, string const & name, string const & type)
|
||||
: m_org(org), m_name(name), m_type(type), m_scale(-1.0)
|
||||
Bookmark(m2::PointD const & org, string const & name, string const & type,
|
||||
string const & description = string())
|
||||
: m_org(org), m_name(name), m_description(description), m_type(type), m_scale(-1.0)
|
||||
{
|
||||
}
|
||||
|
||||
m2::PointD const & GetOrg() const { return m_org; }
|
||||
string const & GetName() const { return m_name; }
|
||||
string const & GetDescription() const { return m_description; }
|
||||
/// @return Now its a bookmark color.
|
||||
string const & GetType() const { return m_type; }
|
||||
m2::RectD GetViewport() const { return m2::RectD(m_org, m_org); }
|
||||
|
|
|
@ -109,10 +109,12 @@ char const * kmlString =
|
|||
Bookmark const * bm = cat.GetBookmark(0);
|
||||
TEST_EQUAL(bm->GetName(), "Nebraska", ());
|
||||
TEST_EQUAL(bm->GetType(), "placemark-red", ());
|
||||
TEST_EQUAL(bm->GetDescription(), "", ());
|
||||
|
||||
bm = cat.GetBookmark(1);
|
||||
TEST_EQUAL(bm->GetName(), "Monongahela National Forest", ());
|
||||
TEST_EQUAL(bm->GetType(), "placemark-pink", ());
|
||||
TEST_EQUAL(bm->GetDescription(), "Huttonsville, WV 26273<br>", ());
|
||||
|
||||
bm = cat.GetBookmark(2);
|
||||
m2::PointD org = bm->GetOrg();
|
||||
|
@ -120,13 +122,14 @@ char const * kmlString =
|
|||
TEST_ALMOST_EQUAL(MercatorBounds::YToLat(org.y), 53.900047, ());
|
||||
TEST_EQUAL(bm->GetName(), "From: Минск, Минская область, Беларусь", ());
|
||||
TEST_EQUAL(bm->GetType(), "placemark-blue", ());
|
||||
TEST_EQUAL(bm->GetDescription(), "", ());
|
||||
|
||||
bm = cat.GetBookmark(3);
|
||||
org = bm->GetOrg();
|
||||
TEST_ALMOST_EQUAL(MercatorBounds::XToLon(org.x), 27.551532, ());
|
||||
TEST_ALMOST_EQUAL(MercatorBounds::YToLat(org.y), 53.89306, ());
|
||||
TEST_EQUAL(bm->GetName(), "<MWM & Sons>", ());
|
||||
|
||||
TEST_EQUAL(bm->GetDescription(), "Amps & <brackets>", ());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue