Search in sources :

Example 51 with Amenity

use of net.osmand.data.Amenity 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)

Example 52 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class QuickSearchListFragment method showResult.

public void showResult(SearchResult searchResult) {
    if (searchResult.location != null) {
        OsmandApplication app = getMyApplication();
        String lang = searchResult.requiredSearchPhrase.getSettings().getLang();
        boolean transliterate = searchResult.requiredSearchPhrase.getSettings().isTransliterate();
        PointDescription pointDescription = null;
        Object object = searchResult.object;
        switch(searchResult.objectType) {
            case POI:
                Amenity a = (Amenity) object;
                String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(a, lang, transliterate);
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat);
                pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(app, a));
                break;
            case RECENT_OBJ:
                HistoryEntry entry = (HistoryEntry) object;
                pointDescription = entry.getName();
                if (pointDescription.isPoi()) {
                    Amenity amenity = app.getSearchUICore().findAmenity(entry.getName().getName(), entry.getLat(), entry.getLon(), lang, transliterate);
                    if (amenity != null) {
                        object = amenity;
                        pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI, OsmAndFormatter.getPoiStringWithoutType(amenity, lang, transliterate));
                        pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(app, amenity));
                    }
                } else if (pointDescription.isFavorite()) {
                    LatLon entryLatLon = new LatLon(entry.getLat(), entry.getLon());
                    List<FavouritePoint> favs = app.getFavorites().getFavouritePoints();
                    for (FavouritePoint f : favs) {
                        if (entryLatLon.equals(new LatLon(f.getLatitude(), f.getLongitude())) && pointDescription.getName().equals(f.getName())) {
                            object = f;
                            pointDescription = f.getPointDescription();
                            break;
                        }
                    }
                }
                break;
            case FAVORITE:
                FavouritePoint fav = (FavouritePoint) object;
                pointDescription = fav.getPointDescription();
                break;
            case VILLAGE:
            case CITY:
                String cityName = searchResult.localeName;
                String typeNameCity = QuickSearchListItem.getTypeName(app, searchResult);
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameCity, cityName);
                pointDescription.setIconName("ic_action_building_number");
                break;
            case STREET:
                String streetName = searchResult.localeName;
                String typeNameStreet = QuickSearchListItem.getTypeName(app, searchResult);
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameStreet, streetName);
                pointDescription.setIconName("ic_action_street_name");
                break;
            case HOUSE:
                String typeNameHouse = null;
                String name = searchResult.localeName;
                if (searchResult.relatedObject instanceof City) {
                    name = ((City) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true) + " " + name;
                } else if (searchResult.relatedObject instanceof Street) {
                    String s = ((Street) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
                    typeNameHouse = ((Street) searchResult.relatedObject).getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
                    name = s + " " + name;
                } else if (searchResult.localeRelatedObjectName != null) {
                    name = searchResult.localeRelatedObjectName + " " + name;
                }
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameHouse, name);
                pointDescription.setIconName("ic_action_building");
                break;
            case LOCATION:
                pointDescription = new PointDescription(searchResult.location.getLatitude(), searchResult.location.getLongitude());
                pointDescription.setIconName("ic_action_world_globe");
                break;
            case STREET_INTERSECTION:
                String typeNameIntersection = QuickSearchListItem.getTypeName(app, searchResult);
                if (Algorithms.isEmpty(typeNameIntersection)) {
                    typeNameIntersection = null;
                }
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameIntersection, QuickSearchListItem.getName(app, searchResult));
                pointDescription.setIconName("ic_action_intersection");
                break;
            case WPT:
                GPXUtilities.WptPt wpt = (GPXUtilities.WptPt) object;
                pointDescription = wpt.getPointDescription(getMyApplication());
                break;
        }
        dialogFragment.hideToolbar();
        dialogFragment.hide();
        showOnMap(getMapActivity(), dialogFragment, searchResult.location.getLatitude(), searchResult.location.getLongitude(), searchResult.preferredZoom, pointDescription, object);
    }
}
Also used : Amenity(net.osmand.data.Amenity) OsmandApplication(net.osmand.plus.OsmandApplication) FavouritePoint(net.osmand.data.FavouritePoint) City(net.osmand.data.City) GPXUtilities(net.osmand.plus.GPXUtilities) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) Street(net.osmand.data.Street) ArrayList(java.util.ArrayList) List(java.util.List)

Example 53 with Amenity

use of net.osmand.data.Amenity in project Osmand by osmandapp.

the class ResourceManager method searchAmenitiesOnThePath.

public List<Amenity> searchAmenitiesOnThePath(List<Location> locations, double radius, SearchPoiTypeFilter filter, ResultMatcher<Amenity> matcher) {
    searchAmenitiesInProgress = true;
    final List<Amenity> amenities = new ArrayList<Amenity>();
    try {
        if (locations != null && locations.size() > 0) {
            List<AmenityIndexRepository> repos = new ArrayList<AmenityIndexRepository>();
            double topLatitude = locations.get(0).getLatitude();
            double bottomLatitude = locations.get(0).getLatitude();
            double leftLongitude = locations.get(0).getLongitude();
            double rightLongitude = locations.get(0).getLongitude();
            for (Location l : locations) {
                topLatitude = Math.max(topLatitude, l.getLatitude());
                bottomLatitude = Math.min(bottomLatitude, l.getLatitude());
                leftLongitude = Math.min(leftLongitude, l.getLongitude());
                rightLongitude = Math.max(rightLongitude, l.getLongitude());
            }
            if (!filter.isEmpty()) {
                for (AmenityIndexRepository index : amenityRepositories.values()) {
                    if (index.checkContainsInt(MapUtils.get31TileNumberY(topLatitude), MapUtils.get31TileNumberX(leftLongitude), MapUtils.get31TileNumberY(bottomLatitude), MapUtils.get31TileNumberX(rightLongitude))) {
                        repos.add(index);
                    }
                }
                if (!repos.isEmpty()) {
                    for (AmenityIndexRepository r : repos) {
                        List<Amenity> res = r.searchAmenitiesOnThePath(locations, radius, filter, matcher);
                        if (res != null) {
                            amenities.addAll(res);
                        }
                    }
                }
            }
        }
    } finally {
        searchAmenitiesInProgress = false;
    }
    return amenities;
}
Also used : Amenity(net.osmand.data.Amenity) ArrayList(java.util.ArrayList) Location(net.osmand.Location)

Aggregations

Amenity (net.osmand.data.Amenity)53 LatLon (net.osmand.data.LatLon)17 ArrayList (java.util.ArrayList)11 PoiCategory (net.osmand.osm.PoiCategory)9 AbstractPoiType (net.osmand.osm.AbstractPoiType)8 PoiType (net.osmand.osm.PoiType)8 PointDescription (net.osmand.data.PointDescription)7 Paint (android.graphics.Paint)6 View (android.view.View)6 ImageView (android.widget.ImageView)6 HashMap (java.util.HashMap)6 FavouritePoint (net.osmand.data.FavouritePoint)6 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)5 File (java.io.File)5 Map (java.util.Map)5 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)5 QuadRect (net.osmand.data.QuadRect)5 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 LinearLayout (android.widget.LinearLayout)4