From 1269e13617f552b6404efca5bbf3c4b2107349f8 Mon Sep 17 00:00:00 2001 From: vng Date: Thu, 15 Aug 2013 18:21:13 +0300 Subject: [PATCH] [api] Show viewport on correct zoom level in on API request. --- map/framework.cpp | 27 ++++++++++++++++++++------- map/framework.hpp | 7 +++---- map/mwm_url.cpp | 24 ++++++++++++++++++++---- map/mwm_url.hpp | 11 +++++++++-- map/ruler.cpp | 2 +- 5 files changed, 53 insertions(+), 18 deletions(-) diff --git a/map/framework.cpp b/map/framework.cpp index c28d7daec4..736278afb9 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -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 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(); diff --git a/map/framework.hpp b/map/framework.hpp index a868900029..4709597226 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -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 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 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); //@} diff --git a/map/mwm_url.cpp b/map/mwm_url.cpp index e7bd3b84f4..eea9f97ceb 100644 --- a/map/mwm_url.cpp +++ b/map/mwm_url.cpp @@ -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(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; } diff --git a/map/mwm_url.hpp b/map/mwm_url.hpp index ff71b71c27..6394ddec71 100644 --- a/map/mwm_url.hpp +++ b/map/mwm_url.hpp @@ -20,15 +20,22 @@ class ParsedMapApi public: ParsedMapApi(Uri const & uri); ParsedMapApi(); + bool SetUriAndParse(string const & url); bool IsValid() const; vector 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; }; diff --git a/map/ruler.cpp b/map/ruler.cpp index 8a7c3e459a..dff4fb35d2 100644 --- a/map/ruler.cpp +++ b/map/ruler.cpp @@ -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 },