Search, go to nearest point with map centered

This commit is contained in:
androiddevkotlin 2021-04-11 23:23:45 +03:00
parent 63e1ffbf1d
commit d61718cdfc
2 changed files with 33 additions and 21 deletions

View file

@ -101,6 +101,7 @@ public class MenuBuilder {
protected static final String[] arrowChars = new String[]{"=>", " - "}; protected static final String[] arrowChars = new String[]{"=>", " - "};
protected final String NEAREST_WIKI_KEY = "nearest_wiki_key"; protected final String NEAREST_WIKI_KEY = "nearest_wiki_key";
protected final String NEAREST_POI_KEY = "nearest_poi_key"; protected final String NEAREST_POI_KEY = "nearest_poi_key";
private static final int LIMIT = 10000;
protected MapActivity mapActivity; protected MapActivity mapActivity;
protected MapContextMenu mapContextMenu; protected MapContextMenu mapContextMenu;
@ -1217,13 +1218,13 @@ public class MenuBuilder {
return new CollapsableView(textView, this, collapsed); return new CollapsableView(textView, this, collapsed);
} }
protected CollapsableView getCollapsableView(final Context context, boolean collapsed, List<Amenity> nearestAmenities, String nearestPoiType) { protected CollapsableView getCollapsableView(Context context, boolean collapsed, List<Amenity> nearestAmenities, String nearestPoiType) {
final LinearLayout view = buildCollapsableContentView(context, collapsed, true); LinearLayout view = buildCollapsableContentView(context, collapsed, true);
for (final Amenity poi : nearestAmenities) { for (final Amenity poi : nearestAmenities) {
TextViewEx button = buildButtonInCollapsableView(context, false, false); TextViewEx button = buildButtonInCollapsableView(context, false, false);
final PointDescription pointDescription = mapActivity.getMapLayers().getPoiMapLayer().getObjectName(poi); final PointDescription pointDescription = mapActivity.getMapLayers().getPoiMapLayer().getObjectName(poi);
String name = mapActivity.getMapLayers().getPoiMapLayer().getObjectName(poi).getName(); String name = pointDescription.getName();
if (Algorithms.isBlank(name)) { if (Algorithms.isBlank(name)) {
name = AmenityMenuController.getTypeStr(poi); name = AmenityMenuController.getTypeStr(poi);
} }
@ -1235,6 +1236,7 @@ public class MenuBuilder {
public void onClick(View v) { public void onClick(View v) {
LatLon latLon = new LatLon(poi.getLocation().getLatitude(), poi.getLocation().getLongitude()); LatLon latLon = new LatLon(poi.getLocation().getLatitude(), poi.getLocation().getLongitude());
mapActivity.getContextMenu().show(latLon, pointDescription, poi); mapActivity.getContextMenu().show(latLon, pointDescription, poi);
mapActivity.setMapLocation(poi.getLocation().getLatitude(), poi.getLocation().getLongitude());
} }
}); });
view.addView(button); view.addView(button);
@ -1398,10 +1400,19 @@ public class MenuBuilder {
} }
private List<Amenity> getSortedAmenities(PoiUIFilter filter, final LatLon latLon) { private List<Amenity> getSortedAmenities(PoiUIFilter filter, final LatLon latLon) {
QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), 250); int radius = 250;
QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), radius);
List<Amenity> nearestAmenities = getAmenities(rect, filter); List<Amenity> nearestAmenities = getAmenities(rect, filter);
nearestAmenities.remove(amenity); nearestAmenities.remove(amenity);
boolean isWikiFilter = filter.getFilterId().equals("std_osmwiki");
for (; nearestAmenities.size() < 10 && !isWikiFilter; radius += 10) {
rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), radius);
nearestAmenities = getAmenities(rect, filter);
}
Collections.sort(nearestAmenities, new Comparator<Amenity>() { Collections.sort(nearestAmenities, new Comparator<Amenity>() {
@Override @Override
@ -1411,6 +1422,7 @@ public class MenuBuilder {
return Double.compare(d1, d2); return Double.compare(d1, d2);
} }
}); });
return nearestAmenities; return nearestAmenities;
} }

View file

@ -313,7 +313,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
public List<Amenity> searchAmenities(double top, double left, double bottom, double right, int zoom, public List<Amenity> searchAmenities(double top, double left, double bottom, double right, int zoom,
ResultMatcher<Amenity> matcher) { ResultMatcher<Amenity> matcher) {
List<Amenity> results = new ArrayList<Amenity>(); List<Amenity> results = new ArrayList<>();
List<Amenity> tempResults = currentSearchResult; List<Amenity> tempResults = currentSearchResult;
if (tempResults != null) { if (tempResults != null) {
for (Amenity a : tempResults) { for (Amenity a : tempResults) {