This commit is contained in:
Alexey Kulish 2016-11-10 19:55:39 +03:00
parent 9705573d12
commit af7031bfb6
3 changed files with 50 additions and 5 deletions

View file

@ -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<Boolean> showToast) {
RoutingHelper rh = app.getRoutingHelper();

View file

@ -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<MapRouteInfoMenuFragment> 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<Boolean> showToast) {
directionInfo = -1;

View file

@ -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 &&