From cb28d862895b42da7caf39b7841927c661830f8e Mon Sep 17 00:00:00 2001 From: Daria Volvenkova Date: Thu, 12 Jul 2018 18:53:41 +0300 Subject: [PATCH] Fixed scaling to max zoom on desktop and iPad. --- drape_frontend/my_position_controller.cpp | 6 +++--- drape_frontend/screen_operations.cpp | 2 +- drape_frontend/user_event_stream.cpp | 4 ++-- drape_frontend/user_mark_shapes.cpp | 2 +- drape_frontend/visual_params.cpp | 26 ++++++++++++++++------- drape_frontend/visual_params.hpp | 8 ++++--- map/bookmark_manager.cpp | 2 +- map/local_ads_manager.cpp | 2 +- map/traffic_manager.cpp | 2 +- 9 files changed, 33 insertions(+), 21 deletions(-) diff --git a/drape_frontend/my_position_controller.cpp b/drape_frontend/my_position_controller.cpp index 268aa5c666..7c73d47a72 100644 --- a/drape_frontend/my_position_controller.cpp +++ b/drape_frontend/my_position_controller.cpp @@ -61,7 +61,7 @@ std::string LocationModeStatisticsName(location::EMyPositionMode mode) int GetZoomLevel(ScreenBase const & screen) { - return static_cast(df::GetTileBasedZoomLevel(screen.GetScale())); + return static_cast(df::GetZoomLevel(screen.GetScale())); } int GetZoomLevel(ScreenBase const & screen, m2::PointD const & position, double errorRadius) @@ -143,7 +143,7 @@ MyPositionController::MyPositionController(Params && params, ref_ptr(GetTileBasedZoomLevel(ScreenBase::GetStartPerspectiveScale() * 1.1)); + preferredZoomLevel = static_cast(GetZoomLevel(ScreenBase::GetStartPerspectiveScale() * 1.1)); ChangeMode(location::Follow); ChangeModelView(m_position, 0.0, m_visiblePixelRect.Center(), preferredZoomLevel); } diff --git a/drape_frontend/screen_operations.cpp b/drape_frontend/screen_operations.cpp index 022625eb8f..d7c0659553 100644 --- a/drape_frontend/screen_operations.cpp +++ b/drape_frontend/screen_operations.cpp @@ -260,7 +260,7 @@ bool ApplyScale(m2::PointD const & pixelScaleCenter, double factor, ScreenBase & if (!CheckMaxScale(tmp)) { - auto const maxScale = GetTileBasedScale(scales::GetUpperStyleScale() + 0.42); + auto const maxScale = GetScreenScale(scales::GetUpperStyleScale() + 0.42); if (maxScale > screen.GetScale() && CheckMaxScale(screen)) return false; tmp.SetScale(maxScale); diff --git a/drape_frontend/user_event_stream.cpp b/drape_frontend/user_event_stream.cpp index c1eed0a19f..69eebcfc9d 100644 --- a/drape_frontend/user_event_stream.cpp +++ b/drape_frontend/user_event_stream.cpp @@ -392,7 +392,7 @@ bool UserEventStream::OnSetCenter(ref_ptr centerEvent) } else { - screen.SetFromParams(center, screen.GetAngle(), GetTileBasedScale(zoom)); + screen.SetFromParams(center, screen.GetAngle(), GetScreenScale(zoom)); screen.MatchGandP3d(center, m_visibleViewport.Center()); } @@ -554,7 +554,7 @@ bool UserEventStream::SetFollowAndRotate(m2::PointD const & userPos, m2::PointD } else { - screen.SetFromParams(userPos, -azimuth, isAutoScale ? autoScale : GetTileBasedScale(preferredZoomLevel)); + screen.SetFromParams(userPos, -azimuth, isAutoScale ? autoScale : GetScreenScale(preferredZoomLevel)); } screen.MatchGandP3d(userPos, pixelPos); diff --git a/drape_frontend/user_mark_shapes.cpp b/drape_frontend/user_mark_shapes.cpp index e545bf6398..c91fd3beb8 100644 --- a/drape_frontend/user_mark_shapes.cpp +++ b/drape_frontend/user_mark_shapes.cpp @@ -461,7 +461,7 @@ void CacheUserLines(TileKey const & tileKey, ref_ptr texture double sqrScale = 1.0; if (simplify) { - double const currentScaleGtoP = 1.0 / GetTileBasedScale(tileKey.m_zoomLevel); + double const currentScaleGtoP = 1.0 / GetScreenScale(tileKey.m_zoomLevel); sqrScale = currentScaleGtoP * currentScaleGtoP; } diff --git a/drape_frontend/visual_params.cpp b/drape_frontend/visual_params.cpp index d3dd96b86a..eb5b7d31c7 100644 --- a/drape_frontend/visual_params.cpp +++ b/drape_frontend/visual_params.cpp @@ -192,6 +192,11 @@ int GetTileScaleBase(m2::RectD const & r) return max(1, my::rounds(log((MercatorBounds::maxX - MercatorBounds::minX) / sz) / log(2.0))); } +double GetTileScaleBase(double drawScale) +{ + return std::max(1.0, drawScale - GetTileScaleIncrement()); +} + int GetTileScaleIncrement(uint32_t tileSize, double visualScale) { return log(tileSize / 256.0 / visualScale) / log(2.0); @@ -284,6 +289,11 @@ int GetDrawTileScale(int baseScale) return GetDrawTileScale(baseScale, p.GetTileSize(), p.GetVisualScale()); } +double GetDrawTileScale(double baseScale) +{ + return std::max(1.0, baseScale + GetTileScaleIncrement()); +} + int GetDrawTileScale(ScreenBase const & s) { VisualParams const & p = VisualParams::Instance(); @@ -298,7 +308,7 @@ int GetDrawTileScale(m2::RectD const & r) void ExtractZoomFactors(ScreenBase const & s, double & zoom, int & index, float & lerpCoef) { - double const zoomLevel = GetTileBasedZoomLevel(s.GetScale()); + double const zoomLevel = GetZoomLevel(s.GetScale()); zoom = trunc(zoomLevel); index = static_cast(zoom - 1.0); lerpCoef = static_cast(zoomLevel - zoom); @@ -322,28 +332,28 @@ m2::PointF InterpolateByZoomLevels(int index, float lerpCoef, std::vector(p.GetTileSize()); return len / pxLen; } -double GetTileBasedZoomLevel(double scale) +double GetZoomLevel(double screenScale) { VisualParams const & p = VisualParams::Instance(); auto const pxLen = static_cast(p.GetTileSize()); - auto const len = pxLen * scale; + auto const len = pxLen * screenScale; auto const factor = (MercatorBounds::maxX - MercatorBounds::minX) / len; static double const kLog2 = log(2.0); - return my::clamp(fabs(log(factor) / kLog2), 1.0, scales::GetUpperStyleScale() + 1.0); + return my::clamp(GetDrawTileScale(fabs(log(factor) / kLog2)), 1.0, scales::GetUpperStyleScale() + 1.0); } } // namespace df diff --git a/drape_frontend/visual_params.hpp b/drape_frontend/visual_params.hpp index 4e4ecf078b..614de5a313 100644 --- a/drape_frontend/visual_params.hpp +++ b/drape_frontend/visual_params.hpp @@ -66,6 +66,7 @@ m2::RectD const & GetWorldRect(); int GetTileScaleBase(ScreenBase const & s, uint32_t tileSize); int GetTileScaleBase(ScreenBase const & s); int GetTileScaleBase(m2::RectD const & r); +double GetTileScaleBase(double drawScale); /// @return Adjusting base tile scale to look the same across devices with different /// tile size and visual scale values. @@ -76,6 +77,7 @@ int GetDrawTileScale(int baseScale, uint32_t tileSize, double visualScale); int GetDrawTileScale(ScreenBase const & s, uint32_t tileSize, double visualScale); int GetDrawTileScale(m2::RectD const & r, uint32_t tileSize, double visualScale); int GetDrawTileScale(int baseScale); +double GetDrawTileScale(double baseScale); int GetDrawTileScale(ScreenBase const & s); int GetDrawTileScale(m2::RectD const & r); @@ -89,7 +91,7 @@ uint32_t CalculateTileSize(uint32_t screenWidth, uint32_t screenHeight); void ExtractZoomFactors(ScreenBase const & s, double & zoom, int & index, float & lerpCoef); float InterpolateByZoomLevels(int index, float lerpCoef, std::vector const & values); m2::PointF InterpolateByZoomLevels(int index, float lerpCoef, std::vector const & values); -double GetNormalizedZoomLevel(double scale, int minZoom = 1); -double GetTileBasedScale(double zoomLevel); -double GetTileBasedZoomLevel(double scale); +double GetNormalizedZoomLevel(double screenScale, int minZoom = 1); +double GetScreenScale(double zoomLevel); +double GetZoomLevel(double screenScale); } // namespace df diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index eaa3e370bd..e3e14790b9 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -574,7 +574,7 @@ Bookmark * BookmarkManager::CreateBookmark(kml::BookmarkData && bm, kml::MarkGro alohalytics::Stats::Instance().LogEvent("Bookmarks_Bookmark_action", details); bm.m_timestamp = std::chrono::system_clock::now(); - bm.m_viewportScale = static_cast(df::GetTileBasedZoomLevel(m_viewport.GetScale())); + bm.m_viewportScale = static_cast(df::GetZoomLevel(m_viewport.GetScale())); auto * bookmark = CreateBookmark(std::move(bm)); bookmark->Attach(groupId); diff --git a/map/local_ads_manager.cpp b/map/local_ads_manager.cpp index e9f76c58bb..b4c6aed5e8 100644 --- a/map/local_ads_manager.cpp +++ b/map/local_ads_manager.cpp @@ -316,7 +316,7 @@ void LocalAdsManager::UpdateViewport(ScreenBase const & screen) { auto const connectionStatus = GetPlatform().ConnectionStatus(); if (kServerUrl.empty() || connectionStatus == Platform::EConnectionType::CONNECTION_NONE || - df::GetTileBasedZoomLevel(screen.GetScale()) < kRequestMinZoomLevel) + df::GetZoomLevel(screen.GetScale()) < kRequestMinZoomLevel) { return; } diff --git a/map/traffic_manager.cpp b/map/traffic_manager.cpp index 1427790d4d..2551f86d2e 100644 --- a/map/traffic_manager.cpp +++ b/map/traffic_manager.cpp @@ -222,7 +222,7 @@ void TrafficManager::UpdateViewport(ScreenBase const & screen) if (!IsEnabled() || IsInvalidState() || m_isPaused) return; - if (df::GetTileBasedZoomLevel(screen.GetScale()) < df::kRoadClass0ZoomLevel) + if (df::GetZoomLevel(screen.GetScale()) < df::kRoadClass0ZoomLevel) return; // Request traffic.