Search in sources :

Example 1 with PoiFilter

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

the class ContextMenuLayer method getPublicTransportTypes.

private List<String> getPublicTransportTypes() {
    if (publicTransportTypes == null) {
        publicTransportTypes = new ArrayList<>();
        List<PoiFilter> filters = activity.getMyApplication().getPoiTypes().getPoiCategoryByName("transportation").getPoiFilters();
        for (PoiFilter poiFilter : filters) {
            if (poiFilter.getKeyName().equals("public_transport")) {
                for (PoiType poiType : poiFilter.getPoiTypes()) {
                    publicTransportTypes.add(poiType.getKeyName());
                    for (PoiType poiAdditionalType : poiType.getPoiAdditionals()) {
                        publicTransportTypes.add(poiAdditionalType.getKeyName());
                    }
                }
            }
        }
    }
    return publicTransportTypes;
}
Also used : PoiFilter(net.osmand.osm.PoiFilter) PoiType(net.osmand.osm.PoiType)

Example 2 with PoiFilter

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

the class QuickSearchListItem method getTypeName.

public static String getTypeName(OsmandApplication app, SearchResult searchResult) {
    switch(searchResult.objectType) {
        case CITY:
            City city = (City) searchResult.object;
            return getCityTypeStr(app, city.getType());
        case POSTCODE:
            return app.getString(R.string.postcode);
        case VILLAGE:
            city = (City) searchResult.object;
            if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
                if (searchResult.distRelatedObjectName > 0) {
                    return getCityTypeStr(app, city.getType()) + " • " + OsmAndFormatter.getFormattedDistance((float) searchResult.distRelatedObjectName, app) + " " + app.getString(R.string.shared_string_from) + " " + searchResult.localeRelatedObjectName;
                } else {
                    return getCityTypeStr(app, city.getType()) + ", " + searchResult.localeRelatedObjectName;
                }
            } else {
                return getCityTypeStr(app, city.getType());
            }
        case STREET:
            StringBuilder streetBuilder = new StringBuilder();
            if (searchResult.localeName.endsWith(")")) {
                int i = searchResult.localeName.indexOf('(');
                if (i > 0) {
                    streetBuilder.append(searchResult.localeName.substring(i + 1, searchResult.localeName.length() - 1));
                }
            }
            if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
                if (streetBuilder.length() > 0) {
                    streetBuilder.append(", ");
                }
                streetBuilder.append(searchResult.localeRelatedObjectName);
            }
            return streetBuilder.toString();
        case HOUSE:
            if (searchResult.relatedObject != null) {
                Street relatedStreet = (Street) searchResult.relatedObject;
                if (relatedStreet.getCity() != null) {
                    return searchResult.localeRelatedObjectName + ", " + relatedStreet.getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
                } else {
                    return searchResult.localeRelatedObjectName;
                }
            }
            return "";
        case STREET_INTERSECTION:
            Street street = (Street) searchResult.object;
            if (street.getCity() != null) {
                return street.getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
            }
            return "";
        case POI_TYPE:
            String res = "";
            if (searchResult.object instanceof AbstractPoiType) {
                AbstractPoiType abstractPoiType = (AbstractPoiType) searchResult.object;
                if (abstractPoiType instanceof PoiCategory) {
                    res = "";
                } else if (abstractPoiType instanceof PoiFilter) {
                    PoiFilter poiFilter = (PoiFilter) abstractPoiType;
                    res = poiFilter.getPoiCategory() != null ? poiFilter.getPoiCategory().getTranslation() : "";
                } else if (abstractPoiType instanceof PoiType) {
                    PoiType poiType = (PoiType) abstractPoiType;
                    res = poiType.getParentType() != null ? poiType.getParentType().getTranslation() : null;
                    if (res == null) {
                        res = poiType.getCategory() != null ? poiType.getCategory().getTranslation() : null;
                    }
                    if (res == null) {
                        res = "";
                    }
                } else {
                    res = "";
                }
            } else if (searchResult.object instanceof CustomSearchPoiFilter) {
                res = ((CustomSearchPoiFilter) searchResult.object).getName();
            }
            return res;
        case POI:
            Amenity amenity = (Amenity) searchResult.object;
            PoiCategory pc = amenity.getType();
            PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType());
            String typeStr = amenity.getSubType();
            if (pt != null) {
                typeStr = pt.getTranslation();
            } else if (typeStr != null) {
                typeStr = Algorithms.capitalizeFirstLetterAndLowercase(typeStr.replace('_', ' '));
            }
            return typeStr;
        case LOCATION:
            LatLon latLon = searchResult.location;
            if (latLon != null && searchResult.localeRelatedObjectName == null) {
                String locationCountry = app.getRegions().getCountryName(latLon);
                searchResult.localeRelatedObjectName = locationCountry == null ? "" : locationCountry;
            }
            return searchResult.localeRelatedObjectName;
        case FAVORITE:
            FavouritePoint fav = (FavouritePoint) searchResult.object;
            return fav.getCategory().length() == 0 ? app.getString(R.string.shared_string_favorites) : fav.getCategory();
        case FAVORITE_GROUP:
            return app.getString(R.string.shared_string_my_favorites);
        case REGION:
            BinaryMapIndexReader binaryMapIndexReader = (BinaryMapIndexReader) searchResult.object;
            System.out.println(binaryMapIndexReader.getFile().getAbsolutePath() + " " + binaryMapIndexReader.getCountryName());
            break;
        case RECENT_OBJ:
            HistoryEntry entry = (HistoryEntry) searchResult.object;
            boolean hasTypeInDescription = !Algorithms.isEmpty(entry.getName().getTypeName());
            if (hasTypeInDescription) {
                return entry.getName().getTypeName();
            } else {
                return "";
            }
        case WPT:
            StringBuilder sb = new StringBuilder();
            GPXFile gpx = (GPXFile) searchResult.relatedObject;
            if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
                sb.append(searchResult.localeRelatedObjectName);
            }
            if (gpx != null && !Algorithms.isEmpty(gpx.path)) {
                if (sb.length() > 0) {
                    sb.append(", ");
                }
                sb.append(new File(gpx.path).getName());
            }
            return sb.toString();
        case UNKNOWN_NAME_FILTER:
            break;
    }
    return searchResult.objectType.name();
}
Also used : Amenity(net.osmand.data.Amenity) PoiFilter(net.osmand.osm.PoiFilter) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter) FavouritePoint(net.osmand.data.FavouritePoint) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) City(net.osmand.data.City) AbstractPoiType(net.osmand.osm.AbstractPoiType) FavouritePoint(net.osmand.data.FavouritePoint) LatLon(net.osmand.data.LatLon) PoiCategory(net.osmand.osm.PoiCategory) Street(net.osmand.data.Street) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File)

Example 3 with PoiFilter

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

the class PoiFiltersHelper method getTopDefinedPoiFilters.

public List<PoiUIFilter> getTopDefinedPoiFilters() {
    if (cacheTopStandardFilters == null) {
        List<PoiUIFilter> top = new ArrayList<PoiUIFilter>();
        // user defined
        top.addAll(getUserDefinedPoiFilters());
        if (getLocalWikiPOIFilter() != null) {
            top.add(getLocalWikiPOIFilter());
        }
        // default
        MapPoiTypes poiTypes = application.getPoiTypes();
        for (PoiFilter t : poiTypes.getTopVisibleFilters()) {
            PoiUIFilter f = new PoiUIFilter(t, application, "");
            top.add(f);
        }
        Collections.sort(top);
        cacheTopStandardFilters = top;
    }
    List<PoiUIFilter> result = new ArrayList<PoiUIFilter>();
    result.addAll(cacheTopStandardFilters);
    result.add(getShowAllPOIFilter());
    return result;
}
Also used : PoiFilter(net.osmand.osm.PoiFilter) ArrayList(java.util.ArrayList) MapPoiTypes(net.osmand.osm.MapPoiTypes)

Example 4 with PoiFilter

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

the class PoiUIFilter method fillPoiAdditionals.

private void fillPoiAdditionals(AbstractPoiType pt, boolean allFromCategory) {
    for (PoiType add : pt.getPoiAdditionals()) {
        poiAdditionals.put(add.getKeyName().replace('_', ':').replace(' ', ':'), add);
        poiAdditionals.put(add.getTranslation().replace(' ', ':').toLowerCase(), add);
    }
    if (pt instanceof PoiCategory && allFromCategory) {
        for (PoiFilter pf : ((PoiCategory) pt).getPoiFilters()) {
            fillPoiAdditionals(pf, true);
        }
        for (PoiType ps : ((PoiCategory) pt).getPoiTypes()) {
            fillPoiAdditionals(ps, false);
        }
    } else if (pt instanceof PoiFilter && !(pt instanceof PoiCategory)) {
        for (PoiType ps : ((PoiFilter) pt).getPoiTypes()) {
            fillPoiAdditionals(ps, false);
        }
    }
}
Also used : PoiFilter(net.osmand.osm.PoiFilter) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter) PoiCategory(net.osmand.osm.PoiCategory) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType)

Example 5 with PoiFilter

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

the class QuickSearchListItem method getTypeName.

public static String getTypeName(SampleApplication app, SearchResult searchResult) {
    switch(searchResult.objectType) {
        case CITY:
            City city = (City) searchResult.object;
            return getCityTypeStr(app, city.getType());
        case POSTCODE:
            return app.getString("postcode");
        case VILLAGE:
            city = (City) searchResult.object;
            if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
                if (searchResult.distRelatedObjectName > 0) {
                    return getCityTypeStr(app, city.getType()) + " • " + SampleFormatter.getFormattedDistance((float) searchResult.distRelatedObjectName, app) + " " + app.getString("shared_string_from") + " " + searchResult.localeRelatedObjectName;
                } else {
                    return getCityTypeStr(app, city.getType()) + ", " + searchResult.localeRelatedObjectName;
                }
            } else {
                return getCityTypeStr(app, city.getType());
            }
        case STREET:
            StringBuilder streetBuilder = new StringBuilder();
            if (searchResult.localeName.endsWith(")")) {
                int i = searchResult.localeName.indexOf('(');
                if (i > 0) {
                    streetBuilder.append(searchResult.localeName.substring(i + 1, searchResult.localeName.length() - 1));
                }
            }
            if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
                if (streetBuilder.length() > 0) {
                    streetBuilder.append(", ");
                }
                streetBuilder.append(searchResult.localeRelatedObjectName);
            }
            return streetBuilder.toString();
        case HOUSE:
            if (searchResult.relatedObject != null) {
                Street relatedStreet = (Street) searchResult.relatedObject;
                if (relatedStreet.getCity() != null) {
                    return searchResult.localeRelatedObjectName + ", " + relatedStreet.getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
                } else {
                    return searchResult.localeRelatedObjectName;
                }
            }
            return "";
        case STREET_INTERSECTION:
            Street street = (Street) searchResult.object;
            if (street.getCity() != null) {
                return street.getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
            }
            return "";
        case POI_TYPE:
            String res = "";
            if (searchResult.object instanceof AbstractPoiType) {
                AbstractPoiType abstractPoiType = (AbstractPoiType) searchResult.object;
                if (abstractPoiType instanceof PoiCategory) {
                    res = "";
                } else if (abstractPoiType instanceof PoiFilter) {
                    PoiFilter poiFilter = (PoiFilter) abstractPoiType;
                    res = poiFilter.getPoiCategory() != null ? poiFilter.getPoiCategory().getTranslation() : "";
                } else if (abstractPoiType instanceof PoiType) {
                    PoiType poiType = (PoiType) abstractPoiType;
                    res = poiType.getParentType() != null ? poiType.getParentType().getTranslation() : null;
                    if (res == null) {
                        res = poiType.getCategory() != null ? poiType.getCategory().getTranslation() : null;
                    }
                    if (res == null) {
                        res = "";
                    }
                } else {
                    res = "";
                }
            } else if (searchResult.object instanceof CustomSearchPoiFilter) {
                res = ((CustomSearchPoiFilter) searchResult.object).getName();
            }
            return res;
        case POI:
            Amenity amenity = (Amenity) searchResult.object;
            PoiCategory pc = amenity.getType();
            PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType());
            String typeStr = amenity.getSubType();
            if (pt != null) {
                typeStr = pt.getTranslation();
            } else if (typeStr != null) {
                typeStr = Algorithms.capitalizeFirstLetterAndLowercase(typeStr.replace('_', ' '));
            }
            return typeStr;
        case LOCATION:
            LatLon latLon = searchResult.location;
            if (searchResult.localeRelatedObjectName == null) {
                String locationCountry = app.getRegions().getCountryName(latLon);
                searchResult.localeRelatedObjectName = locationCountry == null ? "" : locationCountry;
            }
            return searchResult.localeRelatedObjectName;
        case REGION:
            BinaryMapIndexReader binaryMapIndexReader = (BinaryMapIndexReader) searchResult.object;
            System.out.println(binaryMapIndexReader.getFile().getAbsolutePath() + " " + binaryMapIndexReader.getCountryName());
            break;
        case UNKNOWN_NAME_FILTER:
            break;
    }
    return searchResult.objectType.name();
}
Also used : Amenity(net.osmand.data.Amenity) PoiFilter(net.osmand.osm.PoiFilter) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) City(net.osmand.data.City) AbstractPoiType(net.osmand.osm.AbstractPoiType) LatLon(net.osmand.data.LatLon) PoiCategory(net.osmand.osm.PoiCategory) Street(net.osmand.data.Street) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter)

Aggregations

PoiFilter (net.osmand.osm.PoiFilter)6 PoiType (net.osmand.osm.PoiType)5 AbstractPoiType (net.osmand.osm.AbstractPoiType)4 PoiCategory (net.osmand.osm.PoiCategory)4 CustomSearchPoiFilter (net.osmand.search.core.CustomSearchPoiFilter)3 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)2 Amenity (net.osmand.data.Amenity)2 City (net.osmand.data.City)2 LatLon (net.osmand.data.LatLon)2 Street (net.osmand.data.Street)2 MapPoiTypes (net.osmand.osm.MapPoiTypes)2 NonNull (android.support.annotation.NonNull)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 FavouritePoint (net.osmand.data.FavouritePoint)1 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)1 HistoryEntry (net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry)1