diff --git a/android/jni/CMakeLists.txt b/android/jni/CMakeLists.txt index c589950371..653ba7f56c 100644 --- a/android/jni/CMakeLists.txt +++ b/android/jni/CMakeLists.txt @@ -22,6 +22,7 @@ set( SRC # JNI headers ../../private.h + com/mapswithme/util/FeatureIdBuilder.hpp com/mapswithme/core/jni_helper.hpp com/mapswithme/core/logging.hpp com/mapswithme/core/ScopedEnv.hpp diff --git a/android/jni/com/mapswithme/core/jni_helper.hpp b/android/jni/com/mapswithme/core/jni_helper.hpp index b4fc53bba1..b49495a8c3 100644 --- a/android/jni/com/mapswithme/core/jni_helper.hpp +++ b/android/jni/com/mapswithme/core/jni_helper.hpp @@ -4,11 +4,11 @@ #include "ScopedLocalRef.hpp" +#include "geometry/point2d.hpp" + #include "base/buffer_vector.hpp" #include "base/logging.hpp" -#include "geometry/point2d.hpp" - #include #include #include diff --git a/android/jni/com/mapswithme/maps/Framework.cpp b/android/jni/com/mapswithme/maps/Framework.cpp index 7ee3416c63..06b509a559 100644 --- a/android/jni/com/mapswithme/maps/Framework.cpp +++ b/android/jni/com/mapswithme/maps/Framework.cpp @@ -4,6 +4,7 @@ #include "com/mapswithme/opengl/androidoglcontextfactory.hpp" #include "com/mapswithme/platform/Platform.hpp" #include "com/mapswithme/util/NetworkPolicy.hpp" +#include "com/mapswithme/util/FeatureIdBuilder.hpp" #include "com/mapswithme/vulkan/android_vulkan_context_factory.hpp" #include "map/chart_generator.hpp" @@ -874,6 +875,13 @@ void Framework::OnPowerSchemeChanged(power_management::Scheme const actualScheme // Dummy // TODO: provide information for UI Properties. } + +FeatureID Framework::BuildFeatureId(JNIEnv * env, jobject featureId) +{ + static FeatureIdBuilder const builder(env); + + return builder.Build(env, featureId); +} } // namespace android //============ GLUE CODE for com.mapswithme.maps.Framework class =============// @@ -1963,7 +1971,6 @@ Java_com_mapswithme_maps_Framework_nativeGetPhoneAuthUrl(JNIEnv * env, jclass, j JNIEXPORT jobjectArray JNICALL Java_com_mapswithme_maps_Framework_nativeGetDefaultAuthHeaders(JNIEnv * env, jobject) { - auto const & bm = frm()->GetBookmarkManager(); return jni::ToKeyValueArray(env, web_api::GetDefaultAuthHeaders()); } @@ -1980,10 +1987,12 @@ Java_com_mapswithme_maps_Framework_nativeGetTermsOfUseLink(JNIEnv * env, jclass) } JNIEXPORT void JNICALL -Java_com_mapswithme_maps_Framework_nativeShowFeatureByLatLon(JNIEnv * env, jclass, - jdouble lat, jdouble lon) +Java_com_mapswithme_maps_Framework_nativeShowFeature(JNIEnv * env, jclass, jobject featureId) { - frm()->ShowFeatureByMercator(mercator::FromLatLon(ms::LatLon(lat, lon))); + auto const f = g_framework->BuildFeatureId(env, featureId); + + if (f.IsValid()) + frm()->ShowFeature(f); } JNIEXPORT void JNICALL diff --git a/android/jni/com/mapswithme/maps/Framework.hpp b/android/jni/com/mapswithme/maps/Framework.hpp index 4eaf070f1e..6d75e3ab6e 100644 --- a/android/jni/com/mapswithme/maps/Framework.hpp +++ b/android/jni/com/mapswithme/maps/Framework.hpp @@ -22,6 +22,9 @@ #include "partners_api/promo_api.hpp" #include "partners_api/utm.hpp" +#include "indexer/feature_decl.hpp" +#include "indexer/map_style.hpp" + #include "platform/country_defines.hpp" #include "platform/location.hpp" @@ -29,8 +32,6 @@ #include "base/timer.hpp" -#include "indexer/map_style.hpp" - #include #include #include @@ -227,6 +228,8 @@ namespace android // PowerManager::Subscriber overrides: void OnPowerFacilityChanged(power_management::Facility const facility, bool enabled) override; void OnPowerSchemeChanged(power_management::Scheme const actualScheme) override; + + FeatureID BuildFeatureId(JNIEnv * env, jobject featureId); }; } diff --git a/android/jni/com/mapswithme/maps/isolines/IsolinesManager.cpp b/android/jni/com/mapswithme/maps/isolines/IsolinesManager.cpp index 836a0a7512..9ff68dd9cf 100644 --- a/android/jni/com/mapswithme/maps/isolines/IsolinesManager.cpp +++ b/android/jni/com/mapswithme/maps/isolines/IsolinesManager.cpp @@ -1,5 +1,5 @@ #include -#include +#include "com/mapswithme/maps/Framework.hpp" #include "com/mapswithme/core/jni_helper.hpp" #include "com/mapswithme/platform/Platform.hpp" diff --git a/android/jni/com/mapswithme/maps/ugc/UGC.cpp b/android/jni/com/mapswithme/maps/ugc/UGC.cpp index 79ee1cceda..eb3068ffb0 100644 --- a/android/jni/com/mapswithme/maps/ugc/UGC.cpp +++ b/android/jni/com/mapswithme/maps/ugc/UGC.cpp @@ -18,46 +18,6 @@ namespace { -class FeatureIdBuilder -{ -public: - FeatureID Build(JNIEnv * env, jobject obj) - { - Init(env); - - jstring jcountryName = static_cast(env->GetObjectField(obj, m_countryName)); - jint jindex = env->GetIntField(obj, m_index); - - auto const countryName = jni::ToNativeString(env, jcountryName); - auto const index = static_cast(jindex); - - auto const & ds = g_framework->GetDataSource(); - auto const id = ds.GetMwmIdByCountryFile(platform::CountryFile(countryName)); - return FeatureID(id, index); - } - -private: - void Init(JNIEnv * env) - { - if (m_initialized) - return; - - m_class = jni::GetGlobalClassRef(env, "com/mapswithme/maps/bookmarks/data/FeatureId"); - m_countryName = env->GetFieldID(m_class, "mMwmName", "Ljava/lang/String;"); - m_version = env->GetFieldID(m_class, "mMwmVersion", "J"); - m_index = env->GetFieldID(m_class, "mFeatureIndex", "I"); - - m_initialized = true; - } - - bool m_initialized = false; - - jclass m_class; - jfieldID m_countryName; - jfieldID m_version; - jfieldID m_index; -} g_builder; - class JavaBridge { public: @@ -270,7 +230,7 @@ JNIEXPORT void JNICALL Java_com_mapswithme_maps_ugc_UGC_nativeRequestUGC(JNIEnv * env, jclass /* clazz */, jobject featureId) { - auto const fid = g_builder.Build(env, featureId); + auto const fid = g_framework->BuildFeatureId(env, featureId); g_framework->RequestUGC(fid, [](ugc::UGC const & ugc, ugc::UGCUpdate const & update) { g_bridge.OnUGCReceived(jni::GetEnv(), ugc, update); }); @@ -281,7 +241,7 @@ void JNICALL Java_com_mapswithme_maps_ugc_UGC_nativeSetUGCUpdate(JNIEnv * env, j jobject featureId, jobject ugcUpdate) { - auto const fid = g_builder.Build(env, featureId); + auto const fid = g_framework->BuildFeatureId(env, featureId); ugc::UGCUpdate update = g_bridge.ToNativeUGCUpdate(env, ugcUpdate); g_framework->SetUGCUpdate(fid, update, [](ugc::Storage::SettingResult const & result) { g_bridge.OnUGCSaved(jni::GetEnv(), result); diff --git a/android/jni/com/mapswithme/util/FeatureIdBuilder.hpp b/android/jni/com/mapswithme/util/FeatureIdBuilder.hpp new file mode 100644 index 0000000000..e35b0e3b04 --- /dev/null +++ b/android/jni/com/mapswithme/util/FeatureIdBuilder.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include "com/mapswithme/core/jni_helper.hpp" + +#include "indexer/feature_decl.hpp" + +class FeatureIdBuilder +{ +public: + FeatureIdBuilder(JNIEnv * env) + { + m_class = jni::GetGlobalClassRef(env, "com/mapswithme/maps/bookmarks/data/FeatureId"); + m_countryName = env->GetFieldID(m_class, "mMwmName", "Ljava/lang/String;"); + m_version = env->GetFieldID(m_class, "mMwmVersion", "J"); + m_index = env->GetFieldID(m_class, "mFeatureIndex", "I"); + } + + FeatureID Build(JNIEnv * env, jobject obj) const + { + jstring jcountryName = static_cast(env->GetObjectField(obj, m_countryName)); + jint jindex = env->GetIntField(obj, m_index); + + auto const countryName = jni::ToNativeString(env, jcountryName); + auto const index = static_cast(jindex); + + auto const & ds = g_framework->GetDataSource(); + auto const id = ds.GetMwmIdByCountryFile(platform::CountryFile(countryName)); + return FeatureID(id, index); + } + +private: + jclass m_class; + jfieldID m_countryName; + jfieldID m_version; + jfieldID m_index; +}; diff --git a/android/src/com/mapswithme/maps/Framework.java b/android/src/com/mapswithme/maps/Framework.java index c8a1c334bd..f50022e57e 100644 --- a/android/src/com/mapswithme/maps/Framework.java +++ b/android/src/com/mapswithme/maps/Framework.java @@ -18,6 +18,7 @@ import com.mapswithme.maps.api.ParsedUrlMwmRequest; import com.mapswithme.maps.auth.AuthorizationListener; import com.mapswithme.maps.background.NotificationCandidate; import com.mapswithme.maps.bookmarks.data.DistanceAndAzimut; +import com.mapswithme.maps.bookmarks.data.FeatureId; import com.mapswithme.maps.bookmarks.data.MapObject; import com.mapswithme.maps.downloader.DownloaderPromoBanner; import com.mapswithme.maps.gdpr.UserBindingListener; @@ -493,7 +494,7 @@ public class Framework @NonNull public static native String nativeGetTermsOfUseLink(); - public static native void nativeShowFeatureByLatLon(double lat, double lon); + public static native void nativeShowFeature(@NonNull FeatureId featureId); public static native void nativeShowBookmarkCategory(long cat); private static native int nativeGetFilterRating(float rawRating); diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java index 4b5ffdacc6..b082cca816 100644 --- a/android/src/com/mapswithme/maps/MwmActivity.java +++ b/android/src/com/mapswithme/maps/MwmActivity.java @@ -1165,7 +1165,7 @@ public class MwmActivity extends BaseMwmFragmentActivity @Override public boolean run(@NonNull MwmActivity target) { - Framework.nativeShowFeatureByLatLon(object.getLat(), object.getLon()); + Framework.nativeShowFeature(object.getFeatureId()); return false; } }); diff --git a/android/src/com/mapswithme/maps/discovery/DiscoveryFragment.java b/android/src/com/mapswithme/maps/discovery/DiscoveryFragment.java index ee6b15ba03..eb34eabd3f 100644 --- a/android/src/com/mapswithme/maps/discovery/DiscoveryFragment.java +++ b/android/src/com/mapswithme/maps/discovery/DiscoveryFragment.java @@ -399,7 +399,7 @@ public class DiscoveryFragment extends BaseMwmToolbarFragment implements Discove String title = TextUtils.isEmpty(item.getTitle()) ? subtitle : item.getTitle(); - return MapObject.createMapObject(FeatureId.EMPTY, MapObject.SEARCH, title, subtitle, + return MapObject.createMapObject(item.getFeatureId(), MapObject.SEARCH, title, subtitle, item.getLat(), item.getLon()); } diff --git a/android/src/com/mapswithme/maps/gallery/Items.java b/android/src/com/mapswithme/maps/gallery/Items.java index 54e78e3065..128a8a5a3e 100644 --- a/android/src/com/mapswithme/maps/gallery/Items.java +++ b/android/src/com/mapswithme/maps/gallery/Items.java @@ -5,6 +5,7 @@ import androidx.annotation.Nullable; import com.mapswithme.maps.MwmApplication; import com.mapswithme.maps.R; +import com.mapswithme.maps.bookmarks.data.FeatureId; import com.mapswithme.maps.search.Popularity; import com.mapswithme.maps.search.SearchResult; @@ -135,6 +136,15 @@ public class Items return mResult.description.featureType; } + @NonNull + public FeatureId getFeatureId() + { + if (mResult.description == null) + return FeatureId.EMPTY; + + return mResult.description.featureId == null ? FeatureId.EMPTY : mResult.description.featureId; + } + @NonNull public Popularity getPopularity() { diff --git a/map/framework.cpp b/map/framework.cpp index f5e82c9e1e..9af24d60b8 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -1136,17 +1136,20 @@ void Framework::ShowBookmarkCategory(kml::MarkGroupId categoryId, bool animation ShowRect(rect, -1 /* maxScale */, animation); } -void Framework::ShowFeatureByMercator(m2::PointD const & pt) +void Framework::ShowFeature(FeatureID const & featureId) { StopLocationFollow(); place_page::BuildInfo info; - info.m_mercator = pt; + info.m_featureId = featureId; + info.m_match = place_page::BuildInfo::Match::FeatureOnly; m_currentPlacePageInfo = BuildPlacePageInfo(info); + if (m_drapeEngine != nullptr) { - m_drapeEngine->SetModelViewCenter(pt, scales::GetUpperComfortScale(), true /* isAnim */, - true /* trackVisibleViewport */); + auto const pt = m_currentPlacePageInfo->GetMercator(); + auto const scale = scales::GetUpperComfortScale(); + m_drapeEngine->SetModelViewCenter(pt, scale, true /* isAnim */, true /* trackVisibleViewport */); } ActivateMapSelection(m_currentPlacePageInfo); } @@ -3124,20 +3127,18 @@ bool Framework::ParseEditorDebugCommand(search::SearchParams const & params) auto const features = FindFeaturesByIndex(index); for (auto const & fid : features) { - FeaturesLoaderGuard guard(m_featuresFetcher.GetDataSource(), fid.m_mwmId); - auto ft = guard.GetFeatureByIndex(fid.m_index); - if (!ft) + if (!fid.IsValid()) continue; // Show the first feature on the map. if (!isShown) { - ShowFeatureByMercator(feature::GetCenter(*ft)); + ShowFeature(fid); isShown = true; } // Log found features. - LOG(LINFO, ("Feature found:", fid, mercator::ToLatLon(feature::GetCenter(*ft)))); + LOG(LINFO, ("Feature found:", fid)); } } return true; diff --git a/map/framework.hpp b/map/framework.hpp index 2468550f60..ac977d5fd9 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -351,7 +351,7 @@ public: void ShowBookmark(kml::MarkId id); void ShowBookmark(Bookmark const * bookmark); void ShowTrack(kml::TrackId trackId); - void ShowFeatureByMercator(m2::PointD const & pt); + void ShowFeature(FeatureID const & featureId); void ShowBookmarkCategory(kml::MarkGroupId categoryId, bool animation = true); void AddBookmarksFile(std::string const & filePath, bool isTemporaryFile);