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;
}
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;
}
Aggregations