Added search of poi additionals

This commit is contained in:
Alexey Kulish 2016-11-09 21:29:18 +03:00
parent a7311bee9e
commit 050aadf201
5 changed files with 69 additions and 49 deletions

View file

@ -7,6 +7,7 @@ import net.osmand.ResultMatcher;
import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.data.Amenity;
import net.osmand.data.LatLon;
import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.MapPoiTypes;
import net.osmand.search.core.CustomSearchPoiFilter;
import net.osmand.search.core.ObjectType;
@ -220,6 +221,8 @@ public class SearchUICore {
}
return MapUtils.getDistance(r1.location, r2.location) < similarityRadius;
}
} else if (r1.object != null && r2.object != null) {
return r1.object == r2.object;
}
return false;
}

View file

@ -1,20 +1,7 @@
package net.osmand.search.core;
import gnu.trove.list.array.TIntArrayList;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.TreeSet;
import com.jwetherell.openmap.common.LatLonPoint;
import com.jwetherell.openmap.common.UTMPoint;
import net.osmand.CollatorStringMatcher.StringMatcherMode;
import net.osmand.ResultMatcher;
@ -44,8 +31,20 @@ import net.osmand.util.GeoPointParserUtil;
import net.osmand.util.GeoPointParserUtil.GeoParsedPoint;
import net.osmand.util.MapUtils;
import com.jwetherell.openmap.common.LatLonPoint;
import com.jwetherell.openmap.common.UTMPoint;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import gnu.trove.list.array.TIntArrayList;
public class SearchCoreFactory {
@ -533,35 +532,43 @@ public class SearchCoreFactory {
categories = types.getCategories(false);
}
// results.clear();
TreeMap<String, AbstractPoiType> results = new TreeMap<String, AbstractPoiType>() ;
List<AbstractPoiType> results = new ArrayList<AbstractPoiType>() ;
NameStringMatcher nm = phrase.getNameStringMatcher();
for (PoiFilter pf : topVisibleFilters) {
if (!phrase.isUnknownSearchWordPresent() || nm.matches(pf.getTranslation())) {
results.put(pf.getTranslation(), pf);
results.add(pf);
}
}
if (phrase.isUnknownSearchWordPresent()) {
for (PoiCategory c : categories) {
if (!phrase.isUnknownSearchWordPresent() || nm.matches(c.getTranslation())) {
results.put(c.getTranslation(), c);
if (!results.contains(c) && nm.matches(c.getTranslation())) {
results.add(c);
}
}
Iterator<Entry<String, PoiType>> it = translatedNames.entrySet().iterator();
while (it.hasNext()) {
Entry<String, PoiType> e = it.next();
if (e.getValue().getCategory() != types.getOtherMapCategory()
&& (nm.matches(e.getKey()) || nm.matches(e.getValue().getTranslation()))) {
results.put(e.getValue().getTranslation(), e.getValue());
PoiType pt = e.getValue();
if (pt.getCategory() != types.getOtherMapCategory()) {
if (!results.contains(pt) && (nm.matches(e.getKey()) || nm.matches(pt.getTranslation()))) {
results.add(pt);
}
List<PoiType> additionals = pt.getPoiAdditionals();
if (additionals != null) {
for (PoiType a : additionals) {
if (!a.isReference() && !results.contains(a) && (nm.matches(a.getKeyName()) || nm.matches(a.getTranslation()))) {
results.add(a);
}
}
}
}
}
}
Iterator<Entry<String, AbstractPoiType>> it = results.entrySet().iterator();
while(it.hasNext()) {
Entry<String, AbstractPoiType> p = it.next();
for (AbstractPoiType pt : results) {
SearchResult res = new SearchResult(phrase);
res.localeName = p.getKey();
res.object = p.getValue();
res.priority = SEARCH_AMENITY_TYPE_PRIORITY;
res.localeName = pt.getTranslation();
res.object = pt;
res.priority = SEARCH_AMENITY_TYPE_PRIORITY + (pt instanceof PoiCategory ? 0.0 : 0.1);
res.priorityDistance = 0;
res.objectType = ObjectType.POI_TYPE;
resultMatcher.publish(res);

View file

@ -36,6 +36,7 @@ import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.ResultMatcher;
@ -43,6 +44,7 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiType;
import net.osmand.plus.AppInitializer;
import net.osmand.plus.AppInitializer.AppInitializeListener;
import net.osmand.plus.GPXUtilities;
@ -611,16 +613,16 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
}
public void show() {
paused = false;
if (useMapCenter) {
LatLon mapCenter = getMapActivity().getMapView().getCurrentRotatedTileBox().getCenterLatLon();
SearchSettings ss = searchUICore.getSearchSettings().setOriginalLocation(
new LatLon(mapCenter.getLatitude(), mapCenter.getLongitude()));
searchUICore.updateSettings(ss);
updateUseMapCenterUI();
forceUpdateLocationUI(mapCenter, null);
updateLocationUI(mapCenter, null);
}
getDialog().show();
paused = false;
hidden = false;
if (interruptedSearch) {
interruptedSearch = false;
@ -1142,6 +1144,26 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
}
public void completeQueryWithObject(SearchResult sr) {
if (sr.object instanceof PoiType && ((PoiType) sr.object).isAdditional()) {
PoiType additional = (PoiType) sr.object;
AbstractPoiType parent = additional.getParentType();
if (parent != null) {
PoiUIFilter custom = app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + parent.getKeyName());
if (custom != null) {
custom.clearFilter();
custom.updateTypesToAccept(parent);
custom.setFilterByName(additional.getKeyName().replace('_', ':').toLowerCase());
SearchPhrase phrase = searchUICore.getPhrase();
sr = new SearchResult(phrase);
sr.localeName = custom.getName();
sr.object = custom;
sr.priority = SEARCH_AMENITY_TYPE_PRIORITY;
sr.priorityDistance = 0;
sr.objectType = ObjectType.POI_TYPE;
}
}
}
searchUICore.selectSearchResult(sr);
String txt = searchUICore.getPhrase().getText(true);
searchQuery = txt;
@ -1326,20 +1348,6 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
}
}
private void forceUpdateLocationUI(LatLon latLon, Float heading) {
if (latLon != null) {
if (mainSearchFragment != null) {
mainSearchFragment.updateLocation(latLon, heading);
}
if (historySearchFragment != null) {
historySearchFragment.updateLocation(latLon, heading);
}
if (categoriesSearchFragment != null) {
categoriesSearchFragment.updateLocation(latLon, heading);
}
}
}
private void updateUseMapCenterUI() {
if (!paused && !cancelPrev) {
if (mainSearchFragment != null) {

View file

@ -11,6 +11,7 @@ import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.data.Amenity;
@ -405,7 +406,6 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
private void updateDistanceDirection(View view, QuickSearchListItem listItem) {
TextView distanceText = (TextView) view.findViewById(R.id.distance);
ImageView direction = (ImageView) view.findViewById(R.id.direction);
/*
SearchPhrase phrase = listItem.getSearchResult().requiredSearchPhrase;
LatLon loc = location;
if(phrase != null && useMapCenter) {
@ -414,8 +414,7 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
loc = ol;
}
}
*/
DashLocationFragment.updateLocationView(useMapCenter, location,
DashLocationFragment.updateLocationView(useMapCenter, loc,
heading, direction, distanceText,
listItem.getSearchResult().location.getLatitude(),
listItem.getSearchResult().location.getLongitude(),

View file

@ -266,6 +266,9 @@ public class QuickSearchListItem {
((PoiType) abstractPoiType).getOsmTag() + "_" + ((PoiType) abstractPoiType).getOsmValue())) {
return ((PoiType) abstractPoiType).getOsmTag() + "_" + ((PoiType) abstractPoiType).getOsmValue();
}
if (abstractPoiType instanceof PoiType && ((PoiType) abstractPoiType).getParentType() != null) {
return getPoiTypeIconName(((PoiType) abstractPoiType).getParentType());
}
return null;
}