Search in sources :

Example 16 with Location

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

the class RouteProvider method findStartAndEndLocationsFromRoute.

private ArrayList<Location> findStartAndEndLocationsFromRoute(List<Location> route, Location startLoc, LatLon endLoc, int[] startI, int[] endI) {
    float minDist = Integer.MAX_VALUE;
    int start = 0;
    int end = route.size();
    if (startLoc != null) {
        for (int i = 0; i < route.size(); i++) {
            float d = route.get(i).distanceTo(startLoc);
            if (d < minDist) {
                start = i;
                minDist = d;
            }
        }
    } else {
        startLoc = route.get(0);
    }
    // $NON-NLS-1$
    Location l = new Location("temp");
    l.setLatitude(endLoc.getLatitude());
    l.setLongitude(endLoc.getLongitude());
    minDist = Integer.MAX_VALUE;
    // get in reverse order taking into account ways with cycle
    for (int i = route.size() - 1; i >= start; i--) {
        float d = route.get(i).distanceTo(l);
        if (d < minDist) {
            end = i + 1;
            // slightly modify to allow last point to be added
            minDist = d - 40;
        }
    }
    ArrayList<Location> sublist = new ArrayList<Location>(route.subList(start, end));
    if (startI != null) {
        startI[0] = start;
    }
    if (endI != null) {
        endI[0] = end;
    }
    return sublist;
}
Also used : ArrayList(java.util.ArrayList) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) Location(net.osmand.Location)

Example 17 with Location

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

the class ImpassableRoadsLayer method onPrepareBufferImage.

@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
    if (tileBox.getZoom() >= startZoom) {
        for (long id : getImpassableRoadLocations().keySet()) {
            if (contextMenuLayer.getMoveableObject() instanceof RouteDataObject) {
                RouteDataObject object = (RouteDataObject) contextMenuLayer.getMoveableObject();
                if (object.id == id) {
                    continue;
                }
            }
            Location location = getImpassableRoadLocations().get(id);
            final double latitude = location.getLatitude();
            final double longitude = location.getLongitude();
            if (tileBox.containsLatLon(latitude, longitude)) {
                drawPoint(canvas, tileBox, latitude, longitude);
            }
        }
        for (StoredRoadDataObject storedRoadDataObject : storedRoadDataObjects) {
            final LatLon latLon = storedRoadDataObject.getLatLon();
            if (tileBox.containsLatLon(latLon)) {
                drawPoint(canvas, tileBox, latLon.getLatitude(), latLon.getLongitude());
            }
        }
    }
}
Also used : LatLon(net.osmand.data.LatLon) RouteDataObject(net.osmand.binary.RouteDataObject) Location(net.osmand.Location)

Example 18 with Location

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

the class BinaryMapIndexReader method testSearchOnthePath.

private static void testSearchOnthePath(BinaryMapIndexReader reader) throws IOException {
    float radius = 1000;
    final MapPoiTypes poiTypes = MapPoiTypes.getDefault();
    long now = System.currentTimeMillis();
    println("Searching poi on the path...");
    final List<Location> locations = readGPX(new File("/Users/victorshcherb/osmand/maps/2015-03-07_19-07_Sat.gpx"));
    SearchRequest<Amenity> req = buildSearchPoiRequest(locations, radius, new SearchPoiTypeFilter() {

        @Override
        public boolean accept(PoiCategory type, String subcategory) {
            if (type == poiTypes.getPoiCategoryByName("shop") && subcategory.contains("super")) {
                return true;
            }
            return false;
        }

        @Override
        public boolean isEmpty() {
            return false;
        }
    }, null);
    req.zoom = -1;
    List<Amenity> results = reader.searchPoi(req);
    int k = 0;
    println("Search done in " + (System.currentTimeMillis() - now) + " ms ");
    now = System.currentTimeMillis();
    for (Amenity a : results) {
        final float dds = dist(a.getLocation(), locations);
        if (dds <= radius) {
            println("+ " + a.getType() + " " + a.getSubType() + " Dist " + dds + " (=" + (float) a.getRoutePoint().deviateDistance + ") " + a.getName() + " " + a.getLocation());
            k++;
        } else {
            println(a.getType() + " " + a.getSubType() + " Dist " + dds + " " + a.getName() + " " + a.getLocation());
        }
    }
    println("Filtered in " + (System.currentTimeMillis() - now) + "ms " + k + " of " + results.size());
}
Also used : Amenity(net.osmand.data.Amenity) MapPoiTypes(net.osmand.osm.MapPoiTypes) PoiCategory(net.osmand.osm.PoiCategory) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Location(net.osmand.Location)

Example 19 with Location

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

the class MapActivityActions method setGPXRouteParams.

public void setGPXRouteParams(GPXFile result) {
    if (result == null) {
        mapActivity.getRoutingHelper().setGpxParams(null);
        settings.FOLLOW_THE_GPX_ROUTE.set(null);
    } else {
        GPXRouteParamsBuilder params = new GPXRouteParamsBuilder(result, mapActivity.getMyApplication().getSettings());
        if (result.hasRtePt() && !result.hasTrkPt()) {
            settings.GPX_CALCULATE_RTEPT.set(true);
        } else {
            settings.GPX_CALCULATE_RTEPT.set(false);
        }
        params.setCalculateOsmAndRouteParts(settings.GPX_ROUTE_CALC_OSMAND_PARTS.get());
        params.setUseIntermediatePointsRTE(settings.GPX_CALCULATE_RTEPT.get());
        params.setCalculateOsmAndRoute(settings.GPX_ROUTE_CALC.get());
        List<Location> ps = params.getPoints();
        mapActivity.getRoutingHelper().setGpxParams(params);
        settings.FOLLOW_THE_GPX_ROUTE.set(result.path);
        if (!ps.isEmpty()) {
            Location startLoc = ps.get(0);
            Location finishLoc = ps.get(ps.size() - 1);
            TargetPointsHelper tg = mapActivity.getMyApplication().getTargetPointsHelper();
            tg.navigateToPoint(new LatLon(finishLoc.getLatitude(), finishLoc.getLongitude()), false, -1);
            if (startLoc != finishLoc) {
                tg.setStartPoint(new LatLon(startLoc.getLatitude(), startLoc.getLongitude()), false, null);
            } else {
                tg.clearStartPoint(false);
            }
        }
    }
}
Also used : LatLon(net.osmand.data.LatLon) GPXRouteParamsBuilder(net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) Location(net.osmand.Location)

Example 20 with Location

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

the class MapActivity method newRouteIsCalculated.

@Override
public void newRouteIsCalculated(boolean newRoute, ValueHolder<Boolean> showToast) {
    RoutingHelper rh = app.getRoutingHelper();
    if (newRoute && rh.isRoutePlanningMode() && mapView != null) {
        Location lt = rh.getLastProjection();
        if (lt == null) {
            lt = app.getTargetPointsHelper().getPointToStartLocation();
        }
        if (lt != null) {
            double left = lt.getLongitude(), right = lt.getLongitude();
            double top = lt.getLatitude(), bottom = lt.getLatitude();
            List<Location> list = rh.getCurrentCalculatedRoute();
            for (Location l : list) {
                left = Math.min(left, l.getLongitude());
                right = Math.max(right, l.getLongitude());
                top = Math.max(top, l.getLatitude());
                bottom = Math.min(bottom, l.getLatitude());
            }
            List<TargetPoint> targetPoints = app.getTargetPointsHelper().getIntermediatePointsWithTarget();
            for (TargetPoint l : targetPoints) {
                left = Math.min(left, l.getLongitude());
                right = Math.max(right, l.getLongitude());
                top = Math.max(top, l.getLatitude());
                bottom = Math.min(bottom, l.getLatitude());
            }
            RotatedTileBox tb = mapView.getCurrentRotatedTileBox().copy();
            int tileBoxWidthPx = 0;
            int tileBoxHeightPx = 0;
            MapRouteInfoMenu routeInfoMenu = mapLayers.getMapControlsLayer().getMapRouteInfoMenu();
            WeakReference<MapRouteInfoMenuFragment> fragmentRef = routeInfoMenu.findMenuFragment();
            if (fragmentRef != null) {
                MapRouteInfoMenuFragment f = fragmentRef.get();
                if (landscapeLayout) {
                    tileBoxWidthPx = tb.getPixWidth() - f.getWidth();
                } else {
                    tileBoxHeightPx = tb.getPixHeight() - f.getHeight();
                }
            }
            mapView.fitRectToMap(left, right, top, bottom, tileBoxWidthPx, tileBoxHeightPx, 0);
        }
    }
}
Also used : RotatedTileBox(net.osmand.data.RotatedTileBox) MapRouteInfoMenu(net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu) RoutingHelper(net.osmand.plus.routing.RoutingHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) MapRouteInfoMenuFragment(net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenuFragment) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) QuadPoint(net.osmand.data.QuadPoint) NewGpxPoint(net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint) 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