From c5515dd5ff7eb3bc5c8dacccaf6561488a2adf7e Mon Sep 17 00:00:00 2001 From: vshcherb Date: Wed, 26 Mar 2014 23:28:51 +0100 Subject: [PATCH] Show whole route after calculation --- .../plus/activities/MapActivityActions.java | 1 + .../plus/base/MapViewTrackingUtilities.java | 39 ++++++++++++++++++- .../views/controls/MapRouteInfoControl.java | 2 +- .../controls/MapRoutePreferencesControl.java | 1 + 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index b4bb1a9f54..161b98456a 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -460,6 +460,7 @@ public class MapActivityActions implements DialogProvider { // save application mode controls settings.FOLLOW_THE_ROUTE.set(false); settings.FOLLOW_THE_GPX_ROUTE.set(null); + app.getRoutingHelper().setGpxParams(null); app.getRoutingHelper().setFollowingMode(false); app.getRoutingHelper().setRoutePlanningMode(true); targets.setStartPoint(from, false, fromName); diff --git a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java index 9a200a4e58..77f65cb850 100644 --- a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java +++ b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java @@ -1,7 +1,10 @@ package net.osmand.plus.base; +import java.util.List; + import net.osmand.Location; import net.osmand.StateChangedListener; +import net.osmand.data.LatLon; import net.osmand.data.RotatedTileBox; import net.osmand.map.IMapLocationListener; import net.osmand.plus.OsmAndConstants; @@ -13,13 +16,14 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.AutoZoomMap; import net.osmand.plus.R; import net.osmand.plus.routing.RoutingHelper; +import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener; import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.util.MapUtils; import android.content.Context; import android.view.WindowManager; -public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLocationListener, OsmAndCompassListener { +public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLocationListener, OsmAndCompassListener, IRouteInformationListener { private static final int AUTO_FOLLOW_MSG_ID = OsmAndConstants.UI_HANDLER_LOCATION_SERVICE + 4; private long lastTimeAutoZooming = 0; @@ -39,6 +43,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc app.getLocationProvider().addLocationListener(this); app.getLocationProvider().addCompassListener(this); addTargetPointListener(app); + app.getRoutingHelper().addListener(this); } private void addTargetPointListener(OsmandApplication app) { @@ -274,4 +279,36 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc } } + @Override + public void newRouteIsCalculated(boolean newRoute) { + RoutingHelper rh = app.getRoutingHelper(); + if(newRoute && rh.isRoutePlanningMode()) { + RotatedTileBox rt = mapView.getCurrentRotatedTileBox(); + Location lt = rh.getLastProjection(); + if(lt != null) { + double left = lt.getLongitude(), right = lt.getLongitude(); + double top = lt.getLatitude(), bottom = lt.getLatitude(); + List list = app.getTargetPointsHelper().getIntermediatePointsWithTarget(); + for(LatLon l : list) { + left = Math.min(left, l.getLongitude()); + right = Math.max(left, l.getLongitude()); + top = Math.max(top, l.getLatitude()); + bottom = Math.min(bottom, l.getLatitude()); + } + RotatedTileBox tb = new RotatedTileBox(rt); + tb.setPixelDimensions(2 * tb.getPixWidth() / 3, 2 * tb.getPixHeight() / 3); + tb.setLatLonCenter(bottom / 2 + top / 2, left / 2 + right / 2); + while(tb.getZoom() >= 7 && (!tb.containsLatLon(top, left) || !tb.containsLatLon(bottom, right))) { + tb.setZoom(tb.getZoom() - 1); + } + mapView.getAnimatedDraggingThread().startMoving(tb.getLatitude(), tb.getLongitude(), tb.getZoom(), + true); + } + } + } + + @Override + public void routeWasCancelled() { + } + } diff --git a/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java b/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java index ec598ae5ae..d4baf51694 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/MapRouteInfoControl.java @@ -6,6 +6,7 @@ import java.util.List; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.RotatedTileBox; +import net.osmand.data.RotatedTileBox.RotatedTileBoxBuilder; import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -16,7 +17,6 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.ShowRouteInfoActivity; import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; -import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener; import net.osmand.plus.views.ContextMenuLayer; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; diff --git a/OsmAnd/src/net/osmand/plus/views/controls/MapRoutePreferencesControl.java b/OsmAnd/src/net/osmand/plus/views/controls/MapRoutePreferencesControl.java index 0b89019e23..83ca9c61fe 100644 --- a/OsmAnd/src/net/osmand/plus/views/controls/MapRoutePreferencesControl.java +++ b/OsmAnd/src/net/osmand/plus/views/controls/MapRoutePreferencesControl.java @@ -318,6 +318,7 @@ public class MapRoutePreferencesControl extends MapControls { loc = ps.get(0); tg.setStartPoint(new LatLon(loc.getLatitude(), loc.getLongitude()), false, null); } + tg.updateRoutingHelper(); } mapActivity.getRoutingHelper().setGpxParams(params); settings.FOLLOW_THE_GPX_ROUTE.set(result.path);