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