Search in sources :

Example 16 with MapPoiTypes

use of net.osmand.osm.MapPoiTypes in project Osmand by osmandapp.

the class QuickSearchPoiFilterFragment method processFilterFields.

private void processFilterFields() {
    OsmandApplication app = getMyApplication();
    String filterByName = filter.getFilterByName();
    if (!Algorithms.isEmpty(filterByName)) {
        int index;
        MapPoiTypes poiTypes = app.getPoiTypes();
        Map<String, PoiType> poiAdditionals = filter.getPoiAdditionals();
        Set<String> excludedPoiAdditionalCategories = getExcludedPoiAdditionalCategories();
        List<PoiType> otherAdditionalCategories = poiTypes.getOtherMapCategory().getPoiAdditionalsCategorized();
        if (!excludedPoiAdditionalCategories.contains("opening_hours")) {
            String keyNameOpen = app.getString(R.string.shared_string_is_open).replace(' ', '_').toLowerCase();
            String keyNameOpen24 = app.getString(R.string.shared_string_is_open_24_7).replace(' ', '_').toLowerCase();
            index = filterByName.indexOf(keyNameOpen24);
            if (index != -1) {
                selectedPoiAdditionals.add(keyNameOpen24);
                filterByName = filterByName.replaceAll(keyNameOpen24, "");
            }
            index = filterByName.indexOf(keyNameOpen);
            if (index != -1) {
                selectedPoiAdditionals.add(keyNameOpen);
                filterByName = filterByName.replaceAll(keyNameOpen, "");
            }
        }
        if (poiAdditionals != null) {
            Map<String, List<PoiType>> additionalsMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
            extractPoiAdditionals(poiAdditionals.values(), additionalsMap, excludedPoiAdditionalCategories, true);
            extractPoiAdditionals(otherAdditionalCategories, additionalsMap, excludedPoiAdditionalCategories, true);
            if (additionalsMap.size() > 0) {
                List<String> filters = new ArrayList<>(Arrays.asList(filterByName.split(" ")));
                for (Entry<String, List<PoiType>> entry : additionalsMap.entrySet()) {
                    for (PoiType poiType : entry.getValue()) {
                        String keyName = poiType.getKeyName().replace('_', ':').toLowerCase();
                        index = filters.indexOf(keyName);
                        if (index != -1) {
                            selectedPoiAdditionals.add(keyName);
                            filters.remove(index);
                        }
                    }
                }
                filterByName = TextUtils.join(" ", filters);
            }
        }
        if (filterByName.trim().length() > 0 && Algorithms.isEmpty(nameFilterText)) {
            nameFilterText = filterByName.trim();
        }
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) MapPoiTypes(net.osmand.osm.MapPoiTypes) List(java.util.List) ArrayList(java.util.ArrayList)

Example 17 with MapPoiTypes

use of net.osmand.osm.MapPoiTypes 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

MapPoiTypes (net.osmand.osm.MapPoiTypes)17 AbstractPoiType (net.osmand.osm.AbstractPoiType)11 PoiType (net.osmand.osm.PoiType)10 OsmandApplication (net.osmand.plus.OsmandApplication)7 PoiCategory (net.osmand.osm.PoiCategory)6 ArrayList (java.util.ArrayList)5 Drawable (android.graphics.drawable.Drawable)3 NonNull (android.support.annotation.NonNull)3 View (android.view.View)3 TextView (android.widget.TextView)3 List (java.util.List)3 Map (java.util.Map)3 Amenity (net.osmand.data.Amenity)3 DialogInterface (android.content.DialogInterface)2 AlertDialog (android.support.v7.app.AlertDialog)2 AutoCompleteTextView (android.widget.AutoCompleteTextView)2 Button (android.widget.Button)2 ImageButton (android.widget.ImageButton)2 LinearLayout (android.widget.LinearLayout)2 File (java.io.File)2