Search in sources :

Example 1 with AmenityRoutePoint

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

the class BinaryMapPoiReaderAdapter method dist.

private AmenityRoutePoint dist(LatLon l, List<Location> locations, double radius) {
    float dist = (float) (radius + 0.1);
    AmenityRoutePoint arp = null;
    // Special iterations because points stored by pairs!
    for (int i = 1; i < locations.size(); i += 2) {
        float d = (float) MapUtils.getOrthogonalDistance(l.getLatitude(), l.getLongitude(), locations.get(i - 1).getLatitude(), locations.get(i - 1).getLongitude(), locations.get(i).getLatitude(), locations.get(i).getLongitude());
        if (d < dist) {
            arp = new Amenity.AmenityRoutePoint();
            dist = d;
            arp.deviateDistance = dist;
            arp.pointA = locations.get(i - 1);
            arp.pointB = locations.get(i);
        }
    }
    if (arp != null && arp.deviateDistance != 0 && arp.pointA != null && arp.pointB != null) {
        arp.deviationDirectionRight = MapUtils.rightSide(l.getLatitude(), l.getLongitude(), arp.pointA.getLatitude(), arp.pointA.getLongitude(), arp.pointB.getLatitude(), arp.pointB.getLongitude());
    }
    return arp;
}
Also used : Amenity(net.osmand.data.Amenity) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint)

Example 2 with AmenityRoutePoint

use of net.osmand.data.Amenity.AmenityRoutePoint 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 3 with AmenityRoutePoint

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

Aggregations

Amenity (net.osmand.data.Amenity)3 AmenityRoutePoint (net.osmand.data.Amenity.AmenityRoutePoint)3 Location (net.osmand.Location)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 ArrayList (java.util.ArrayList)1 LatLon (net.osmand.data.LatLon)1 LocationPoint (net.osmand.data.LocationPoint)1 PoiCategory (net.osmand.osm.PoiCategory)1 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)1 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)1