- allow bbox zoom to scale to MAX_END_SCALE
- use FastMath.clamp
This commit is contained in:
parent
2cb8a9d45f
commit
c14d101aef
@ -63,6 +63,10 @@ public class FastMath {
|
|||||||
return (value < min ? min : (value > max ? max : value));
|
return (value < min ? min : (value > max ? max : value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static double clamp(double value, double min, double max) {
|
||||||
|
return (value < min ? min : (value > max ? max : value));
|
||||||
|
}
|
||||||
|
|
||||||
public static float clampN(float value) {
|
public static float clampN(float value) {
|
||||||
return (value < 0f ? 0f : (value > 1f ? 1f : value));
|
return (value < 0f ? 0f : (value > 1f ? 1f : value));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,6 +43,7 @@ public class MapViewPosition {
|
|||||||
|
|
||||||
public final static int MAX_ZOOMLEVEL = 17;
|
public final static int MAX_ZOOMLEVEL = 17;
|
||||||
public final static int MIN_ZOOMLEVEL = 2;
|
public final static int MIN_ZOOMLEVEL = 2;
|
||||||
|
public final static int MAX_END_SCALE = 8;
|
||||||
|
|
||||||
private final static float MAX_ANGLE = 65;
|
private final static float MAX_ANGLE = 65;
|
||||||
|
|
||||||
@ -496,10 +497,7 @@ public class MapViewPosition {
|
|||||||
public synchronized boolean scaleMap(float scale, float pivotX, float pivotY) {
|
public synchronized boolean scaleMap(float scale, float pivotX, float pivotY) {
|
||||||
|
|
||||||
// sanitize input
|
// sanitize input
|
||||||
if (scale < 0.5)
|
scale = FastMath.clamp(scale, 0.5f, 2);
|
||||||
scale = 0.5f;
|
|
||||||
else if (scale > 2)
|
|
||||||
scale = 2;
|
|
||||||
|
|
||||||
float newScale = mMapScale * scale;
|
float newScale = mMapScale * scale;
|
||||||
|
|
||||||
@ -552,11 +550,7 @@ public class MapViewPosition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean tilt(float move) {
|
public synchronized boolean tilt(float move) {
|
||||||
float tilt = mTilt + move;
|
float tilt = FastMath.clamp(mTilt + move, 0, MAX_ANGLE);
|
||||||
if (tilt > MAX_ANGLE)
|
|
||||||
tilt = MAX_ANGLE;
|
|
||||||
else if (tilt < 0)
|
|
||||||
tilt = 0;
|
|
||||||
|
|
||||||
if (mTilt == tilt)
|
if (mTilt == tilt)
|
||||||
return false;
|
return false;
|
||||||
@ -596,11 +590,7 @@ public class MapViewPosition {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setZoomLevelLimit(byte zoomLevel) {
|
private void setZoomLevelLimit(byte zoomLevel) {
|
||||||
mZoomLevel = zoomLevel;
|
mZoomLevel = (byte)FastMath.clamp(zoomLevel, MIN_ZOOMLEVEL, MAX_ZOOMLEVEL);
|
||||||
if (mZoomLevel > MAX_ZOOMLEVEL)
|
|
||||||
mZoomLevel = MAX_ZOOMLEVEL;
|
|
||||||
else if (mZoomLevel < MIN_ZOOMLEVEL)
|
|
||||||
mZoomLevel = MIN_ZOOMLEVEL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePosition() {
|
private void updatePosition() {
|
||||||
@ -627,14 +617,10 @@ public class MapViewPosition {
|
|||||||
|
|
||||||
double z = Math.min(zx, zy);
|
double z = Math.min(zx, zy);
|
||||||
|
|
||||||
if (z > MAX_ZOOMLEVEL)
|
setZoomLevelLimit((byte) Math.floor(z));
|
||||||
z = MAX_ZOOMLEVEL;
|
|
||||||
else if (z < MIN_ZOOMLEVEL)
|
mScale = FastMath.clamp((float) (1 + (z - mZoomLevel)), 1, MAX_END_SCALE);
|
||||||
z = MIN_ZOOMLEVEL;
|
|
||||||
|
|
||||||
mZoomLevel = (byte) Math.floor(z);
|
|
||||||
mScale = (float) (1 + (z - mZoomLevel));
|
|
||||||
// global scale
|
|
||||||
mMapScale = (1 << mZoomLevel) * mScale;
|
mMapScale = (1 << mZoomLevel) * mScale;
|
||||||
//Log.d(TAG, "zoom: " + bbox + " " + zx + " " + zy + " / " + mScale + " " + mZoomLevel);
|
//Log.d(TAG, "zoom: " + bbox + " " + zx + " " + zy + " / " + mScale + " " + mZoomLevel);
|
||||||
setMapCenter(bbox.getCenterPoint());
|
setMapCenter(bbox.getCenterPoint());
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user