mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 04:53:36 +00:00
[android] Expected "Show on map" search button behaviour.
Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
committed by
Konstantin Pastbin
parent
bbb28107b8
commit
1151f0fb75
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user