add MapEventLayer.fixOnCenter()
- when enabled position is kept for zoom/rotation gesture
This commit is contained in:
parent
fbfe17743e
commit
1ca175c598
@ -40,11 +40,11 @@ public class MapEventLayer extends Layer implements InputListener, GestureListen
|
|||||||
|
|
||||||
static final Logger log = LoggerFactory.getLogger(MapEventLayer.class);
|
static final Logger log = LoggerFactory.getLogger(MapEventLayer.class);
|
||||||
|
|
||||||
/* TODO replace with bitmasks */
|
|
||||||
private boolean mEnableRotate = true;
|
private boolean mEnableRotate = true;
|
||||||
private boolean mEnableTilt = true;
|
private boolean mEnableTilt = true;
|
||||||
private boolean mEnableMove = true;
|
private boolean mEnableMove = true;
|
||||||
private boolean mEnableScale = true;
|
private boolean mEnableScale = true;
|
||||||
|
private boolean mFixOnCenter = false;
|
||||||
|
|
||||||
/* possible state transitions */
|
/* possible state transitions */
|
||||||
private boolean mCanScale;
|
private boolean mCanScale;
|
||||||
@ -113,6 +113,13 @@ public class MapEventLayer extends Layer implements InputListener, GestureListen
|
|||||||
mEnableScale = enable;
|
mEnableScale = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When enabled zoom- and rotation-gestures will not move the viewport.
|
||||||
|
*/
|
||||||
|
public void setFixOnCenter(boolean enable) {
|
||||||
|
mFixOnCenter = enable;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean onTouchEvent(MotionEvent e) {
|
public boolean onTouchEvent(MotionEvent e) {
|
||||||
|
|
||||||
int action = getAction(e);
|
int action = getAction(e);
|
||||||
@ -142,10 +149,14 @@ public class MapEventLayer extends Layer implements InputListener, GestureListen
|
|||||||
if (action == MotionEvent.ACTION_UP) {
|
if (action == MotionEvent.ACTION_UP) {
|
||||||
mDown = false;
|
mDown = false;
|
||||||
if (mDoubleTap && !mDragZoom) {
|
if (mDoubleTap && !mDragZoom) {
|
||||||
|
float pivotX = 0, pivotY = 0;
|
||||||
|
if (!mFixOnCenter) {
|
||||||
|
pivotX = mPrevX1 - mMap.getWidth() / 2;
|
||||||
|
pivotY = mPrevY1 - mMap.getHeight() / 2;
|
||||||
|
}
|
||||||
|
|
||||||
/* handle double tap zoom */
|
/* handle double tap zoom */
|
||||||
mMap.animator().animateZoom(300, 2,
|
mMap.animator().animateZoom(300, 2, pivotX, pivotY);
|
||||||
mPrevX1 - mMap.getWidth() / 2,
|
|
||||||
mPrevY1 - mMap.getHeight() / 2);
|
|
||||||
|
|
||||||
} else if (mStartMove > 0) {
|
} else if (mStartMove > 0) {
|
||||||
/* handle fling gesture */
|
/* handle fling gesture */
|
||||||
@ -337,16 +348,21 @@ public class MapEventLayer extends Layer implements InputListener, GestureListen
|
|||||||
if (!(mDoRotate || mDoScale || mDoTilt))
|
if (!(mDoRotate || mDoScale || mDoTilt))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float fx = (x2 + x1) / 2 - width / 2;
|
float pivotX = 0, pivotY = 0;
|
||||||
float fy = (y2 + y1) / 2 - height / 2;
|
|
||||||
|
if (!mFixOnCenter) {
|
||||||
|
pivotX = (x2 + x1) / 2 - width / 2;
|
||||||
|
pivotY = (y2 + y1) / 2 - height / 2;
|
||||||
|
}
|
||||||
|
|
||||||
synchronized (mViewport) {
|
synchronized (mViewport) {
|
||||||
if (!mDoTilt) {
|
if (!mDoTilt) {
|
||||||
if (rotateBy != 0)
|
if (rotateBy != 0)
|
||||||
mViewport.rotateMap(rotateBy, fx, fy);
|
mViewport.rotateMap(rotateBy, pivotX, pivotY);
|
||||||
if (scaleBy != 1)
|
if (scaleBy != 1)
|
||||||
mViewport.scaleMap(scaleBy, fx, fy);
|
mViewport.scaleMap(scaleBy, pivotX, pivotY);
|
||||||
|
|
||||||
|
if (!mFixOnCenter)
|
||||||
mViewport.moveMap(mx, my);
|
mViewport.moveMap(mx, my);
|
||||||
} else {
|
} else {
|
||||||
if (tiltBy != 0 && mViewport.tiltMap(-tiltBy))
|
if (tiltBy != 0 && mViewport.tiltMap(-tiltBy))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user