use of net.osmand.router.RouteCalculationProgress 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;
}
use of net.osmand.router.RouteCalculationProgress 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;
}
use of net.osmand.router.RouteCalculationProgress in project Osmand by osmandapp.
the class RoutingHelper method recalculateRouteInBackground.
private void recalculateRouteInBackground(final Location start, final LatLon end, final List<LatLon> intermediates, final GPXRouteParamsBuilder gpxRoute, final RouteCalculationResult previousRoute, boolean paramsChanged, boolean onlyStartPointChanged) {
if (start == null || end == null) {
return;
}
// do not evaluate very often
if ((currentRunningJob == null && System.currentTimeMillis() - lastTimeEvaluatedRoute > evalWaitInterval) || paramsChanged || !onlyStartPointChanged) {
if (System.currentTimeMillis() - lastTimeEvaluatedRoute < RECALCULATE_THRESHOLD_CAUSING_FULL_RECALCULATE_INTERVAL) {
recalculateCountInInterval++;
}
RouteCalculationParams params = new RouteCalculationParams();
params.start = start;
params.end = end;
params.intermediates = intermediates;
params.gpxRoute = gpxRoute == null ? null : gpxRoute.build(start, settings);
params.onlyStartPointChanged = onlyStartPointChanged;
if (recalculateCountInInterval < RECALCULATE_THRESHOLD_COUNT_CAUSING_FULL_RECALCULATE) {
params.previousToRecalculate = previousRoute;
} else {
recalculateCountInInterval = 0;
}
params.leftSide = settings.DRIVING_REGION.get().leftHandDriving;
params.fast = settings.FAST_ROUTE_MODE.getModeValue(mode);
params.type = settings.ROUTER_SERVICE.getModeValue(mode);
params.mode = mode;
params.ctx = app;
boolean updateProgress = false;
if (params.type == RouteService.OSMAND) {
params.calculationProgress = new RouteCalculationProgress();
updateProgress = true;
}
startRouteCalculationThread(params, paramsChanged, updateProgress);
}
}
Aggregations