From af7031bfb6cf33b5a836fa690089ce5efb56e87b Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Thu, 10 Nov 2016 19:55:39 +0300 Subject: [PATCH] Fix #3245 --- .../osmand/plus/activities/MapActivity.java | 7 ++++-- .../other/MapRouteInfoMenu.java | 25 ++++++++++++++++--- .../osmand/plus/views/OsmandMapTileView.java | 23 +++++++++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 2f1ad2a545..1671f80532 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -781,8 +781,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven if (MapRouteInfoMenu.isVisible()) { mapContextMenu.showMinimized(latLonToShow, mapLabelToShow, toShow); mapLayers.getMapControlsLayer().getMapRouteInfoMenu().updateMenu(); - mapView.getAnimatedDraggingThread().startMoving(latLonToShow.getLatitude(), - latLonToShow.getLongitude(), settings.getMapZoomToShow(), true); + MapRouteInfoMenu.showLocationOnMap(this, latLonToShow.getLatitude(), latLonToShow.getLongitude()); } else { mapContextMenu.show(latLonToShow, mapLabelToShow, toShow); } @@ -1383,6 +1382,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } + public boolean isLandscapeLayout() { + return landscapeLayout; + } + @Override public void newRouteIsCalculated(boolean newRoute, ValueHolder showToast) { RoutingHelper rh = app.getRoutingHelper(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java index 8f02585075..07cfc0c3b9 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java @@ -20,6 +20,7 @@ import android.widget.Spinner; import android.widget.TextView; import net.osmand.AndroidUtils; +import net.osmand.Location; import net.osmand.ValueHolder; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; @@ -547,8 +548,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener { RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo); net.osmand.Location l = routingHelper.getLocationFromRouteDirection(info); contextMenu.showMinimized(new LatLon(l.getLatitude(), l.getLongitude()), null, info); - mapView.getAnimatedDraggingThread().startMoving(l.getLatitude(), l.getLongitude(), - mapView.getZoom(), true); + showLocationOnMap(mapActivity, l.getLatitude(), l.getLongitude()); } } mapView.refreshMap(); @@ -570,7 +570,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener { RouteDirectionInfo info = routingHelper.getRouteDirections().get(directionInfo); net.osmand.Location l = routingHelper.getLocationFromRouteDirection(info); contextMenu.showMinimized(new LatLon(l.getLatitude(), l.getLongitude()), null, info); - mapView.getAnimatedDraggingThread().startMoving(l.getLatitude(), l.getLongitude(), mapView.getZoom(), true); + showLocationOnMap(mapActivity, l.getLatitude(), l.getLongitude()); } mapView.refreshMap(); updateInfo(mainView); @@ -623,6 +623,25 @@ public class MapRouteInfoMenu implements IRouteInformationListener { } } + public static void showLocationOnMap(MapActivity mapActivity, double latitude, double longitude) { + RotatedTileBox tb = mapActivity.getMapView().getCurrentRotatedTileBox().copy(); + int tileBoxWidthPx = 0; + int tileBoxHeightPx = 0; + + MapRouteInfoMenu routeInfoMenu = mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu(); + WeakReference fragmentRef = routeInfoMenu.findMenuFragment(); + if (fragmentRef != null) { + MapRouteInfoMenuFragment f = fragmentRef.get(); + if (mapActivity.isLandscapeLayout()) { + tileBoxWidthPx = tb.getPixWidth() - f.getWidth(); + } else { + tileBoxHeightPx = tb.getPixHeight() - f.getHeight(); + } + } + mapActivity.getMapView().fitLocationToMap(latitude, longitude, mapActivity.getMapView().getZoom(), + tileBoxWidthPx, tileBoxHeightPx, AndroidUtils.dpToPx(mapActivity, 40f)); + } + @Override public void newRouteIsCalculated(boolean newRoute, ValueHolder showToast) { directionInfo = -1; diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index b480f72934..6560c5c5f5 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -798,6 +798,29 @@ public class OsmandMapTileView implements IMapDownloaderCallback { animatedDraggingThread.startMoving(clat, clon, tb.getZoom(), true); } + public void fitLocationToMap(double clat, double clon, int zoom, + int tileBoxWidthPx, int tileBoxHeightPx, int marginTopPx) { + RotatedTileBox tb = currentViewport.copy(); + int dy = 0; + + int tbw = tb.getPixWidth(); + int tbh = tb.getPixHeight(); + if (tileBoxWidthPx > 0) { + tbw = tileBoxWidthPx; + } else if (tileBoxHeightPx > 0) { + tbh = tileBoxHeightPx; + dy = (tb.getPixHeight() - tileBoxHeightPx) / 2 - marginTopPx; + } + tb.setPixelDimensions(tbw, tbh); + tb.setLatLonCenter(clat, clon); + tb.setZoom(zoom); + if (dy != 0) { + clat = tb.getLatFromPixel(tb.getPixWidth() / 2, tb.getPixHeight() / 2 + dy); + clon = tb.getLonFromPixel(tb.getPixWidth() / 2, tb.getPixHeight() / 2); + } + animatedDraggingThread.startMoving(clat, clon, tb.getZoom(), true); + } + public boolean onGenericMotionEvent(MotionEvent event) { if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0 && event.getAction() == MotionEvent.ACTION_SCROLL &&