[api] Added zoom level support, minor renamings

This commit is contained in:
Alex Zolotarev 2013-06-04 22:36:05 +03:00 committed by Alex Zolotarev
parent 75c3950888
commit 5d09ef6a44
4 changed files with 60 additions and 29 deletions

View file

@ -465,8 +465,8 @@ public:
void MapApiSetUriAndParse(string const & url);
bool GetMapApiPoint(m2::PointD const & pxPoint, url_scheme::ApiPoint & point);
vector<url_scheme::ApiPoint> const & GetMapApiPoints() { return m_ParsedMapApi.GetPoints(); }
void ClearMapApiPoints() { m_ParsedMapApi.Clear(); }
int GetMapApiVersion() const { return m_ParsedMapApi.GetApiversion(); }
void ClearMapApiPoints() { m_ParsedMapApi.Reset(); }
int GetMapApiVersion() const { return m_ParsedMapApi.GetApiVersion(); }
string const & GetMapApiAppTitle() const { return m_ParsedMapApi.GetAppTitle(); }
string const & GetMapApiBackUrl() const { return m_ParsedMapApi.GetGlobalBackUrl(); }
m2::RectD GetMapApiRect() const { return m_ParsedMapApi.GetRect(); }

View file

@ -133,23 +133,23 @@ UNIT_TEST(VersionTest)
{
{
ParsedMapApi api(Uri("mwm://map?ll=1,2&v=1&n=PointName"));
TEST_EQUAL(api.GetApiversion(), 1, ());
TEST_EQUAL(api.GetApiVersion(), 1, ());
}
{
ParsedMapApi api(Uri("mwm://map?ll=1,2&v=kotik&n=PointName"));
TEST_EQUAL(api.GetApiversion(), 0, ());
TEST_EQUAL(api.GetApiVersion(), 0, ());
}
{
ParsedMapApi api(Uri("mwm://map?ll=1,2&v=APacanyVoobsheKotjata&n=PointName"));
TEST_EQUAL(api.GetApiversion(), 0, ());
TEST_EQUAL(api.GetApiVersion(), 0, ());
}
{
ParsedMapApi api(Uri("mwm://map?ll=1,2&n=PointName"));
TEST_EQUAL(api.GetApiversion(), 0, ());
TEST_EQUAL(api.GetApiVersion(), 0, ());
}
{
ParsedMapApi api(Uri("mwm://map?v=666&ll=1,2&n=PointName"));
TEST_EQUAL(api.GetApiversion(), 666, ());
ParsedMapApi api(Uri("mwm://map?V=666&ll=1,2&n=PointName"));
TEST_EQUAL(api.GetApiVersion(), 666, ());
}
}
@ -259,7 +259,7 @@ void generateRandomTest(size_t numberOfPoints, size_t stringLength)
TEST_EQUAL(points[i].m_title, vect[i].m_title, ());
TEST_EQUAL(points[i].m_url, vect[i].m_url, ());
}
TEST_EQUAL(api.GetApiversion(), 1, ());
TEST_EQUAL(api.GetApiVersion(), 1, ());
}
}
@ -273,3 +273,17 @@ UNIT_TEST(StressTestRandomTest)
{
generateRandomTest(10000, 100);
}
UNIT_TEST(MWMApiZoomLevelTest)
{
m2::RectD const r1 = ParsedMapApi(Uri("mwm://map?ll=0,0")).GetRect();
m2::RectD const r2 = ParsedMapApi(Uri("mwm://map?z=14.5&ll=0,0")).GetRect();
TEST_NOT_EQUAL(r1, r2, ());
m2::RectD const r3 = ParsedMapApi(Uri("mwm://map?ll=0,0&z=14")).GetRect();
TEST_NOT_EQUAL(r2, r3, ());
TEST_NOT_EQUAL(r1, r3, ());
m2::RectD const rEqualToR3 = ParsedMapApi(Uri("mwm://map?ll=0,0&z=14.000")).GetRect();
TEST_EQUAL(r3, rEqualToR3, ());
m2::RectD const rEqualToR1 = ParsedMapApi(Uri("mwm://map?ll=0,0&z=-23.43")).GetRect();
TEST_EQUAL(r1, rEqualToR1, ());
}

View file

@ -1,6 +1,7 @@
#include "mwm_url.hpp"
#include "../indexer/mercator.hpp"
#include "../indexer/scales.hpp"
#include "../coding/uri.hpp"
@ -21,20 +22,19 @@ bool IsInvalidApiPoint(ApiPoint const & p) { return p.m_lat == INVALID_LAT_VALUE
} // unnames namespace
ParsedMapApi::ParsedMapApi():m_id(0)
{}
ParsedMapApi::ParsedMapApi() : m_version(0), m_zoomLevel(0.0)
{
}
ParsedMapApi::ParsedMapApi(Uri const & uri):m_id(0)
ParsedMapApi::ParsedMapApi(Uri const & uri) : m_version(0), m_zoomLevel(0.0)
{
if (!Parse(uri))
{
m_points.clear();
}
Reset();
}
bool ParsedMapApi::SetUriAndParse(string const & url)
{
Clear();
Reset();
return Parse(url_scheme::Uri(url));
}
@ -55,7 +55,7 @@ bool ParsedMapApi::Parse(Uri const & uri)
return true;
}
void ParsedMapApi::AddKeyValue(string const & key, string const & value)
void ParsedMapApi::AddKeyValue(string key, string const & value)
{
strings::AsciiToLower(key);
@ -95,6 +95,11 @@ void ParsedMapApi::AddKeyValue(string const & key, string const & value)
m_points.back().m_lon = lon;
m_showRect = m2::Add(m_showRect, m2::PointD(lon, lat));
}
else if (key == "z")
{
if (!strings::to_double(value, m_zoomLevel))
m_zoomLevel = 0.0;
}
else if (key == "n")
{
if (!m_points.empty())
@ -109,11 +114,6 @@ void ParsedMapApi::AddKeyValue(string const & key, string const & value)
else
LOG(LWARNING, ("Map API: Point url with no point. 'll' should come first!"));
}
}
void ParsedMapApi::Clear()
{
m_points.clear();
else if (key == "backurl")
{
m_globalBackUrl = value;
@ -127,8 +127,23 @@ void ParsedMapApi::Clear()
{
m_appTitle = value;
}
}
void ParsedMapApi::Reset()
{
m_points.clear();
m_globalBackUrl.clear();
m_appTitle.clear();
m_id = 0;
m_version = 0;
m_showRect = m2::RectD();
m_zoomLevel = 0.0;
}
m2::RectD ParsedMapApi::GetRect() const
{
// Use zoom only for one point and ignore it for several points
if (m_zoomLevel >= 1.0 && m_points.size() == 1)
return scales::GetRectForLevel(m_zoomLevel, m_showRect.Center(), 1.0);
return m_showRect;
}

View file

@ -25,20 +25,22 @@ public:
vector<ApiPoint> const & GetPoints() const { return m_points; }
string const & GetGlobalBackUrl() const { return m_globalBackUrl; }
string const & GetAppTitle() const { return m_appTitle; }
int GetApiversion() const { return m_id; }
m2::RectD GetRect() const { return m_showRect; }
void Clear();
int GetApiVersion() const { return m_version; }
m2::RectD GetRect() const;
void Reset();
private:
bool Parse(Uri const & uri);
void AddKeyValue(string const & key, string const & value);
void AddKeyValue(string key, string const & value);
vector<ApiPoint> m_points;
string m_globalBackUrl;
string m_appTitle;
int m_id;
//Lon Lat coordinates
int m_version;
m2::RectD m_showRect;
/// Zoom level in OSM format (e.g. from 1.0 to 20.0)
/// Taken into an account when calculating GetRect(), but only if points count is == 1
double m_zoomLevel;
};
}