mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 13:03: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);
|
nativeShowResult(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MainThread
|
||||||
|
public void updateViewportWithLastResults()
|
||||||
|
{
|
||||||
|
nativeUpdateViewportWithLastResults();
|
||||||
|
}
|
||||||
|
|
||||||
public void initialize()
|
public void initialize()
|
||||||
{
|
{
|
||||||
nativeInit();
|
nativeInit();
|
||||||
@@ -224,4 +230,6 @@ public enum SearchEngine implements SearchListener, MapSearchListener,
|
|||||||
private static native void nativeCancelEverywhereSearch();
|
private static native void nativeCancelEverywhereSearch();
|
||||||
|
|
||||||
private static native void nativeCancelAllSearches();
|
private static native void nativeCancelAllSearches();
|
||||||
|
|
||||||
|
private static native void nativeUpdateViewportWithLastResults();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -430,6 +430,8 @@ public class SearchFragment extends BaseMwmFragment implements SearchListener, C
|
|||||||
|
|
||||||
void showAllResultsOnMap()
|
void showAllResultsOnMap()
|
||||||
{
|
{
|
||||||
|
SearchEngine.INSTANCE.updateViewportWithLastResults();
|
||||||
|
|
||||||
// The previous search should be cancelled before the new one is started, since previous search
|
// The previous search should be cancelled before the new one is started, since previous search
|
||||||
// results are no longer needed.
|
// results are no longer needed.
|
||||||
SearchEngine.INSTANCE.cancel();
|
SearchEngine.INSTANCE.cancel();
|
||||||
|
|||||||
@@ -372,4 +372,10 @@ extern "C"
|
|||||||
{
|
{
|
||||||
g_framework->NativeFramework()->GetSearchAPI().CancelAllSearches();
|
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"
|
} // extern "C"
|
||||||
|
|||||||
@@ -1375,67 +1375,40 @@ void Framework::ShowSearchResult(search::Result const & res, bool animation)
|
|||||||
SelectSearchResult(res, 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.
|
// Setup viewport according to results.
|
||||||
m2::AnyRectD viewport = m_currentModelView.GlobalRect();
|
m2::AnyRectD viewport = m_currentModelView.GlobalRect();
|
||||||
m2::PointD const center = viewport.Center();
|
m2::PointD const center = viewport.Center();
|
||||||
|
|
||||||
double minDistance = numeric_limits<double>::max();
|
double minDistance = numeric_limits<double>::max();
|
||||||
int minInd = -1;
|
search::Result const * res = nullptr;
|
||||||
for (size_t i = 0; i < count; ++i)
|
for (auto const & r : results)
|
||||||
{
|
{
|
||||||
Result const & r = results[i];
|
|
||||||
if (r.HasPoint())
|
if (r.HasPoint())
|
||||||
{
|
{
|
||||||
double const dist = center.SquaredLength(r.GetFeatureCenter());
|
double const dist = center.SquaredLength(r.GetFeatureCenter());
|
||||||
if (dist < minDistance)
|
if (dist < minDistance)
|
||||||
{
|
{
|
||||||
minDistance = dist;
|
minDistance = dist;
|
||||||
minInd = static_cast<int>(i);
|
res = &r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minInd != -1)
|
if (res)
|
||||||
{
|
{
|
||||||
m2::PointD const pt = results[minInd].GetFeatureCenter();
|
m2::PointD const pt = res->GetFeatureCenter();
|
||||||
|
|
||||||
if (m_currentModelView.isPerspective())
|
|
||||||
{
|
|
||||||
StopLocationFollow();
|
|
||||||
SetViewportCenter(pt);
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!viewport.IsPointInside(pt))
|
if (!viewport.IsPointInside(pt))
|
||||||
{
|
{
|
||||||
viewport.SetSizesToIncludePoint(pt);
|
viewport.SetSizesToIncludePoint(pt);
|
||||||
|
double constexpr factor = 0.05;
|
||||||
|
viewport.Inflate(viewport.GetLocalRect().SizeX() * factor, viewport.GetLocalRect().SizeY() * factor);
|
||||||
|
|
||||||
StopLocationFollow();
|
StopLocationFollow();
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Graphics engine can be recreated (on Android), so we always set up viewport here.
|
|
||||||
ShowRect(viewport);
|
ShowRect(viewport);
|
||||||
|
}
|
||||||
return count;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Framework::FillSearchResultsMarks(bool clear, search::Results const & results)
|
void Framework::FillSearchResultsMarks(bool clear, search::Results const & results)
|
||||||
|
|||||||
@@ -489,7 +489,7 @@ public:
|
|||||||
// search result.
|
// search result.
|
||||||
void ShowSearchResult(search::Result const & res, bool animation = true);
|
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(bool clear, search::Results const & results);
|
||||||
void FillSearchResultsMarks(SearchResultsIterT beg, SearchResultsIterT end, bool clear);
|
void FillSearchResultsMarks(SearchResultsIterT beg, SearchResultsIterT end, bool clear);
|
||||||
|
|||||||
Reference in New Issue
Block a user