use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.
the class MissingMapsHelper method findOnlineRoutePoints.
public List<Location> findOnlineRoutePoints() throws IOException, JSONException {
List<LatLon> points = new ArrayList<>();
List<Location> routeLocation = new ArrayList<>();
OnlineRoutingHelper onlineRoutingHelper = params.ctx.getOnlineRoutingHelper();
List<Location> location = getStartFinishIntermediatePoints();
for (Location e : location) {
points.add(new LatLon(e.getLatitude(), e.getLongitude()));
}
OnlineRoutingEngine engine = onlineRoutingHelper.startOsrmEngine(params.mode);
if (engine != null) {
OnlineRoutingResponse response = onlineRoutingHelper.calculateRouteOnline(engine, points, params.start.hasBearing() ? params.start.getBearing() : null, params.leftSide, false);
if (response != null) {
routeLocation.addAll(response.getRoute());
}
}
return removeDensePoints(routeLocation);
}
use of net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine in project Osmand by osmandapp.
the class RouteRecalculationHelper method recalculateRouteInBackground.
public 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 ((!isRouteBeingCalculated() && System.currentTimeMillis() - lastTimeEvaluatedRoute > evalWaitInterval) || paramsChanged || !onlyStartPointChanged) {
if (System.currentTimeMillis() - lastTimeEvaluatedRoute < RECALCULATE_THRESHOLD_CAUSING_FULL_RECALCULATE_INTERVAL) {
recalculateCountInInterval++;
}
ApplicationMode mode = getAppMode();
final RouteCalculationParams params = new RouteCalculationParams();
params.start = start;
params.end = end;
params.intermediates = intermediates;
params.gpxRoute = gpxRoute == null ? null : gpxRoute.build(app);
params.onlyStartPointChanged = onlyStartPointChanged;
if (recalculateCountInInterval < RECALCULATE_THRESHOLD_COUNT_CAUSING_FULL_RECALCULATE || (gpxRoute != null && gpxRoute.isPassWholeRoute() && isDeviatedFromRoute())) {
params.previousToRecalculate = previousRoute;
} else {
recalculateCountInInterval = 0;
}
params.leftSide = getSettings().DRIVING_REGION.get().leftHandDriving;
params.fast = getSettings().FAST_ROUTE_MODE.getModeValue(mode);
params.mode = mode;
params.ctx = app;
boolean updateProgress = false;
if (params.mode.getRouteService() == RouteService.OSMAND) {
params.calculationProgress = new RouteCalculationProgress();
updateProgress = true;
}
if (getLastProjection() != null) {
params.currentLocation = getLastFixedLocation();
}
if (params.mode.getRouteService() == RouteService.ONLINE) {
OnlineRoutingEngine engine = app.getOnlineRoutingHelper().getEngineByKey(params.mode.getRoutingProfile());
if (engine != null) {
engine.updateRouteParameters(params, paramsChanged ? previousRoute : null);
}
}
startRouteCalculationThread(params, paramsChanged, updateProgress);
}
}
Aggregations