Search in sources :

Example 21 with OnlineRoutingEngine

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);
}
Also used : LatLon(net.osmand.data.LatLon) OnlineRoutingEngine(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine) ArrayList(java.util.ArrayList) OnlineRoutingHelper(net.osmand.plus.onlinerouting.OnlineRoutingHelper) OnlineRoutingResponse(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine.OnlineRoutingResponse) Location(net.osmand.Location)

Example 22 with OnlineRoutingEngine

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);
    }
}
Also used : OnlineRoutingEngine(net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) RouteCalculationProgress(net.osmand.router.RouteCalculationProgress)

Aggregations

OnlineRoutingEngine (net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine)22 ArrayList (java.util.ArrayList)8 File (java.io.File)6 ITileSource (net.osmand.map.ITileSource)6 AvoidRoadInfo (net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo)5 HistoryEntry (net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry)5 MapMarkersGroup (net.osmand.plus.mapmarkers.MapMarkersGroup)5 FavoriteGroup (net.osmand.plus.myplaces.FavoriteGroup)5 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)5 QuickAction (net.osmand.plus.quickaction.QuickAction)5 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)5 OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)4 OsmNotesPoint (net.osmand.plus.plugins.osmedit.data.OsmNotesPoint)4 ApplicationModeBean (net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean)4 NonNull (androidx.annotation.NonNull)3 MapMarker (net.osmand.plus.mapmarkers.MapMarker)3 OnlineRoutingHelper (net.osmand.plus.onlinerouting.OnlineRoutingHelper)3 SQLiteTileSource (net.osmand.plus.resources.SQLiteTileSource)3 FileSettingsItem (net.osmand.plus.settings.backend.backup.items.FileSettingsItem)3 GlobalSettingsItem (net.osmand.plus.settings.backend.backup.items.GlobalSettingsItem)3