use of net.osmand.osm.PoiCategory in project Osmand by osmandapp.
the class QuickSearchDialogFragment method showInstance.
public static boolean showInstance(@NonNull MapActivity mapActivity, @NonNull String searchQuery, @Nullable Object object, QuickSearchType searchType, QuickSearchTab showSearchTab, @Nullable LatLon latLon) {
try {
if (mapActivity.isActivityDestroyed()) {
return false;
}
mapActivity.getMyApplication().logEvent(mapActivity, "search_open");
Bundle bundle = new Bundle();
if (object != null) {
bundle.putBoolean(QUICK_SEARCH_RUN_SEARCH_FIRST_TIME_KEY, true);
String objectLocalizedName = searchQuery;
if (object instanceof PoiCategory) {
PoiCategory c = (PoiCategory) object;
objectLocalizedName = c.getTranslation();
SearchUICore searchUICore = mapActivity.getMyApplication().getSearchUICore().getCore();
SearchPhrase phrase = searchUICore.resetPhrase(objectLocalizedName + " ");
SearchResult sr = new SearchResult(phrase);
sr.localeName = objectLocalizedName;
sr.object = c;
sr.priority = SEARCH_AMENITY_TYPE_PRIORITY;
sr.priorityDistance = 0;
sr.objectType = ObjectType.POI_TYPE;
searchUICore.selectSearchResult(sr);
bundle.putBoolean(QUICK_SEARCH_PHRASE_DEFINED_KEY, true);
} else if (object instanceof PoiUIFilter) {
PoiUIFilter filter = (PoiUIFilter) object;
objectLocalizedName = filter.getName();
SearchUICore searchUICore = mapActivity.getMyApplication().getSearchUICore().getCore();
SearchPhrase phrase = searchUICore.resetPhrase();
SearchResult sr = new SearchResult(phrase);
sr.localeName = objectLocalizedName;
sr.object = filter;
sr.priority = SEARCH_AMENITY_TYPE_PRIORITY;
sr.priorityDistance = 0;
sr.objectType = ObjectType.POI_TYPE;
searchUICore.selectSearchResult(sr);
bundle.putBoolean(QUICK_SEARCH_PHRASE_DEFINED_KEY, true);
}
searchQuery = objectLocalizedName.trim() + " ";
} else if (!Algorithms.isEmpty(searchQuery)) {
bundle.putBoolean(QUICK_SEARCH_RUN_SEARCH_FIRST_TIME_KEY, true);
}
bundle.putString(QUICK_SEARCH_QUERY_KEY, searchQuery);
bundle.putString(QUICK_SEARCH_SHOW_TAB_KEY, showSearchTab.name());
bundle.putString(QUICK_SEARCH_TYPE_KEY, searchType.name());
if (latLon != null) {
bundle.putDouble(QUICK_SEARCH_LAT_KEY, latLon.getLatitude());
bundle.putDouble(QUICK_SEARCH_LON_KEY, latLon.getLongitude());
}
QuickSearchDialogFragment fragment = new QuickSearchDialogFragment();
fragment.setArguments(bundle);
fragment.show(mapActivity.getSupportFragmentManager(), TAG);
return true;
} catch (RuntimeException e) {
return false;
}
}
use of net.osmand.osm.PoiCategory in project Osmand by osmandapp.
the class QuickSearchPoiFilterFragment method getExcludedPoiAdditionalCategories.
@NonNull
private Set<String> getExcludedPoiAdditionalCategories() {
Set<String> excludedPoiAdditionalCategories = new LinkedHashSet<>();
if (filter.getAcceptedTypes().size() == 0) {
return excludedPoiAdditionalCategories;
}
MapPoiTypes poiTypes = getMyApplication().getPoiTypes();
PoiCategory topCategory = null;
for (Entry<PoiCategory, LinkedHashSet<String>> entry : filter.getAcceptedTypes().entrySet()) {
if (topCategory == null) {
topCategory = entry.getKey();
}
if (entry.getValue() != null) {
Set<String> excluded = new LinkedHashSet<>();
for (String keyName : entry.getValue()) {
PoiType poiType = poiTypes.getPoiTypeByKeyInCategory(topCategory, keyName);
if (poiType != null) {
collectExcludedPoiAdditionalCategories(poiType, excluded);
if (!poiType.isReference()) {
PoiFilter poiFilter = poiType.getFilter();
if (poiFilter != null) {
collectExcludedPoiAdditionalCategories(poiFilter, excluded);
}
PoiCategory poiCategory = poiType.getCategory();
if (poiCategory != null) {
collectExcludedPoiAdditionalCategories(poiCategory, excluded);
}
}
}
if (excludedPoiAdditionalCategories.size() == 0) {
excludedPoiAdditionalCategories.addAll(excluded);
} else {
excludedPoiAdditionalCategories.retainAll(excluded);
}
excluded.clear();
}
}
}
if (topCategory != null && topCategory.getExcludedPoiAdditionalCategories() != null) {
excludedPoiAdditionalCategories.addAll(topCategory.getExcludedPoiAdditionalCategories());
}
return excludedPoiAdditionalCategories;
}
use of net.osmand.osm.PoiCategory in project Osmand by osmandapp.
the class OsmandMapLayer method findAmenity.
public Amenity findAmenity(OsmandApplication app, long id, List<String> names, LatLon latLon, int radius) {
QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), radius);
List<Amenity> amenities = app.getResourceManager().searchAmenities(new BinaryMapIndexReader.SearchPoiTypeFilter() {
@Override
public boolean accept(PoiCategory type, String subcategory) {
return true;
}
@Override
public boolean isEmpty() {
return false;
}
}, rect.top, rect.left, rect.bottom, rect.right, -1, null);
Amenity res = null;
for (Amenity amenity : amenities) {
Long amenityId = amenity.getId() >> 1;
if (amenityId == id) {
res = amenity;
break;
}
}
if (res == null && names != null && names.size() > 0) {
for (Amenity amenity : amenities) {
for (String name : names) {
if (name.equals(amenity.getName())) {
res = amenity;
break;
}
}
if (res != null) {
break;
}
}
}
return res;
}
use of net.osmand.osm.PoiCategory in project Osmand by osmandapp.
the class QuickSearchHelper method findAmenity.
public Amenity findAmenity(String name, double lat, double lon, String lang, boolean transliterate) {
QuadRect rect = MapUtils.calculateLatLonBbox(lat, lon, 15);
List<Amenity> amenities = app.getResourceManager().searchAmenities(new SearchPoiTypeFilter() {
@Override
public boolean accept(PoiCategory type, String subcategory) {
return true;
}
@Override
public boolean isEmpty() {
return false;
}
}, rect.top, rect.left, rect.bottom, rect.right, -1, null);
MapPoiTypes types = app.getPoiTypes();
for (Amenity amenity : amenities) {
String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(amenity, lang, transliterate);
if (poiSimpleFormat.equals(name)) {
return amenity;
}
}
for (Amenity amenity : amenities) {
String amenityName = amenity.getName(lang, transliterate);
if (Algorithms.isEmpty(amenityName)) {
AbstractPoiType st = types.getAnyPoiTypeByKey(amenity.getSubType());
if (st != null) {
amenityName = st.getTranslation();
} else {
amenityName = amenity.getSubType();
}
}
if (name.contains(amenityName)) {
return amenity;
}
}
return null;
}
Aggregations