Search in sources :

Example 36 with Amenity

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

the class BinaryMapPoiReaderAdapter method readPoiPoint.

private Amenity readPoiPoint(int left31, int right31, int top31, int bottom31, int px, int py, int zoom, SearchRequest<Amenity> req, PoiRegion region, boolean checkBounds) throws IOException {
    Amenity am = null;
    int x = 0;
    int y = 0;
    StringBuilder retValue = new StringBuilder();
    PoiCategory amenityType = null;
    LinkedList<String> textTags = null;
    while (true) {
        int t = codedIS.readTag();
        int tag = WireFormat.getTagFieldNumber(t);
        if (amenityType == null && (tag > OsmandOdb.OsmAndPoiBoxDataAtom.CATEGORIES_FIELD_NUMBER || tag == 0)) {
            codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
            return null;
        }
        switch(tag) {
            case 0:
                req.numberOfAcceptedObjects++;
                if (req.radius > 0) {
                    LatLon loc = am.getLocation();
                    List<Location> locs = req.tiles.get(req.getTileHashOnPath(loc.getLatitude(), loc.getLongitude()));
                    if (locs == null) {
                        return null;
                    }
                    AmenityRoutePoint arp = dist(am.getLocation(), locs, req.radius);
                    if (arp == null) {
                        return null;
                    } else {
                        am.setRoutePoint(arp);
                    }
                }
                return am;
            case OsmandOdb.OsmAndPoiBoxDataAtom.DX_FIELD_NUMBER:
                x = (codedIS.readSInt32() + (px << (24 - zoom))) << 7;
                break;
            case OsmandOdb.OsmAndPoiBoxDataAtom.DY_FIELD_NUMBER:
                y = (codedIS.readSInt32() + (py << (24 - zoom))) << 7;
                req.numberOfVisitedObjects++;
                if (checkBounds) {
                    if (left31 > x || right31 < x || top31 > y || bottom31 < y) {
                        codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
                        return null;
                    }
                }
                am = new Amenity();
                am.setLocation(MapUtils.get31LatitudeY(y), MapUtils.get31LongitudeX(x));
                break;
            case OsmandOdb.OsmAndPoiBoxDataAtom.SUBCATEGORIES_FIELD_NUMBER:
                int subtypev = codedIS.readUInt32();
                retValue.setLength(0);
                PoiSubType st = region.getSubtypeFromId(subtypev, retValue);
                if (st != null) {
                    am.setAdditionalInfo(st.name, retValue.toString());
                }
                break;
            case OsmandOdb.OsmAndPoiBoxDataAtom.TEXTCATEGORIES_FIELD_NUMBER:
                int texttypev = codedIS.readUInt32();
                retValue.setLength(0);
                PoiSubType textt = region.getSubtypeFromId(texttypev, retValue);
                if (textt != null && textt.text) {
                    if (textTags == null) {
                        textTags = new LinkedList<String>();
                    }
                    textTags.add(textt.name);
                }
                break;
            case OsmandOdb.OsmAndPoiBoxDataAtom.TEXTVALUES_FIELD_NUMBER:
                String str = codedIS.readString();
                if (textTags != null && !textTags.isEmpty()) {
                    am.setAdditionalInfo(textTags.poll(), str);
                }
                break;
            case OsmandOdb.OsmAndPoiBoxDataAtom.CATEGORIES_FIELD_NUMBER:
                int cat = codedIS.readUInt32();
                int subcatId = cat >> SHIFT_BITS_CATEGORY;
                int catId = cat & CATEGORY_MASK;
                PoiCategory type = poiTypes.getOtherPoiCategory();
                String subtype = "";
                if (catId < region.categoriesType.size()) {
                    type = region.categoriesType.get(catId);
                    List<String> subcats = region.subcategories.get(catId);
                    if (subcatId < subcats.size()) {
                        subtype = subcats.get(subcatId);
                    }
                }
                subtype = poiTypes.replaceDeprecatedSubtype(type, subtype);
                if (req.poiTypeFilter == null || req.poiTypeFilter.accept(type, subtype)) {
                    if (amenityType == null) {
                        amenityType = type;
                        am.setSubType(subtype);
                        am.setType(amenityType);
                    } else {
                        am.setSubType(am.getSubType() + ";" + subtype);
                    }
                }
                break;
            case OsmandOdb.OsmAndPoiBoxDataAtom.ID_FIELD_NUMBER:
                am.setId(codedIS.readUInt64());
                break;
            case OsmandOdb.OsmAndPoiBoxDataAtom.NAME_FIELD_NUMBER:
                am.setName(codedIS.readString());
                break;
            case OsmandOdb.OsmAndPoiBoxDataAtom.NAMEEN_FIELD_NUMBER:
                am.setEnName(codedIS.readString());
                break;
            case OsmandOdb.OsmAndPoiBoxDataAtom.OPENINGHOURS_FIELD_NUMBER:
                am.setOpeningHours(codedIS.readString());
                break;
            case OsmandOdb.OsmAndPoiBoxDataAtom.SITE_FIELD_NUMBER:
                am.setSite(codedIS.readString());
                break;
            case OsmandOdb.OsmAndPoiBoxDataAtom.PHONE_FIELD_NUMBER:
                am.setPhone(codedIS.readString());
                break;
            case OsmandOdb.OsmAndPoiBoxDataAtom.NOTE_FIELD_NUMBER:
                am.setDescription(codedIS.readString());
                break;
            default:
                skipUnknownField(t);
                break;
        }
    }
}
Also used : Amenity(net.osmand.data.Amenity) LatLon(net.osmand.data.LatLon) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint) PoiCategory(net.osmand.osm.PoiCategory) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint) Location(net.osmand.Location)

Example 37 with Amenity

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

the class FavouritePointMenuBuilder method findAmenity.

private Amenity findAmenity(String nameStringEn, double lat, double lon) {
    QuadRect rect = MapUtils.calculateLatLonBbox(lat, lon, 15);
    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);
    for (Amenity amenity : amenities) {
        String stringEn = amenity.toStringEn();
        if (stringEn.equals(nameStringEn)) {
            return amenity;
        }
    }
    return null;
}
Also used : Amenity(net.osmand.data.Amenity) PoiCategory(net.osmand.osm.PoiCategory) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) QuadRect(net.osmand.data.QuadRect)

Example 38 with Amenity

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

the class WaypointHelper method calculatePoi.

protected void calculatePoi(RouteCalculationResult route, List<LocationPointWrapper> locationPoints, boolean announcePOI) {
    if (app.getPoiFilters().isShowingAnyPoi()) {
        final List<Location> locs = route.getImmutableAllLocations();
        List<Amenity> amenities = new ArrayList<>();
        for (PoiUIFilter pf : app.getPoiFilters().getSelectedPoiFilters()) {
            amenities.addAll(pf.searchAmenitiesOnThePath(locs, poiSearchDeviationRadius));
        }
        for (Amenity a : amenities) {
            AmenityRoutePoint rp = a.getRoutePoint();
            int i = locs.indexOf(rp.pointA);
            if (i >= 0) {
                LocationPointWrapper lwp = new LocationPointWrapper(route, POI, new AmenityLocationPoint(a), (float) rp.deviateDistance, i);
                lwp.deviationDirectionRight = rp.deviationDirectionRight;
                lwp.setAnnounce(announcePOI);
                locationPoints.add(lwp);
            }
        }
    }
}
Also used : Amenity(net.osmand.data.Amenity) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) Location(net.osmand.Location) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 39 with Amenity

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

the class SearchPOIActivity method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
    final Amenity amenity = ((AmenityAdapter) getListAdapter()).getItem(position);
    final OsmandSettings settings = app.getSettings();
    String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(amenity, app.getSettings().MAP_PREFERRED_LOCALE.get(), app.getSettings().MAP_TRANSLITERATE_NAMES.get());
    PointDescription name = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat);
    int z = Math.max(16, settings.getLastKnownMapZoom());
    LatLon location = amenity.getLocation();
    settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), z, name, true, // $NON-NLS-1$
    amenity);
    MapActivity.launchMapActivityMoveToTop(this);
}
Also used : Amenity(net.osmand.data.Amenity) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 40 with Amenity

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

the class EntityParser method parseAmenities.

public static List<Amenity> parseAmenities(MapPoiTypes poiTypes, Entity entity, Map<String, String> tags, List<Amenity> amenitiesList) {
    amenitiesList.clear();
    // it could be collection of amenities
    boolean relation = entity instanceof Relation;
    boolean purerelation = relation && !"multipolygon".equals(tags.get("type"));
    Collection<Map<String, String>> it = MapRenderingTypes.splitTagsIntoDifferentObjects(tags);
    for (Map<String, String> ts : it) {
        for (Map.Entry<String, String> e : ts.entrySet()) {
            Amenity am = poiTypes.parseAmenity(e.getKey(), e.getValue(), purerelation, ts);
            if (am != null) {
                parseMapObject(am, entity, ts);
                String wbs = getWebSiteURL(ts, false);
                if (wbs != null) {
                    am.setAdditionalInfo("website", wbs);
                }
                wbs = getWebSiteURL(ts, true);
                if (wbs != null) {
                    am.setAdditionalInfo("wikipedia", wbs);
                }
                if (checkAmenitiesToAdd(am, amenitiesList) && !"no".equals(am.getSubType())) {
                    amenitiesList.add(am);
                }
            }
        }
    }
    return amenitiesList;
}
Also used : Amenity(net.osmand.data.Amenity) Map(java.util.Map)

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