Fix snap to road calculation logic
This commit is contained in:
parent
ea1706768e
commit
2214d4996b
4 changed files with 82 additions and 93 deletions
|
@ -45,6 +45,8 @@ import net.osmand.plus.GPXUtilities.WptPt;
|
|||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.TrackActivity;
|
||||
|
@ -65,7 +67,7 @@ import net.osmand.plus.measurementtool.command.MovePointCommand;
|
|||
import net.osmand.plus.measurementtool.command.RemovePointCommand;
|
||||
import net.osmand.plus.measurementtool.command.ReorderPointCommand;
|
||||
import net.osmand.plus.measurementtool.command.SnapToRoadCommand;
|
||||
import net.osmand.plus.routing.RouteProvider.SnapToRoadParams;
|
||||
import net.osmand.plus.routing.RouteCalculationParams;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
|
||||
|
@ -823,8 +825,17 @@ public class MeasurementToolFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
final SnapToRoadParams params = new SnapToRoadParams();
|
||||
params.applicationMode = snapToRoadAppMode;
|
||||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
OsmandSettings settings = app.getSettings();
|
||||
final RouteCalculationParams params = new RouteCalculationParams();
|
||||
params.start = start;
|
||||
params.end = end;
|
||||
params.intermediates = intermediates; // todo delete
|
||||
params.leftSide = settings.DRIVING_REGION.get().leftHandDriving;
|
||||
params.fast = settings.FAST_ROUTE_MODE.getModeValue(snapToRoadAppMode);
|
||||
params.type = settings.ROUTER_SERVICE.getModeValue(snapToRoadAppMode);
|
||||
params.mode = snapToRoadAppMode;
|
||||
params.ctx = app;
|
||||
params.calculationProgress = calculationProgress = new RouteCalculationProgress();
|
||||
params.calculationProgressCallback = new RoutingHelper.RouteCalculationProgressCallback() {
|
||||
@Override
|
||||
|
@ -846,11 +857,11 @@ public class MeasurementToolFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
};
|
||||
params.listener = new SnapToRoadParams.SnapToRoadListener() {
|
||||
params.resultListener = new RouteCalculationParams.RouteCalculationResultListener() {
|
||||
@Override
|
||||
public void onSnapToRoadDone() {
|
||||
ArrayList<WptPt> pts = new ArrayList<>(params.points.size());
|
||||
for (Location loc : params.points) {
|
||||
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();
|
||||
|
@ -864,7 +875,7 @@ public class MeasurementToolFragment extends Fragment {
|
|||
};
|
||||
snapToRoadProgressBar.setVisibility(View.VISIBLE);
|
||||
|
||||
mapActivity.getMyApplication().getRoutingHelper().recalculateSnapToRoad(start, end, intermediates, params);
|
||||
mapActivity.getMyApplication().getRoutingHelper().startRouteCalculationThread(params, true, true);
|
||||
} else if (calculationProgress != null) {
|
||||
calculationProgress.isCancelled = true;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,9 @@ import net.osmand.plus.ApplicationMode;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
|
||||
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||
import net.osmand.plus.routing.RouteProvider.SnapToRoadParams;
|
||||
import net.osmand.plus.routing.RoutingHelper.RouteCalculationProgressCallback;
|
||||
import net.osmand.router.RouteCalculationProgress;
|
||||
import net.osmand.router.RoutingContext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -19,13 +20,20 @@ public class RouteCalculationParams {
|
|||
|
||||
|
||||
public OsmandApplication ctx;
|
||||
public RoutingContext cachedRoutingContext;
|
||||
public ApplicationMode mode;
|
||||
public RouteService type;
|
||||
public GPXRouteParams gpxRoute;
|
||||
public SnapToRoadParams snapToRoadParams;
|
||||
public RouteCalculationResult previousToRecalculate;
|
||||
public boolean onlyStartPointChanged;
|
||||
public boolean fast;
|
||||
public boolean leftSide;
|
||||
public boolean inSnapToRoadMode;
|
||||
public RouteCalculationProgress calculationProgress;
|
||||
public RouteCalculationProgressCallback calculationProgressCallback;
|
||||
public RouteCalculationResultListener resultListener;
|
||||
|
||||
public interface RouteCalculationResultListener {
|
||||
void onRouteCalculated(List<Location> locations);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,9 @@
|
|||
package net.osmand.plus.routing;
|
||||
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.PlatformUtil;
|
||||
|
@ -44,13 +27,11 @@ import net.osmand.plus.TargetPointsHelper.TargetPoint;
|
|||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.activities.SettingsNavigationActivity;
|
||||
import net.osmand.plus.render.NativeOsmandLibrary;
|
||||
import net.osmand.plus.routing.RoutingHelper.RouteCalculationProgressCallback;
|
||||
import net.osmand.router.GeneralRouter;
|
||||
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
|
||||
import net.osmand.router.GeneralRouter.RoutingParameter;
|
||||
import net.osmand.router.GeneralRouter.RoutingParameterType;
|
||||
import net.osmand.router.PrecalculatedRouteDirection;
|
||||
import net.osmand.router.RouteCalculationProgress;
|
||||
import net.osmand.router.RoutePlannerFrontEnd;
|
||||
import net.osmand.router.RoutePlannerFrontEnd.RouteCalculationMode;
|
||||
import net.osmand.router.RouteSegmentResult;
|
||||
|
@ -59,22 +40,36 @@ import net.osmand.router.RoutingConfiguration.Builder;
|
|||
import net.osmand.router.RoutingContext;
|
||||
import net.osmand.router.TurnType;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
import net.osmand.util.GeoPolylineParserUtil;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import btools.routingapp.IBRouterService;
|
||||
|
||||
|
||||
|
@ -284,19 +279,6 @@ public class RouteProvider {
|
|||
}
|
||||
}
|
||||
|
||||
public static class SnapToRoadParams {
|
||||
|
||||
public ApplicationMode applicationMode;
|
||||
public RouteCalculationProgress calculationProgress;
|
||||
public RouteCalculationProgressCallback calculationProgressCallback;
|
||||
public SnapToRoadListener listener;
|
||||
public List<Location> points;
|
||||
|
||||
public interface SnapToRoadListener {
|
||||
void onSnapToRoadDone();
|
||||
}
|
||||
}
|
||||
|
||||
private static Location createLocation(WptPt pt){
|
||||
Location loc = new Location("OsmandRouteProvider");
|
||||
loc.setLatitude(pt.lat);
|
||||
|
@ -769,7 +751,7 @@ public class RouteProvider {
|
|||
paramsR.put(key, vl);
|
||||
}
|
||||
}
|
||||
if (params.snapToRoadParams != null) {
|
||||
if (params.inSnapToRoadMode) {
|
||||
paramsR.put(GeneralRouter.ALLOW_PRIVATE, "true");
|
||||
}
|
||||
float mb = (1 << 20);
|
||||
|
|
|
@ -19,7 +19,6 @@ import net.osmand.plus.notifications.OsmandNotification.NotificationType;
|
|||
import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
|
||||
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
|
||||
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||
import net.osmand.plus.routing.RouteProvider.SnapToRoadParams;
|
||||
import net.osmand.router.RouteCalculationProgress;
|
||||
import net.osmand.router.RouteSegmentResult;
|
||||
import net.osmand.router.TurnType;
|
||||
|
@ -388,7 +387,7 @@ public class RoutingHelper {
|
|||
|
||||
if (calculateRoute) {
|
||||
recalculateRouteInBackground(currentLocation, finalLocation, intermediatePoints, currentGPXRoute,
|
||||
previousRoute.isCalculated() ? previousRoute : null, false, !targetPointsChanged, null);
|
||||
previousRoute.isCalculated() ? previousRoute : null, false, !targetPointsChanged);
|
||||
} else {
|
||||
Thread job = currentRunningJob;
|
||||
if(job instanceof RouteRecalculationThread) {
|
||||
|
@ -871,11 +870,8 @@ public class RoutingHelper {
|
|||
synchronized (RoutingHelper.this) {
|
||||
if (res.isCalculated()) {
|
||||
route = res;
|
||||
if (params.snapToRoadParams != null) {
|
||||
params.snapToRoadParams.points = res.getRouteLocations();
|
||||
if (params.snapToRoadParams.listener != null) {
|
||||
params.snapToRoadParams.listener.onSnapToRoadDone();
|
||||
}
|
||||
if (params.resultListener != null) {
|
||||
params.resultListener.onRouteCalculated(res.getRouteLocations());
|
||||
}
|
||||
} else {
|
||||
evalWaitInterval = Math.max(3000, evalWaitInterval * 3 / 2); // for Issue #3899
|
||||
|
@ -911,18 +907,13 @@ public class RoutingHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void recalculateSnapToRoad(final Location start, final LatLon end, final List<LatLon> intermediates, SnapToRoadParams params) {
|
||||
recalculateRouteInBackground(start, end, intermediates, null, route, true, false, params);
|
||||
}
|
||||
|
||||
public void recalculateRouteDueToSettingsChange() {
|
||||
clearCurrentRoute(finalLocation, intermediatePoints);
|
||||
recalculateRouteInBackground(lastFixedLocation, finalLocation, intermediatePoints, currentGPXRoute, route, true, false, null);
|
||||
recalculateRouteInBackground(lastFixedLocation, finalLocation, intermediatePoints, currentGPXRoute, route, true, false);
|
||||
}
|
||||
|
||||
private void recalculateRouteInBackground(final Location start, final LatLon end, final List<LatLon> intermediates,
|
||||
final GPXRouteParamsBuilder gpxRoute, final RouteCalculationResult previousRoute, boolean paramsChanged, boolean onlyStartPointChanged,
|
||||
final SnapToRoadParams snapToRoadParams){
|
||||
final GPXRouteParamsBuilder gpxRoute, final RouteCalculationResult previousRoute, boolean paramsChanged, boolean onlyStartPointChanged){
|
||||
if (start == null || end == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -944,23 +935,21 @@ public class RoutingHelper {
|
|||
recalculateCountInInterval = 0;
|
||||
}
|
||||
params.leftSide = settings.DRIVING_REGION.get().leftHandDriving;
|
||||
ApplicationMode mode;
|
||||
if (snapToRoadParams != null && snapToRoadParams.applicationMode != null) {
|
||||
params.snapToRoadParams = snapToRoadParams;
|
||||
mode = snapToRoadParams.applicationMode;
|
||||
} else {
|
||||
mode = this.mode;
|
||||
}
|
||||
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) {
|
||||
if (snapToRoadParams != null && snapToRoadParams.calculationProgress != null) {
|
||||
params.calculationProgress = snapToRoadParams.calculationProgress;
|
||||
} else {
|
||||
params.calculationProgress = new RouteCalculationProgress();
|
||||
updateProgress = true;
|
||||
}
|
||||
startRouteCalculationThread(params, paramsChanged, updateProgress);
|
||||
}
|
||||
}
|
||||
|
||||
public void startRouteCalculationThread(RouteCalculationParams params, boolean paramsChanged, boolean updateProgress) {
|
||||
if (updateProgress) {
|
||||
updateProgress(params);
|
||||
}
|
||||
synchronized (this) {
|
||||
|
@ -974,12 +963,11 @@ public class RoutingHelper {
|
|||
currentRunningJob.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateProgress(final RouteCalculationParams params) {
|
||||
final RouteCalculationProgressCallback progressRoute;
|
||||
if (params.snapToRoadParams != null) {
|
||||
progressRoute = params.snapToRoadParams.calculationProgressCallback;
|
||||
if (params.calculationProgressCallback != null) {
|
||||
progressRoute = params.calculationProgressCallback;
|
||||
} else {
|
||||
progressRoute = this.progressRoute;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue