[api] Show viewport on correct zoom level in on API request.

This commit is contained in:
vng 2013-08-15 18:21:13 +03:00 committed by Alex Zolotarev
parent 59a0e39dac
commit 1269e13617
5 changed files with 53 additions and 18 deletions

View file

@ -1414,7 +1414,7 @@ bool Framework::SetViewportByURL(string const & url, url_scheme::ApiPoint & ball
{
StopLocationFollow();
// Can do better consider nav bar size
SetViewPortASync(MercatorBounds::FromLatLonRect(m_ParsedMapApi.GetLatLonRect()));
SetViewPortASync(GetMapApiViewportRect());
if (!m_ParsedMapApi.GetPoints().empty())
{
@ -1596,12 +1596,7 @@ void Framework::DrawMapApiPoints(shared_ptr<PaintEvent> const & e)
}
}
void Framework::MapApiSetUriAndParse(string const & url)
{
m_ParsedMapApi.SetUriAndParse(url);
}
//Dummy method. TODO create method that will run all layers without copy/past
/// @todo Create method that will run all layers without copy/past
bool Framework::GetMapApiPoint(m2::PointD const & pxPoint, url_scheme::ApiPoint & point)
{
int const sm = TOUCH_PIXEL_RADIUS * GetVisualScale();
@ -1630,6 +1625,24 @@ bool Framework::GetMapApiPoint(m2::PointD const & pxPoint, url_scheme::ApiPoint
return result;
}
m2::RectD Framework::GetMapApiViewportRect() const
{
double zoom;
m2::PointD center;
if (m_ParsedMapApi.GetViewport(center, zoom))
{
return m_scales.GetRectForDrawScale(zoom, center);
}
else
{
m2::RectD rect;
if (m_ParsedMapApi.GetViewportRect(rect))
return rect;
return m_scales.GetWorldRect();
}
}
string Framework::GenerateApiBackUrl(url_scheme::ApiPoint const & point)
{
string res = m_ParsedMapApi.GetGlobalBackUrl();

View file

@ -446,22 +446,21 @@ public:
string CodeGe0url(Bookmark const * bmk, bool const addName);
string CodeGe0url(double const lat, double const lon, double const zoomLevel, string const & name);
/// @name Api
//@{
private:
url_scheme::ParsedMapApi m_ParsedMapApi;
void DrawMapApiPoints(shared_ptr<PaintEvent> const & e);
void SetViewPortASync(m2::RectD const & rect);
public:
/// @name Api
//@{
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.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 GetMapApiLatLonRect() const { return m_ParsedMapApi.GetLatLonRect(); }
m2::RectD GetMapApiViewportRect() const;
bool IsValidMapApi() const { return m_ParsedMapApi.IsValid(); }
string GenerateApiBackUrl(url_scheme::ApiPoint const & point);
//@}

View file

@ -11,6 +11,7 @@
#include "../std/algorithm.hpp"
#include "../std/bind.hpp"
using namespace url_scheme;
namespace
@ -143,11 +144,26 @@ void ParsedMapApi::Reset()
m_zoomLevel = 0.0;
}
m2::RectD ParsedMapApi::GetLatLonRect() const
bool ParsedMapApi::GetViewport(m2::PointD & pt, double & zoom) 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);
{
zoom = min(static_cast<double>(scales::GetUpperComfortScale()), m_zoomLevel);
pt.x = MercatorBounds::LonToX(m_points.front().m_lon);
pt.y = MercatorBounds::LatToY(m_points.front().m_lat);
return true;
}
return m_showRect;
return false;
}
bool ParsedMapApi::GetViewportRect(m2::RectD & rect) const
{
if (m_showRect.IsValid())
{
rect = MercatorBounds::FromLatLonRect(m_showRect);
return true;
}
else
return false;
}

View file

@ -20,15 +20,22 @@ class ParsedMapApi
public:
ParsedMapApi(Uri const & uri);
ParsedMapApi();
bool SetUriAndParse(string const & url);
bool IsValid() const;
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_version; }
m2::RectD GetLatLonRect() const;
m2::RectD GetLatLonRect() const { return m_showRect; }
void Reset();
/// @name Used in settings map viewport after invoking API.
//@{
bool GetViewport(m2::PointD & pt, double & zoom) const;
bool GetViewportRect(m2::RectD & rect) const;
//@}
private:
bool Parse(Uri const & uri);
void AddKeyValue(string key, string const & value);
@ -39,7 +46,7 @@ private:
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
/// Taken into an account when calculating viewport rect, but only if points count is == 1
double m_zoomLevel;
};

View file

@ -49,7 +49,7 @@ namespace
{ "100 yd", 100 },
{ "200 yd", 200 },
{ "500 yd", 500 },
{ "0.5 mi", 0.5 * 1760 },
{ "0.5 mi", 1760 / 2 },
{ "1 mi", 1760 },
{ "2 mi", 2 * 1760 },
{ "5 mi", 5 * 1760 },