Search in sources :

Example 51 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class MapContextMenuFragment method updateCompassVisibility.

private void updateCompassVisibility() {
    View compassView = view.findViewById(R.id.compass_layout);
    Location ll = getMyApplication().getLocationProvider().getLastKnownLocation();
    boolean gpsFixed = ll != null && System.currentTimeMillis() - ll.getTime() < 1000 * 60 * 60 * 20;
    if (gpsFixed && menu.displayDistanceDirection() && menu.getCurrentMenuState() != MenuState.FULL_SCREEN) {
        updateDistanceDirection();
        compassView.setVisibility(View.VISIBLE);
    } else {
        if (!menu.displayDistanceDirection()) {
            compassView.setVisibility(View.GONE);
        } else {
            compassView.setVisibility(View.INVISIBLE);
        }
    }
}
Also used : ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Location(net.osmand.Location)

Example 52 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class QuickSearchListAdapter method updateCompassVisibility.

private void updateCompassVisibility(View view, QuickSearchListItem listItem) {
    View compassView = view.findViewById(R.id.compass_layout);
    Location ll = app.getLocationProvider().getLastKnownLocation();
    boolean showCompass = location != null && listItem.getSearchResult().location != null;
    boolean gpsFixed = ll != null && System.currentTimeMillis() - ll.getTime() < 1000 * 60 * 60 * 20;
    if ((gpsFixed || useMapCenter) && showCompass) {
        updateDistanceDirection(view, listItem);
        compassView.setVisibility(View.VISIBLE);
    } else {
        if (!showCompass) {
            compassView.setVisibility(View.GONE);
        } else {
            compassView.setVisibility(View.INVISIBLE);
        }
    }
}
Also used : ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Location(net.osmand.Location)

Example 53 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class BinaryMapIndexReader method readGPX.

private static List<Location> readGPX(File f) {
    List<Location> res = new ArrayList<Location>();
    try {
        StringBuilder content = new StringBuilder();
        BufferedReader reader = new BufferedReader(getUTF8Reader(new FileInputStream(f)));
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dom = factory.newDocumentBuilder();
        // {
        // String s = null;
        // boolean fist = true;
        // while ((s = reader.readLine()) != null) {
        // if (fist) {
        // fist = false;
        // }
        // content.append(s).append("\n");
        // }
        // }
        // Document doc = dom.parse(new InputSource(new StringReader(content.toString())));
        Document doc = dom.parse(new InputSource(reader));
        NodeList list = doc.getElementsByTagName("trkpt");
        Way w = new Way(-1);
        for (int i = 0; i < list.getLength(); i++) {
            Element item = (Element) list.item(i);
            try {
                double lon = Double.parseDouble(item.getAttribute("lon"));
                double lat = Double.parseDouble(item.getAttribute("lat"));
                final Location o = new Location("");
                o.setLatitude(lat);
                o.setLongitude(lon);
                res.add(o);
            } catch (NumberFormatException e) {
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    } catch (SAXException e) {
        throw new RuntimeException(e);
    }
    return res;
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) Way(net.osmand.osm.edit.Way) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) BufferedReader(java.io.BufferedReader) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Location(net.osmand.Location)

Example 54 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class BinaryMapIndexReader method buildSearchPoiRequest.

public static SearchRequest<Amenity> buildSearchPoiRequest(List<Location> route, double radius, SearchPoiTypeFilter poiTypeFilter, ResultMatcher<Amenity> resultMatcher) {
    SearchRequest<Amenity> request = new SearchRequest<Amenity>();
    float coeff = (float) (radius / MapUtils.getTileDistanceWidth(SearchRequest.ZOOM_TO_SEARCH_POI));
    TLongObjectHashMap<List<Location>> zooms = new TLongObjectHashMap<List<Location>>();
    for (int i = 1; i < route.size(); i++) {
        Location cr = route.get(i);
        Location pr = route.get(i - 1);
        double tx = MapUtils.getTileNumberX(SearchRequest.ZOOM_TO_SEARCH_POI, cr.getLongitude());
        double ty = MapUtils.getTileNumberY(SearchRequest.ZOOM_TO_SEARCH_POI, cr.getLatitude());
        double px = MapUtils.getTileNumberX(SearchRequest.ZOOM_TO_SEARCH_POI, pr.getLongitude());
        double py = MapUtils.getTileNumberY(SearchRequest.ZOOM_TO_SEARCH_POI, pr.getLatitude());
        double topLeftX = Math.min(tx, px) - coeff;
        double topLeftY = Math.min(ty, py) - coeff;
        double bottomRightX = Math.max(tx, px) + coeff;
        double bottomRightY = Math.max(ty, py) + coeff;
        for (int x = (int) topLeftX; x <= bottomRightX; x++) {
            for (int y = (int) topLeftY; y <= bottomRightY; y++) {
                long hash = (((long) x) << SearchRequest.ZOOM_TO_SEARCH_POI) + y;
                if (!zooms.containsKey(hash)) {
                    zooms.put(hash, new LinkedList<Location>());
                }
                List<Location> ll = zooms.get(hash);
                ll.add(pr);
                ll.add(cr);
            }
        }
    }
    int sleft = Integer.MAX_VALUE, sright = 0, stop = Integer.MAX_VALUE, sbottom = 0;
    for (long vl : zooms.keys()) {
        long x = (vl >> SearchRequest.ZOOM_TO_SEARCH_POI) << (31 - SearchRequest.ZOOM_TO_SEARCH_POI);
        long y = (vl & ((1 << SearchRequest.ZOOM_TO_SEARCH_POI) - 1)) << (31 - SearchRequest.ZOOM_TO_SEARCH_POI);
        sleft = (int) Math.min(x, sleft);
        stop = (int) Math.min(y, stop);
        sbottom = (int) Math.max(y, sbottom);
        sright = (int) Math.max(x, sright);
    }
    request.radius = radius;
    request.left = sleft;
    request.zoom = -1;
    request.right = sright;
    request.top = stop;
    request.bottom = sbottom;
    request.tiles = zooms;
    request.poiTypeFilter = poiTypeFilter;
    request.resultMatcher = resultMatcher;
    return request;
}
Also used : Amenity(net.osmand.data.Amenity) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) TIntArrayList(gnu.trove.list.array.TIntArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NodeList(org.w3c.dom.NodeList) Location(net.osmand.Location)

Example 55 with Location

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

Aggregations

Location (net.osmand.Location)105 LatLon (net.osmand.data.LatLon)37 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)29 ArrayList (java.util.ArrayList)21 LocationPoint (net.osmand.data.LocationPoint)21 View (android.view.View)13 OsmandApplication (net.osmand.plus.OsmandApplication)12 Paint (android.graphics.Paint)11 TextView (android.widget.TextView)11 ImageView (android.widget.ImageView)10 RouteDataObject (net.osmand.binary.RouteDataObject)9 WptPt (net.osmand.plus.GPXUtilities.WptPt)9 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)8 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)7 PointDescription (net.osmand.data.PointDescription)6 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)6 TIntArrayList (gnu.trove.list.array.TIntArrayList)5 IOException (java.io.IOException)5 QuadPoint (net.osmand.data.QuadPoint)5 MapActivity (net.osmand.plus.activities.MapActivity)5