Fixed api marks style

This commit is contained in:
Roman Kuznetsov 2018-05-11 16:25:31 +03:00 committed by Aleksandr Zatsepin
parent dbafbaaaff
commit 076ec12e60
4 changed files with 46 additions and 50 deletions

View file

@ -2,68 +2,68 @@
#include "base/logging.hpp"
#include <map>
namespace style
{
std::map<std::string, std::string> kStyleToColor = {
{"placemark-red", "BookmarkRed"},
{"placemark-blue", "BookmarkBlue"},
{"placemark-purple", "BookmarkPurple"},
{"placemark-yellow", "BookmarkYellow"},
{"placemark-pink", "BookmarkPink"},
{"placemark-brown", "BookmarkBrown"},
{"placemark-green", "BookmarkGreen"},
{"placemark-orange", "BookmarkOrange"}
};
char const * kSupportedColors[] = {"placemark-red", "placemark-blue", "placemark-purple",
"placemark-yellow", "placemark-pink", "placemark-brown",
"placemark-green", "placemark-orange", "placemark-hotel"};
string GetSupportedStyle(string const & s, string const & context, string const & fallback)
std::string GetSupportedStyle(std::string const & style)
{
if (s.empty())
return fallback;
for (size_t i = 0; i < ARRAY_SIZE(kSupportedColors); ++i)
{
if (s == kSupportedColors[i])
return s;
}
return fallback;
auto const it = kStyleToColor.find(style);
if (it == kStyleToColor.cend())
return "BookmarkGreen";
return it->second;
}
string GetDefaultStyle() { return kSupportedColors[0]; }
} // style
} // style
ApiMarkPoint::ApiMarkPoint(m2::PointD const & ptOrg)
: UserMark(ptOrg, UserMark::Type::API)
{}
ApiMarkPoint::ApiMarkPoint(string const & name, string const & id, string const & style,
ApiMarkPoint::ApiMarkPoint(std::string const & name, std::string const & id, std::string const & style,
m2::PointD const & ptOrg)
: UserMark(ptOrg, UserMark::Type::API),
m_name(name),
m_id(id),
m_style(style)
: UserMark(ptOrg, UserMark::Type::API)
, m_name(name)
, m_id(id)
, m_style(style)
{}
drape_ptr<df::UserPointMark::SymbolNameZoomInfo> ApiMarkPoint::GetSymbolNames() const
{
auto const name = m_style.empty() ? "api-result" : m_style;
//TODO: use its own icon.
auto symbol = make_unique_dp<SymbolNameZoomInfo>();
symbol->insert(std::make_pair(1 /* zoomLevel */, name));
symbol->insert(std::make_pair(1 /* zoomLevel */, "searchbooking-default-s"));
return symbol;
}
m2::PointD ApiMarkPoint::GetPixelOffset() const
df::ColorConstant ApiMarkPoint::GetColorConstant() const
{
return m_style.empty() ? m2::PointD(0.0, 0.0) : m2::PointD(0.0, 3.0);
return m_style;
}
void ApiMarkPoint::SetName(string const & name)
void ApiMarkPoint::SetName(std::string const & name)
{
SetDirty();
m_name = name;
}
void ApiMarkPoint::SetApiID(string const & id)
void ApiMarkPoint::SetApiID(std::string const & id)
{
SetDirty();
m_id = id;
}
void ApiMarkPoint::SetStyle(string const & style)
void ApiMarkPoint::SetStyle(std::string const & style)
{
SetDirty();
m_style = style;

View file

@ -5,40 +5,36 @@
#include "geometry/point2d.hpp"
#include "std/string.hpp"
#include <string>
namespace style
{
// Fixes icons which are not supported by MapsWithMe.
string GetSupportedStyle(string const & s, string const & context, string const & fallback);
// Default icon.
string GetDefaultStyle();
} // style
std::string GetSupportedStyle(std::string const & style);
} // style
class ApiMarkPoint : public UserMark
{
public:
ApiMarkPoint(m2::PointD const & ptOrg);
ApiMarkPoint(string const & name, string const & id, string const & style,
ApiMarkPoint(string const & name, std::string const & id, std::string const & style,
m2::PointD const & ptOrg);
drape_ptr<SymbolNameZoomInfo> GetSymbolNames() const override;
m2::PointD GetPixelOffset() const override;
df::ColorConstant GetColorConstant() const override;
string const & GetName() const { return m_name; }
void SetName(string const & name);
std::string const & GetName() const { return m_name; }
void SetName(std::string const & name);
string const & GetApiID() const { return m_id; }
void SetApiID(string const & id);
std::string const & GetApiID() const { return m_id; }
void SetApiID(std::string const & id);
void SetStyle(string const & style);
string const & GetStyle() const { return m_style; }
void SetStyle(std::string const & style);
std::string const & GetStyle() const { return m_style; }
private:
string m_name;
string m_id;
string m_style;
std::string m_name;
std::string m_id;
std::string m_style;
};

View file

@ -200,7 +200,7 @@ ParsedMapApi::ParsingResult ParsedMapApi::Parse(Uri const & uri)
auto * mark = editSession.CreateUserMark<ApiMarkPoint>(glPoint);
mark->SetName(p.m_name);
mark->SetApiID(p.m_id);
mark->SetStyle(style::GetSupportedStyle(p.m_style, p.m_name, ""));
mark->SetStyle(style::GetSupportedStyle(p.m_style));
}
return ParsingResult::Map;

View file

@ -67,7 +67,7 @@ DebugMarkPoint::DebugMarkPoint(const m2::PointD & ptOrg)
drape_ptr<df::UserPointMark::SymbolNameZoomInfo> DebugMarkPoint::GetSymbolNames() const
{
auto symbol = make_unique_dp<SymbolNameZoomInfo>();
symbol->insert(std::make_pair(1 /* zoomLevel */, "api-result"));
symbol->insert(std::make_pair(1 /* zoomLevel */, "non-found-search-result"));
return symbol;
}