From 4f85c45bcd0ad11114dc5c162c97cd8f88035351 Mon Sep 17 00:00:00 2001 From: Arsentiy Milchakov Date: Sat, 29 Dec 2018 15:41:04 +0300 Subject: [PATCH] [depp links] process viewport center parameter for search in viewport --- android/jni/com/mapswithme/maps/Framework.cpp | 16 ++++++++++++++++ android/src/com/mapswithme/maps/Framework.java | 2 ++ android/src/com/mapswithme/maps/MwmActivity.java | 6 ++++++ iphone/Maps/Classes/MapsAppDelegate.mm | 14 ++++++++++++++ map/framework.cpp | 12 ++++++------ map/framework.hpp | 4 ++-- 6 files changed, 46 insertions(+), 8 deletions(-) diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 40d86b931b..1f3fabe2e6 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -26,6 +26,7 @@ #include "coding/file_name_utils.hpp" #include "geometry/angles.hpp" +#include "geometry/mercator.hpp" #include "indexer/feature_altitude.hpp" @@ -1978,4 +1979,19 @@ Java_com_mapswithme_maps_Framework_nativeSetPowerManagerScheme(JNIEnv *, jclass, { frm()->GetPowerManager().SetScheme(static_cast(schemeType)); } + +JNIEXPORT void JNICALL +Java_com_mapswithme_maps_Framework_nativeSetViewportCenter(JNIEnv *, jclass, jdouble lat, + jdouble lon, jint zoom) +{ + auto const center = MercatorBounds::FromLatLon(static_cast(lat), + static_cast(lon)); + frm()->SetViewportCenter(center, static_cast(zoom)); +} + +JNIEXPORT void JNICALL +Java_com_mapswithme_maps_Framework_nativeStopLocationFollow(JNIEnv *, jclass) +{ + frm()->StopLocationFollow(); +} } // extern "C" diff --git a/android/src/com/mapswithme/maps/Framework.java b/android/src/com/mapswithme/maps/Framework.java index c1b6e9fd91..be4552f1d1 100644 --- a/android/src/com/mapswithme/maps/Framework.java +++ b/android/src/com/mapswithme/maps/Framework.java @@ -516,6 +516,8 @@ public class Framework public static native void nativeOnBatteryLevelChanged(int level); public static native void nativeSetPowerManagerFacility(int facilityType, boolean state); public static native void nativeSetPowerManagerScheme(int schemeType); + public static native void nativeSetViewportCenter(double lat, double lon, int zoom); + public static native void nativeStopLocationFollow(); public enum LocalAdsEventType { diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index 3bcb8f5f61..a152038b4d 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -1729,6 +1729,7 @@ public class MwmActivity extends BaseMwmFragmentActivity public static class OpenUrlTask implements MapTask { private static final long serialVersionUID = 1L; + private static final int SEARCH_IN_VIEWPORT_ZOOM = 16; private final String mUrl; public OpenUrlTask(String url) @@ -1762,6 +1763,11 @@ public class MwmActivity extends BaseMwmFragmentActivity return true; case ParsedUrlMwmRequest.RESULT_SEARCH: final ParsedSearchRequest request = Framework.nativeGetParsedSearchRequest(); + if (request.mIsSearchOnMap) + { + Framework.nativeStopLocationFollow(); + Framework.nativeSetViewportCenter(request.mLat, request.mLon, SEARCH_IN_VIEWPORT_ZOOM); + } SearchActivity.start(target, request.mQuery, request.mLocale, request.mIsSearchOnMap, null, null); return true; diff --git a/iphone/Maps/Classes/MapsAppDelegate.mm b/iphone/Maps/Classes/MapsAppDelegate.mm index 4a89478d7a..3a6666db5d 100644 --- a/iphone/Maps/Classes/MapsAppDelegate.mm +++ b/iphone/Maps/Classes/MapsAppDelegate.mm @@ -39,6 +39,10 @@ #include "platform/http_thread_apple.h" #include "platform/local_country_file_utils.hpp" +#include "geometry/mercator.hpp" + +#include "base/assert.hpp" + #include "private.h" // If you have a "missing header error" here, then please run configure.sh script in the root repo // folder. @@ -59,6 +63,8 @@ NSString * const kUDAutoNightModeOff = @"AutoNightModeOff"; NSString * const kIOSIDFA = @"IFA"; NSString * const kBundleVersion = @"BundleVersion"; +auto const kSearchInViewportZoom = 16; + /// Adds needed localized strings to C++ code /// @TODO Refactor localization mechanism to make it simpler void InitLocalizedStrings() @@ -263,9 +269,17 @@ using namespace osm_auth_ios; auto locale = @(request.m_locale.c_str()); if (request.m_isSearchOnMap) + { + ASSERT([self isDrapeEngineCreated], ()); + f.StopLocationFollow(); + auto const center = MercatorBounds::FromLatLon(request.m_centerLat, request.m_centerLon); + f.SetViewportCenter(center, kSearchInViewportZoom); [manager searchTextOnMap:query forInputLocale:locale]; + } else + { [manager searchText:query forInputLocale:locale]; + } break; } diff --git a/map/framework.cpp b/map/framework.cpp index 6d116b9e16..e759f13b0b 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -325,12 +325,6 @@ void Framework::OnViewportChanged(ScreenBase const & screen) m_viewportChanged(screen); } -void Framework::StopLocationFollow() -{ - if (m_drapeEngine != nullptr) - m_drapeEngine->StopLocationFollow(); -} - bool Framework::IsEnoughSpaceForMigrate() const { return GetPlatform().GetWritableStorageStatus(GetStorage().GetMaxMwmSizeBytes()) == @@ -1222,6 +1216,12 @@ void Framework::SetViewportListener(TViewportChanged const & fn) m_viewportChanged = fn; } +void Framework::StopLocationFollow() +{ + if (m_drapeEngine != nullptr) + m_drapeEngine->StopLocationFollow(); +} + void Framework::OnSize(int w, int h) { if (m_drapeEngine != nullptr) diff --git a/map/framework.hpp b/map/framework.hpp index 99ae4bd19b..1c71e7cc5b 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -248,8 +248,6 @@ protected: void ClearAllCaches(); - void StopLocationFollow(); - void OnViewportChanged(ScreenBase const & screen); void InitTransliteration(); @@ -628,6 +626,8 @@ public: void SetViewportListener(TViewportChanged const & fn); + void StopLocationFollow(); + /// Resize event from window. void OnSize(int w, int h);