parent
d492358a94
commit
ff630fdcfa
@ -112,7 +112,7 @@ public class Animator {
|
||||
if (relative)
|
||||
scale = mStartPos.scale * scale;
|
||||
|
||||
scale = clamp(scale, Viewport.MIN_SCALE, Viewport.MAX_SCALE);
|
||||
scale = mMap.viewport().limitScale(scale);
|
||||
|
||||
mDeltaPos.set(longitudeToX(geoPoint.getLongitude()) - mStartPos.x,
|
||||
latitudeToY(geoPoint.getLatitude()) - mStartPos.y,
|
||||
@ -131,15 +131,13 @@ public class Animator {
|
||||
|
||||
mMap.getMapPosition(mStartPos);
|
||||
|
||||
pos.scale = clamp(pos.scale,
|
||||
Viewport.MIN_SCALE,
|
||||
Viewport.MAX_SCALE);
|
||||
pos.scale = mMap.viewport().limitScale(pos.scale);
|
||||
|
||||
mDeltaPos.set(pos.x - mStartPos.x,
|
||||
pos.y - mStartPos.y,
|
||||
pos.scale - mStartPos.scale,
|
||||
pos.bearing - mStartPos.bearing,
|
||||
clamp(pos.tilt, 0, Viewport.MAX_TILT) - mStartPos.tilt);
|
||||
mMap.viewport().limitTilt(pos.tilt) - mStartPos.tilt);
|
||||
|
||||
animStart(duration, ANIM_MOVE | ANIM_SCALE | ANIM_ROTATE | ANIM_TILT);
|
||||
}
|
||||
@ -156,7 +154,7 @@ public class Animator {
|
||||
scaleBy = mCurPos.scale * scaleBy;
|
||||
|
||||
mStartPos.copy(mCurPos);
|
||||
scaleBy = clamp(scaleBy, Viewport.MIN_SCALE, Viewport.MAX_SCALE);
|
||||
scaleBy = mMap.viewport().limitScale(scaleBy);
|
||||
|
||||
mDeltaPos.scale = scaleBy - mStartPos.scale;
|
||||
|
||||
|
@ -124,7 +124,7 @@ public class ViewController extends Viewport {
|
||||
|
||||
double newScale = mPos.scale * scale;
|
||||
|
||||
newScale = FastMath.clamp(newScale, MIN_SCALE, MAX_SCALE);
|
||||
newScale = clamp(newScale, mMinScale, mMaxScale);
|
||||
|
||||
if (newScale == mPos.scale)
|
||||
return false;
|
||||
@ -175,21 +175,21 @@ public class ViewController extends Viewport {
|
||||
degree += 360;
|
||||
|
||||
mPos.bearing = (float) degree;
|
||||
|
||||
updateMatrices();
|
||||
}
|
||||
|
||||
public boolean tiltMap(float move) {
|
||||
ThreadUtils.assertMainThread();
|
||||
|
||||
return setTilt(mPos.tilt + move);
|
||||
}
|
||||
|
||||
public boolean setTilt(float tilt) {
|
||||
ThreadUtils.assertMainThread();
|
||||
|
||||
tilt = FastMath.clamp(tilt, 0, MAX_TILT);
|
||||
tilt = limitTilt(tilt);
|
||||
if (tilt == mPos.tilt)
|
||||
return false;
|
||||
|
||||
mPos.tilt = tilt;
|
||||
updateMatrices();
|
||||
return true;
|
||||
@ -198,11 +198,15 @@ public class ViewController extends Viewport {
|
||||
public void setMapPosition(MapPosition mapPosition) {
|
||||
ThreadUtils.assertMainThread();
|
||||
|
||||
mPos.scale = clamp(mapPosition.scale, MIN_SCALE, MAX_SCALE);
|
||||
mPos.x = mapPosition.x;
|
||||
mPos.y = mapPosition.y;
|
||||
mPos.tilt = clamp(mapPosition.tilt, 0, MAX_TILT);
|
||||
mPos.bearing = mapPosition.bearing;
|
||||
mPos.copy(mapPosition);
|
||||
limitPosition(mPos);
|
||||
|
||||
// mPos.scale = clamp(mapPosition.scale, mMinScale, mMaxScale);
|
||||
// mPos.x = mapPosition.x;
|
||||
// mPos.y = mapPosition.y;
|
||||
// mPos.tilt = limitTilt(mapPosition.tilt);
|
||||
// mPos.bearing = mapPosition.bearing;
|
||||
|
||||
updateMatrices();
|
||||
}
|
||||
|
||||
|
@ -36,13 +36,24 @@ import org.oscim.utils.FastMath;
|
||||
public class Viewport {
|
||||
//static final Logger log = LoggerFactory.getLogger(Viewport.class);
|
||||
|
||||
public final static int MAX_ZOOMLEVEL = 20;
|
||||
public final static int MIN_ZOOMLEVEL = 2;
|
||||
private final static int MAX_ZOOMLEVEL = 20;
|
||||
private final static int MIN_ZOOMLEVEL = 2;
|
||||
private final static float MIN_TILT = 0;
|
||||
private final static float MAX_TILT = 65;
|
||||
|
||||
public final static double MAX_SCALE = (1 << MAX_ZOOMLEVEL);
|
||||
public final static double MIN_SCALE = (1 << MIN_ZOOMLEVEL);
|
||||
protected double mMaxScale = (1 << MAX_ZOOMLEVEL);
|
||||
protected double mMinScale = (1 << MIN_ZOOMLEVEL);
|
||||
|
||||
public final static float MAX_TILT = 65;
|
||||
protected float mMinTilt = MIN_TILT;
|
||||
protected float mMaxTilt = MAX_TILT;
|
||||
|
||||
protected float mMinBearing = -180;
|
||||
protected float mMaxBearing = 180;
|
||||
|
||||
protected double mMinX = 0;
|
||||
protected double mMaxX = 1;
|
||||
protected double mMinY = 0;
|
||||
protected double mMaxY = 1;
|
||||
|
||||
protected final MapPosition mPos = new MapPosition();
|
||||
|
||||
@ -72,13 +83,76 @@ public class Viewport {
|
||||
public final static float VIEW_SCALE = (VIEW_NEAR / VIEW_DISTANCE) * 0.5f;
|
||||
|
||||
public Viewport() {
|
||||
mPos.scale = MIN_SCALE;
|
||||
mPos.scale = mMinScale;
|
||||
mPos.x = 0.5;
|
||||
mPos.y = 0.5;
|
||||
mPos.bearing = 0;
|
||||
mPos.tilt = 0;
|
||||
}
|
||||
|
||||
public double limitScale(double scale) {
|
||||
if (scale > mMaxScale)
|
||||
return mMaxScale;
|
||||
else if (scale < mMinScale)
|
||||
return mMinScale;
|
||||
|
||||
return scale;
|
||||
}
|
||||
|
||||
public float limitTilt(float tilt) {
|
||||
if (tilt > mMaxTilt)
|
||||
return mMaxTilt;
|
||||
else if (tilt < mMinTilt)
|
||||
return mMinTilt;
|
||||
|
||||
return tilt;
|
||||
}
|
||||
|
||||
public boolean limitPosition(MapPosition pos) {
|
||||
boolean changed = false;
|
||||
if (pos.scale > mMaxScale) {
|
||||
pos.scale = mMaxScale;
|
||||
changed = true;
|
||||
} else if (pos.scale < mMinScale) {
|
||||
pos.scale = mMinScale;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (pos.tilt > mMaxTilt) {
|
||||
pos.tilt = mMaxTilt;
|
||||
changed = true;
|
||||
} else if (pos.tilt < mMinTilt) {
|
||||
pos.tilt = mMinTilt;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (pos.bearing > mMaxBearing) {
|
||||
pos.bearing = mMaxBearing;
|
||||
changed = true;
|
||||
} else if (pos.bearing < mMinBearing) {
|
||||
pos.bearing = mMinBearing;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (pos.x > mMaxX) {
|
||||
pos.x = mMaxX;
|
||||
changed = true;
|
||||
} else if (pos.x < mMinX) {
|
||||
pos.x = mMinX;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (pos.y > mMaxY) {
|
||||
pos.y = mMaxY;
|
||||
changed = true;
|
||||
} else if (pos.y < mMinY) {
|
||||
pos.y = mMinY;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current MapPosition.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user