Search in sources :

Example 1 with RouteCalculationParams

use of net.osmand.plus.routing.RouteCalculationParams in project Osmand by osmandapp.

the class MeasurementEditingContext method getParams.

private RouteCalculationParams getParams() {
    final Pair<WptPt, WptPt> currentPair = snapToRoadPairsToCalculate.poll();
    Location start = new Location("");
    start.setLatitude(currentPair.first.getLatitude());
    start.setLongitude(currentPair.first.getLongitude());
    LatLon end = new LatLon(currentPair.second.getLatitude(), currentPair.second.getLongitude());
    final RouteCalculationParams params = new RouteCalculationParams();
    params.inSnapToRoadMode = true;
    params.start = start;
    params.end = end;
    RoutingHelper.applyApplicationSettings(params, application.getSettings(), snapToRoadAppMode);
    params.mode = snapToRoadAppMode;
    params.ctx = application;
    params.calculationProgress = calculationProgress = new RouteCalculationProgress();
    params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() {

        @Override
        public void updateProgress(int progress) {
            int pairs = calculatedPairs + snapToRoadPairsToCalculate.size();
            if (pairs != 0) {
                int pairProgress = 100 / pairs;
                progress = calculatedPairs * pairProgress + progress / pairs;
            }
            progressListener.updateProgress(progress);
        }

        @Override
        public void requestPrivateAccessRouting() {
        }

        @Override
        public void finish() {
            calculatedPairs = 0;
        }
    };
    params.resultListener = new RouteCalculationParams.RouteCalculationResultListener() {

        @Override
        public void onRouteCalculated(List<Location> locations) {
            ArrayList<WptPt> pts = new ArrayList<>(locations.size());
            for (Location loc : locations) {
                if (!loc.hasAltitude()) {
                    continue;
                }
                WptPt pt = new WptPt();
                pt.lat = loc.getLatitude();
                pt.lon = loc.getLongitude();
                pt.ele = loc.getAltitude();
                pts.add(pt);
            }
            calculatedPairs++;
            snappedToRoadPoints.put(currentPair, pts);
            updateCacheForSnapIfNeeded(true);
            application.runInUIThread(new Runnable() {

                @Override
                public void run() {
                    progressListener.refresh();
                }
            });
            if (!snapToRoadPairsToCalculate.isEmpty()) {
                application.getRoutingHelper().startRouteCalculationThread(getParams(), true, true);
            } else {
                application.runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        progressListener.hideProgressBar();
                    }
                });
            }
        }
    };
    return params;
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) RouteCalculationParams(net.osmand.plus.routing.RouteCalculationParams) ArrayList(java.util.ArrayList) RoutingHelper(net.osmand.plus.routing.RoutingHelper) LatLon(net.osmand.data.LatLon) Location(net.osmand.Location) RouteCalculationProgress(net.osmand.router.RouteCalculationProgress)

Example 2 with RouteCalculationParams

use of net.osmand.plus.routing.RouteCalculationParams in project Osmand by osmandapp.

the class MarkersPlanRouteContext method getParams.

private RouteCalculationParams getParams() {
    final Pair<WptPt, WptPt> currentPair = snapToRoadPairsToCalculate.poll();
    Location start = new Location("");
    start.setLatitude(currentPair.first.getLatitude());
    start.setLongitude(currentPair.first.getLongitude());
    LatLon end = new LatLon(currentPair.second.getLatitude(), currentPair.second.getLongitude());
    final RouteCalculationParams params = new RouteCalculationParams();
    params.inSnapToRoadMode = true;
    params.start = start;
    params.end = end;
    RoutingHelper.applyApplicationSettings(params, app.getSettings(), snappedMode);
    params.mode = snappedMode;
    params.ctx = app;
    params.calculationProgress = calculationProgress = new RouteCalculationProgress();
    params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() {

        @Override
        public void updateProgress(int progress) {
            int pairs = calculatedPairs + snapToRoadPairsToCalculate.size();
            if (pairs != 0) {
                int pairProgress = 100 / pairs;
                progress = calculatedPairs * pairProgress + progress / pairs;
            }
            listener.updateProgress(progress);
        }

        @Override
        public void requestPrivateAccessRouting() {
        }

        @Override
        public void finish() {
            calculatedPairs = 0;
        }
    };
    params.resultListener = new RouteCalculationParams.RouteCalculationResultListener() {

        @Override
        public void onRouteCalculated(List<Location> locations) {
            ArrayList<WptPt> pts = new ArrayList<>(locations.size());
            for (Location loc : locations) {
                WptPt pt = new WptPt();
                pt.lat = loc.getLatitude();
                pt.lon = loc.getLongitude();
                pts.add(pt);
            }
            calculatedPairs++;
            snappedToRoadPoints.put(currentPair, pts);
            recreateSnapTrkSegment(false);
            app.runInUIThread(new Runnable() {

                @Override
                public void run() {
                    listener.refresh();
                }
            });
            if (!snapToRoadPairsToCalculate.isEmpty()) {
                app.getRoutingHelper().startRouteCalculationThread(getParams(), true, true);
            } else {
                app.runInUIThread(new Runnable() {

                    @Override
                    public void run() {
                        listener.hideProgressBar(false);
                    }
                });
            }
        }
    };
    return params;
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) RouteCalculationParams(net.osmand.plus.routing.RouteCalculationParams) ArrayList(java.util.ArrayList) RoutingHelper(net.osmand.plus.routing.RoutingHelper) LatLon(net.osmand.data.LatLon) Location(net.osmand.Location) RouteCalculationProgress(net.osmand.router.RouteCalculationProgress)

Aggregations

ArrayList (java.util.ArrayList)2 Location (net.osmand.Location)2 LatLon (net.osmand.data.LatLon)2 WptPt (net.osmand.plus.GPXUtilities.WptPt)2 RouteCalculationParams (net.osmand.plus.routing.RouteCalculationParams)2 RoutingHelper (net.osmand.plus.routing.RoutingHelper)2 RouteCalculationProgress (net.osmand.router.RouteCalculationProgress)2