Fix context menu zoom
This commit is contained in:
parent
baf37542d5
commit
53bc3b1a1a
2 changed files with 60 additions and 12 deletions
|
@ -565,6 +565,7 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
|||
boolean needMapAdjust = oldMenuState != newMenuState && newMenuState != MenuState.FULL_SCREEN;
|
||||
|
||||
if (newMenuState != oldMenuState) {
|
||||
restoreCustomMapRatio();
|
||||
menu.updateControlsVisibility(true);
|
||||
doBeforeMenuStateChange(oldMenuState, newMenuState);
|
||||
}
|
||||
|
@ -572,20 +573,39 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
|||
applyPosY(currentY, needCloseMenu, needMapAdjust, oldMenuState, newMenuState, 0);
|
||||
}
|
||||
|
||||
public void doZoomIn() {
|
||||
if (!centered) {
|
||||
centered = true;
|
||||
calculateCenterLatLon(menu.getLatLon(), getZoom() + 1, true);
|
||||
private void restoreCustomMapRatio() {
|
||||
if (map.hasCustomMapRatio()) {
|
||||
map.restoreMapRatio();
|
||||
}
|
||||
}
|
||||
|
||||
private void setCustomMapRatio() {
|
||||
LatLon latLon = menu.getLatLon();
|
||||
RotatedTileBox tb = map.getCurrentRotatedTileBox().copy();
|
||||
float px = tb.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
||||
float py = tb.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
|
||||
float ratioX = px / tb.getPixWidth();
|
||||
float ratioY = py / tb.getPixHeight();
|
||||
map.setCustomMapRatio(ratioX, ratioY);
|
||||
map.setLatLon(latLon.getLatitude(), latLon.getLongitude());
|
||||
}
|
||||
|
||||
public void doZoomIn() {
|
||||
if (map.isZooming() && map.hasCustomMapRatio()) {
|
||||
getMapActivity().changeZoom(2, System.currentTimeMillis());
|
||||
} else {
|
||||
if (!map.hasCustomMapRatio()) {
|
||||
setCustomMapRatio();
|
||||
}
|
||||
getMapActivity().changeZoom(1, System.currentTimeMillis());
|
||||
}
|
||||
applyPosY(getViewY(), false, true, 0, 0, 1);
|
||||
}
|
||||
|
||||
public void doZoomOut() {
|
||||
if (!centered) {
|
||||
centered = true;
|
||||
calculateCenterLatLon(menu.getLatLon(), getZoom() - 1, true);
|
||||
if (!map.hasCustomMapRatio()) {
|
||||
setCustomMapRatio();
|
||||
}
|
||||
applyPosY(getViewY(), false, true, 0, 0, -1);
|
||||
getMapActivity().changeZoom(-1, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
private void applyPosY(final int currentY, final boolean needCloseMenu, boolean needMapAdjust,
|
||||
|
@ -859,6 +879,8 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents {
|
|||
|
||||
@Override
|
||||
public void onPause() {
|
||||
restoreCustomMapRatio();
|
||||
|
||||
ViewParent parent = view.getParent();
|
||||
if (parent != null && containerLayoutListener != null) {
|
||||
((View) parent).removeOnLayoutChangeListener(containerLayoutListener);
|
||||
|
|
|
@ -124,9 +124,12 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
|||
private float rotate; // accumulate
|
||||
|
||||
private int mapPosition;
|
||||
|
||||
private int mapPositionX;
|
||||
|
||||
private float mapRatioX;
|
||||
private float mapRatioY;
|
||||
private LatLon originalRatioCenterLatLon;
|
||||
|
||||
private boolean showMapPosition = true;
|
||||
|
||||
private IMapLocationListener locationListener;
|
||||
|
@ -488,6 +491,25 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
|||
this.mapPositionX = type;
|
||||
}
|
||||
|
||||
public void setCustomMapRatio(float ratioX, float ratioY) {
|
||||
this.mapRatioX = ratioX;
|
||||
this.mapRatioY = ratioY;
|
||||
originalRatioCenterLatLon = currentViewport.getCenterLatLon();
|
||||
}
|
||||
|
||||
public void restoreMapRatio() {
|
||||
mapRatioX = 0;
|
||||
mapRatioY = 0;
|
||||
if (originalRatioCenterLatLon != null) {
|
||||
setLatLon(originalRatioCenterLatLon.getLatitude(), originalRatioCenterLatLon.getLongitude());
|
||||
originalRatioCenterLatLon = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasCustomMapRatio() {
|
||||
return mapRatioX != 0 && mapRatioY != 0;
|
||||
}
|
||||
|
||||
public OsmandSettings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
@ -576,7 +598,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
|||
return;
|
||||
}
|
||||
final float ratioy;
|
||||
if (mapPosition == OsmandSettings.BOTTOM_CONSTANT) {
|
||||
if (mapRatioY != 0) {
|
||||
ratioy = mapRatioY;
|
||||
} else if (mapPosition == OsmandSettings.BOTTOM_CONSTANT) {
|
||||
ratioy = 0.85f;
|
||||
} else if (mapPosition == OsmandSettings.MIDDLE_BOTTOM_CONSTANT) {
|
||||
ratioy = 0.70f;
|
||||
|
@ -586,7 +610,9 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
|||
ratioy = 0.5f;
|
||||
}
|
||||
final float ratiox;
|
||||
if (mapPosition == OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT) {
|
||||
if (mapRatioX != 0) {
|
||||
ratiox = mapRatioX;
|
||||
} else if (mapPosition == OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT) {
|
||||
ratiox = 0.7f;
|
||||
} else {
|
||||
ratiox = mapPositionX == 0 ? 0.5f : 0.75f;
|
||||
|
|
Loading…
Reference in a new issue