Search in sources :

Example 46 with PoiType

use of net.osmand.osm.PoiType 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 47 with PoiType

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

the class QuickSearchPoiFilterFragment method initPoiAdditionals.

private void initPoiAdditionals(Collection<PoiType> poiAdditionals, Set<String> excludedPoiAdditionalCategories) {
    Set<String> selectedCategories = new LinkedHashSet<>();
    Set<String> topTrueOnlyCategories = new LinkedHashSet<>();
    Set<String> topFalseOnlyCategories = new LinkedHashSet<>();
    for (PoiType poiType : poiAdditionals) {
        String category = poiType.getPoiAdditionalCategory();
        if (category != null) {
            topTrueOnlyCategories.add(category);
            topFalseOnlyCategories.add(category);
        }
    }
    for (PoiType poiType : poiAdditionals) {
        String category = poiType.getPoiAdditionalCategory();
        if (category == null) {
            category = "";
        }
        if (excludedPoiAdditionalCategories != null && excludedPoiAdditionalCategories.contains(category)) {
            topTrueOnlyCategories.remove(category);
            topFalseOnlyCategories.remove(category);
            continue;
        }
        if (!poiType.isTopVisible()) {
            topTrueOnlyCategories.remove(category);
        } else {
            topFalseOnlyCategories.remove(category);
        }
        String keyName = poiType.getKeyName().replace('_', ':').replace(' ', ':').toLowerCase();
        if (selectedPoiAdditionals.contains(keyName)) {
            selectedCategories.add(category);
        }
    }
    for (String category : topTrueOnlyCategories) {
        if (!showAllCategories.contains(category)) {
            showAllCategories.add(category);
        }
    }
    for (String category : topFalseOnlyCategories) {
        if (!collapsedCategories.contains(category) && !showAllCategories.contains(category)) {
            if (!selectedCategories.contains(category)) {
                collapsedCategories.add(category);
            }
            showAllCategories.add(category);
        }
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType)

Example 48 with PoiType

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

the class POIMapLayer method onPrepareBufferImage.

@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
    Set<PoiUIFilter> selectedPoiFilters = app.getPoiFilters().getSelectedPoiFilters();
    if (!this.filters.equals(selectedPoiFilters)) {
        this.filters = new TreeSet<>(selectedPoiFilters);
        data.clearCache();
    }
    List<Amenity> objects = Collections.emptyList();
    List<Amenity> fullObjects = new ArrayList<>();
    List<LatLon> fullObjectsLatLon = new ArrayList<>();
    List<LatLon> smallObjectsLatLon = new ArrayList<>();
    if (!filters.isEmpty()) {
        if (tileBox.getZoom() >= startZoom) {
            data.queryNewData(tileBox);
            objects = data.getResults();
            if (objects != null) {
                float iconSize = poiBackground.getWidth() * 3 / 2;
                QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
                for (Amenity o : objects) {
                    float x = tileBox.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
                    float y = tileBox.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
                    if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
                        canvas.drawBitmap(poiBackgroundSmall, x - poiBackgroundSmall.getWidth() / 2, y - poiBackgroundSmall.getHeight() / 2, paintIconBackground);
                        smallObjectsLatLon.add(new LatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude()));
                    } else {
                        fullObjects.add(o);
                        fullObjectsLatLon.add(new LatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude()));
                    }
                }
                for (Amenity o : fullObjects) {
                    int x = (int) tileBox.getPixXFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
                    int y = (int) tileBox.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
                    canvas.drawBitmap(poiBackground, x - poiBackground.getWidth() / 2, y - poiBackground.getHeight() / 2, paintIconBackground);
                    String id = null;
                    PoiType st = o.getType().getPoiTypeByKeyName(o.getSubType());
                    if (st != null) {
                        if (RenderingIcons.containsSmallIcon(st.getIconKeyName())) {
                            id = st.getIconKeyName();
                        } else if (RenderingIcons.containsSmallIcon(st.getOsmTag() + "_" + st.getOsmValue())) {
                            id = st.getOsmTag() + "_" + st.getOsmValue();
                        }
                    }
                    if (id != null) {
                        Bitmap bmp = RenderingIcons.getIcon(view.getContext(), id, false);
                        if (bmp != null) {
                            canvas.drawBitmap(bmp, x - bmp.getWidth() / 2, y - bmp.getHeight() / 2, paintIcon);
                        }
                    }
                }
                this.fullObjectsLatLon = fullObjectsLatLon;
                this.smallObjectsLatLon = smallObjectsLatLon;
            }
        }
    }
    mapTextLayer.putData(this, objects);
}
Also used : Amenity(net.osmand.data.Amenity) ArrayList(java.util.ArrayList) PoiType(net.osmand.osm.PoiType) QuadRect(net.osmand.data.QuadRect) Paint(android.graphics.Paint) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) LatLon(net.osmand.data.LatLon) Bitmap(android.graphics.Bitmap)

Example 49 with PoiType

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

the class AddPOIAction method getCategory.

private PoiCategory getCategory(Map<String, PoiType> allTranslatedNames) {
    String tp = getTagsFromParams().get(POI_TYPE_TAG);
    if (tp == null)
        return null;
    PoiType pt = allTranslatedNames.get(tp.toLowerCase());
    if (pt != null) {
        return pt.getCategory();
    } else
        return null;
}
Also used : AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType)

Aggregations

PoiType (net.osmand.osm.PoiType)49 AbstractPoiType (net.osmand.osm.AbstractPoiType)30 PoiCategory (net.osmand.osm.PoiCategory)11 MapPoiTypes (net.osmand.osm.MapPoiTypes)10 View (android.view.View)8 TextView (android.widget.TextView)8 Map (java.util.Map)8 Amenity (net.osmand.data.Amenity)8 ArrayList (java.util.ArrayList)7 LinkedHashMap (java.util.LinkedHashMap)7 AdapterView (android.widget.AdapterView)5 HashMap (java.util.HashMap)5 List (java.util.List)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)5 AutoCompleteTextView (android.widget.AutoCompleteTextView)4 LinkedHashSet (java.util.LinkedHashSet)4 LatLon (net.osmand.data.LatLon)4 PoiFilter (net.osmand.osm.PoiFilter)4 Node (net.osmand.osm.edit.Node)4