Search in sources :

Example 26 with PoiCategory

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;
    }
}
Also used : Bundle(android.os.Bundle) PoiCategory(net.osmand.osm.PoiCategory) SearchUICore(net.osmand.search.SearchUICore) SearchResult(net.osmand.search.core.SearchResult) SpannableString(android.text.SpannableString) SearchPhrase(net.osmand.search.core.SearchPhrase) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 27 with PoiCategory

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) PoiFilter(net.osmand.osm.PoiFilter) PoiCategory(net.osmand.osm.PoiCategory) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) MapPoiTypes(net.osmand.osm.MapPoiTypes) NonNull(android.support.annotation.NonNull)

Example 28 with PoiCategory

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;
}
Also used : Amenity(net.osmand.data.Amenity) PoiCategory(net.osmand.osm.PoiCategory) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) QuadRect(net.osmand.data.QuadRect)

Example 29 with PoiCategory

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;
}
Also used : Amenity(net.osmand.data.Amenity) SearchPoiTypeFilter(net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter) PoiCategory(net.osmand.osm.PoiCategory) AbstractPoiType(net.osmand.osm.AbstractPoiType) QuadRect(net.osmand.data.QuadRect) MapPoiTypes(net.osmand.osm.MapPoiTypes)

Aggregations

PoiCategory (net.osmand.osm.PoiCategory)29 PoiType (net.osmand.osm.PoiType)11 Amenity (net.osmand.data.Amenity)9 AbstractPoiType (net.osmand.osm.AbstractPoiType)9 MapPoiTypes (net.osmand.osm.MapPoiTypes)6 View (android.view.View)5 NonNull (android.support.annotation.NonNull)4 AdapterView (android.widget.AdapterView)4 TextView (android.widget.TextView)4 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)4 QuadRect (net.osmand.data.QuadRect)4 OsmandApplication (net.osmand.plus.OsmandApplication)4 DialogInterface (android.content.DialogInterface)3 AlertDialog (android.support.v7.app.AlertDialog)3 AutoCompleteTextView (android.widget.AutoCompleteTextView)3 Button (android.widget.Button)3 PoiFilter (net.osmand.osm.PoiFilter)3 CustomSearchPoiFilter (net.osmand.search.core.CustomSearchPoiFilter)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2