From 9292651e891607c52a73c4c43125637e30e4fb40 Mon Sep 17 00:00:00 2001 From: vng Date: Fri, 28 Jan 2011 09:50:15 +0200 Subject: [PATCH] Fix initial model rect: if empty, return MercatorBounds. Check for maximum screen scale level (limited by MercatorBounds). --- map/feature_vec_model.cpp | 25 +++++++++++++++---------- map/feature_vec_model.hpp | 3 +-- map/navigator.cpp | 38 ++++++++++++++++++++++++++++---------- 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/map/feature_vec_model.cpp b/map/feature_vec_model.cpp index a629301a08..f280b16672 100644 --- a/map/feature_vec_model.cpp +++ b/map/feature_vec_model.cpp @@ -18,11 +18,6 @@ namespace model { -FeaturesFetcher::FeaturesFetcher() -{ - Clean(); -} - void FeaturesFetcher::InitClassificator() { Platform & p = GetPlatform(); @@ -57,12 +52,22 @@ void FeaturesFetcher::RemoveMap(string const & fName) void FeaturesFetcher::Clean() { - m_rect = m2::RectD(MercatorBounds::minX, - MercatorBounds::minY, - MercatorBounds::maxX, - MercatorBounds::maxY); -// m_rect.MakeEmpty(); + m_rect.MakeEmpty(); m_multiIndex.Clean(); } +m2::RectD FeaturesFetcher::GetWorldRect() const +{ + if (m_rect == m2::RectD()) + { + // rect is empty when now countries are loaded + // return max global rect + return m2::RectD(MercatorBounds::minX, + MercatorBounds::minY, + MercatorBounds::maxX, + MercatorBounds::maxY); + } + return m_rect; +} + } diff --git a/map/feature_vec_model.hpp b/map/feature_vec_model.hpp index 2cd4aef07b..f7a2a60409 100644 --- a/map/feature_vec_model.hpp +++ b/map/feature_vec_model.hpp @@ -32,7 +32,6 @@ namespace model index_t m_multiIndex; public: - FeaturesFetcher(); void InitClassificator(); @@ -56,7 +55,7 @@ namespace model } void AddWorldRect(m2::RectD const & r) { m_rect.Add(r); } - m2::RectD GetWorldRect() const { return m_rect; } + m2::RectD GetWorldRect() const; }; } diff --git a/map/navigator.cpp b/map/navigator.cpp index 7b08fc9213..38a0a490d4 100644 --- a/map/navigator.cpp +++ b/map/navigator.cpp @@ -127,13 +127,13 @@ void Navigator::ScaleToPoint(m2::PointD const & pt, double factor, double /*time if (pt.x != m_Screen.PixelRect().maxX()) { - /// start scaling point is 1 / factor way between pt and right border + // start scaling point is 1 / factor way between pt and right border startPt.x = pt.x + ((m_Screen.PixelRect().maxX() - pt.x) / factor); endPt.x = m_Screen.PixelRect().maxX(); } else { - /// start scaling point is 1 - 1/factor way between left border and pt + // start scaling point is 1 - 1/factor way between left border and pt startPt.x = pt.x + (m_Screen.PixelRect().minX() - pt.x) / factor; endPt.x = m_Screen.PixelRect().minX(); } @@ -152,15 +152,28 @@ void Navigator::ScaleToPoint(m2::PointD const & pt, double factor, double /*time ScaleImpl(pt, endPt, pt, startPt); } -void Navigator::ScaleImpl(m2::PointD const & newPt1, m2::PointD const & newPt2, m2::PointD const & oldPt1, m2::PointD const & oldPt2) +namespace +{ + bool CheckMaxScale(ScreenBase const & screen) + { + m2::RectD const r = screen.GlobalRect(); + return ((r.SizeX() <= (MercatorBounds::maxX - MercatorBounds::minX)) || + (r.SizeY() <= (MercatorBounds::maxY - MercatorBounds::minY))); + } +} + +void Navigator::ScaleImpl(m2::PointD const & newPt1, m2::PointD const & newPt2, + m2::PointD const & oldPt1, m2::PointD const & oldPt2) { math::Matrix newM = m_Screen.GtoPMatrix() * ScreenBase::CalcTransform(oldPt1, oldPt2, newPt1, newPt2); - ScreenBase TmpScreen = m_Screen; - TmpScreen.SetGtoPMatrix(newM); - TmpScreen.Rotate(TmpScreen.GetAngle()); - if ((TmpScreen.GlobalRect().SizeX() <= (MercatorBounds::maxX - MercatorBounds::minX)) - || ((TmpScreen.GlobalRect().SizeY() <= (MercatorBounds::maxY - MercatorBounds::minY)))) - m_Screen = TmpScreen; + + ScreenBase tmp = m_Screen; + tmp.SetGtoPMatrix(newM); + tmp.Rotate(tmp.GetAngle()); + + // limit max scale to MercatorBounds + if (CheckMaxScale(tmp)) + m_Screen = tmp; } void Navigator::DoScale(m2::PointD const & pt1, m2::PointD const & pt2, double /*timeInSec*/) @@ -191,7 +204,12 @@ void Navigator::StopScale(m2::PointD const & pt1, m2::PointD const & pt2, double void Navigator::Scale(double scale) { - m_Screen.Scale(scale); + ScreenBase tmp = m_Screen; + tmp.Scale(scale); + + // limit max scale to MercatorBounds + if (CheckMaxScale(tmp)) + m_Screen = tmp; } void Navigator::Rotate(double angle)