[android] Expected "Show on map" search button behaviour.

Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
Viktor Govako
2025-07-12 22:21:55 -03:00
committed by Konstantin Pastbin
parent bbb28107b8
commit 1151f0fb75
5 changed files with 29 additions and 40 deletions

View File

@@ -190,6 +190,12 @@ public enum SearchEngine implements SearchListener, MapSearchListener,
nativeShowResult(index);
}
@MainThread
public void updateViewportWithLastResults()
{
nativeUpdateViewportWithLastResults();
}
public void initialize()
{
nativeInit();
@@ -224,4 +230,6 @@ public enum SearchEngine implements SearchListener, MapSearchListener,
private static native void nativeCancelEverywhereSearch();
private static native void nativeCancelAllSearches();
private static native void nativeUpdateViewportWithLastResults();
}

View File

@@ -430,6 +430,8 @@ public class SearchFragment extends BaseMwmFragment implements SearchListener, C
void showAllResultsOnMap()
{
SearchEngine.INSTANCE.updateViewportWithLastResults();
// The previous search should be cancelled before the new one is started, since previous search
// results are no longer needed.
SearchEngine.INSTANCE.cancel();

View File

@@ -372,4 +372,10 @@ extern "C"
{
g_framework->NativeFramework()->GetSearchAPI().CancelAllSearches();
}
JNIEXPORT void JNICALL
Java_app_organicmaps_sdk_search_SearchEngine_nativeUpdateViewportWithLastResults(JNIEnv * env, jclass clazz)
{
g_framework->NativeFramework()->UpdateViewport(g_results);
}
} // extern "C"

View File

@@ -1375,67 +1375,40 @@ void Framework::ShowSearchResult(search::Result const & res, bool animation)
SelectSearchResult(res, animation);
}
size_t Framework::ShowSearchResults(search::Results const & results)
void Framework::UpdateViewport(search::Results const & results)
{
using namespace search;
size_t count = results.GetCount();
if (count == 0)
return 0;
if (count == 1)
{
Result const & r = results[0];
if (!r.IsSuggest())
ShowSearchResult(r);
else
return 0;
}
FillSearchResultsMarks(true /* clear */, results);
// Setup viewport according to results.
m2::AnyRectD viewport = m_currentModelView.GlobalRect();
m2::PointD const center = viewport.Center();
double minDistance = numeric_limits<double>::max();
int minInd = -1;
for (size_t i = 0; i < count; ++i)
search::Result const * res = nullptr;
for (auto const & r : results)
{
Result const & r = results[i];
if (r.HasPoint())
{
double const dist = center.SquaredLength(r.GetFeatureCenter());
if (dist < minDistance)
{
minDistance = dist;
minInd = static_cast<int>(i);
res = &r;
}
}
}
if (minInd != -1)
if (res)
{
m2::PointD const pt = results[minInd].GetFeatureCenter();
if (m_currentModelView.isPerspective())
{
StopLocationFollow();
SetViewportCenter(pt);
return count;
}
m2::PointD const pt = res->GetFeatureCenter();
if (!viewport.IsPointInside(pt))
{
viewport.SetSizesToIncludePoint(pt);
double constexpr factor = 0.05;
viewport.Inflate(viewport.GetLocalRect().SizeX() * factor, viewport.GetLocalRect().SizeY() * factor);
StopLocationFollow();
ShowRect(viewport);
}
}
// Graphics engine can be recreated (on Android), so we always set up viewport here.
ShowRect(viewport);
return count;
}
void Framework::FillSearchResultsMarks(bool clear, search::Results const & results)
@@ -1563,7 +1536,7 @@ void Framework::CreateDrapeEngine(ref_ptr<dp::GraphicsContextFactory> contextFac
params.m_isChoosePositionMode, params.m_isChoosePositionMode, GetSelectedFeatureTriangles(),
m_routingManager.IsRoutingActive() && m_routingManager.IsRoutingFollowing(),
isAutozoomEnabled, simplifiedTrafficColors, std::nullopt /* arrow3dCustomDecl */,
std::move(overlaysShowStatsFn), std::move(onGraphicsContextInitialized),
std::move(overlaysShowStatsFn), std::move(onGraphicsContextInitialized),
std::move(params.m_renderInjectionHandler));
m_drapeEngine = make_unique_dp<df::DrapeEngine>(std::move(p));

View File

@@ -489,7 +489,7 @@ public:
// search result.
void ShowSearchResult(search::Result const & res, bool animation = true);
size_t ShowSearchResults(search::Results const & results);
void UpdateViewport(search::Results const & results);
void FillSearchResultsMarks(bool clear, search::Results const & results);
void FillSearchResultsMarks(SearchResultsIterT beg, SearchResultsIterT end, bool clear);
@@ -612,7 +612,7 @@ private:
/// This function can be used for enabling some experimental features for routing.
bool ParseRoutingDebugCommand(search::SearchParams const & params);
bool ParseAllTypesDebugCommand(search::SearchParams const & params);
void FillFeatureInfo(FeatureID const & fid, place_page::Info & info) const;