From 77faa8d0901febcec375975e36299674d02a65e2 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 22 Aug 2016 18:17:29 +0300 Subject: [PATCH] Fix show on map search by name filter --- .../net/osmand/plus/poi/NominatimPoiFilter.java | 2 +- OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java | 16 +++++++++++----- .../net/osmand/plus/poi/SearchByNameFilter.java | 2 +- .../plus/search/QuickSearchDialogFragment.java | 3 ++- .../src/net/osmand/plus/views/POIMapLayer.java | 1 - 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/poi/NominatimPoiFilter.java b/OsmAnd/src/net/osmand/plus/poi/NominatimPoiFilter.java index f54c02abdd..76fbe7649e 100644 --- a/OsmAnd/src/net/osmand/plus/poi/NominatimPoiFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/NominatimPoiFilter.java @@ -73,7 +73,7 @@ public class NominatimPoiFilter extends PoiUIFilter { @Override protected List searchAmenitiesInternal(double lat, double lon, double topLatitude, - double bottomLatitude, double leftLongitude, double rightLongitude, ResultMatcher matcher) { + double bottomLatitude, double leftLongitude, double rightLongitude, int zoom, ResultMatcher matcher) { final int deviceApiVersion = android.os.Build.VERSION.SDK_INT; String NOMINATIM_API; if (deviceApiVersion >= android.os.Build.VERSION_CODES.GINGERBREAD) { diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java index 6ab825118d..90f462ab16 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiUIFilter.java @@ -202,6 +202,12 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable public void clearPreviousZoom() { distanceInd = 0; } + + public void clearCurrentResults() { + if (currentSearchResult != null) { + currentSearchResult = new ArrayList<>(); + } + } public List initializeNewSearch(double lat, double lon, int firstTimeLimit, ResultMatcher matcher) { clearPreviousZoom(); @@ -236,7 +242,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable double bottomLatitude = Math.max(lat - (distance / baseDistY), -84.); double leftLongitude = Math.max(lon - (distance / baseDistX), -180); double rightLongitude = Math.min(lon + (distance / baseDistX), 180); - return searchAmenitiesInternal(lat, lon, topLatitude, bottomLatitude, leftLongitude, rightLongitude, matcher); + return searchAmenitiesInternal(lat, lon, topLatitude, bottomLatitude, leftLongitude, rightLongitude, -1, matcher); } public List searchAmenities(double top, double left, double bottom, double right, int zoom, @@ -254,8 +260,8 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable } } } - List amenities = app.getResourceManager().searchAmenities(this, top, left, bottom, right, zoom, - wrapResultMatcher(matcher)); + List amenities = searchAmenitiesInternal(top / 2 + bottom / 2, left / 2 + right / 2, + top, bottom, left, right, zoom, matcher); results.addAll(amenities); return results; } @@ -265,9 +271,9 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable } protected List searchAmenitiesInternal(double lat, double lon, double topLatitude, - double bottomLatitude, double leftLongitude, double rightLongitude, final ResultMatcher matcher) { + double bottomLatitude, double leftLongitude, double rightLongitude, int zoom, final ResultMatcher matcher) { return app.getResourceManager().searchAmenities(this, - topLatitude, leftLongitude, bottomLatitude, rightLongitude, -1, wrapResultMatcher(matcher)); + topLatitude, leftLongitude, bottomLatitude, rightLongitude, zoom, wrapResultMatcher(matcher)); } public AmenityNameFilter getNameFilter(String filter) { diff --git a/OsmAnd/src/net/osmand/plus/poi/SearchByNameFilter.java b/OsmAnd/src/net/osmand/plus/poi/SearchByNameFilter.java index ca85a10744..27449990bd 100644 --- a/OsmAnd/src/net/osmand/plus/poi/SearchByNameFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/SearchByNameFilter.java @@ -32,7 +32,7 @@ public class SearchByNameFilter extends PoiUIFilter { @Override protected List searchAmenitiesInternal(double lat, double lon, double topLatitude, - double bottomLatitude, double leftLongitude, double rightLongitude, final ResultMatcher matcher) { + double bottomLatitude, double leftLongitude, double rightLongitude, int zoom, final ResultMatcher matcher) { currentSearchResult = new ArrayList(); final int limit = distanceInd == 0 ? 500 : -1; List result = Collections.emptyList(); diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 7123a39a22..e0f5657cd6 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -219,9 +219,10 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC } else if (searchPhrase.isNoSelectedType() || searchPhrase.isLastWord(ObjectType.POI_TYPE)) { PoiUIFilter filter; if (searchPhrase.isNoSelectedType()) { - filter = new PoiUIFilter(null, app, ""); + filter = app.getPoiFilters().getSearchByNamePOIFilter(); if (!Algorithms.isEmpty(searchPhrase.getUnknownSearchWord())) { filter.setFilterByName(searchPhrase.getUnknownSearchWord()); + filter.clearCurrentResults(); } } else if (searchPhrase.getLastSelectedWord().getResult().object instanceof AbstractPoiType) { if (searchPhrase.isNoSelectedType()) { diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index 4a575a0b6b..c586cd655a 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -80,7 +80,6 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon private Bitmap poiBackgroundSmall; private OsmandMapTileView view; - private final static int MAXIMUM_SHOW_AMENITIES = 5; private RoutingHelper routingHelper; private Set filters = new TreeSet<>();