Мне нужно было сделать то же самое, но в MapBox sdk нет ничего соответствующего функциональности. Итак, я что-то выясняю сам. Я настроил MapView из MapBox sdk с включением/отключением функции панорамирования. Для этого я использовал SimpleTwoFingerDoubleTapDetector. Благодаря @Sam для этого класса, который помогает мне обнаруживать два пальца двойного крана.
Мой класс пользовательских MapView:
MyMapView.java:
import android.content.Context;
import android.os.Handler;
import android.support.v4.view.GestureDetectorCompat;
import android.util.AttributeSet;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.widget.Toast;
import com.mapbox.mapboxsdk.tileprovider.MapTileLayerBase;
import com.mapbox.mapboxsdk.views.MapView;
public class MyMapView extends MapView implements OnGestureListener,OnDoubleTapListener {
private GestureDetectorCompat mDetector;
public boolean panShouldEnabled = true;
public boolean isPanShouldEnabled() {
return panShouldEnabled;
}
public void setPanShouldEnabled(boolean panShouldEnabled) {
this.panShouldEnabled = panShouldEnabled;
}
public MyMapView(Context aContext, AttributeSet attrs) {
super(aContext, attrs);
init(aContext);
}
private void init(Context mContext) {
mDetector = new GestureDetectorCompat(mContext, this);
// Set the gesture detector as the double tap
// listener.
mDetector.setOnDoubleTapListener(this);
}
public MyMapView(Context aContext, int tileSizePixels,
MapTileLayerBase tileProvider, Handler tileRequestCompleteHandler,
AttributeSet attrs) {
super(aContext, tileSizePixels, tileProvider,
tileRequestCompleteHandler, attrs);
init(aContext);
}
public MyMapView(Context aContext, int tileSizePixels,
MapTileLayerBase aTileProvider) {
super(aContext, tileSizePixels, aTileProvider);
init(aContext);
}
public MyMapView(Context aContext) {
super(aContext);
init(aContext);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return !panShouldEnabled ? true : super.onInterceptTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (!panShouldEnabled) {
if (detector.onTouchEvent(event)) {
return true;
} else {
mDetector.onTouchEvent(event);
}
}
return !panShouldEnabled ? true : super.onTouchEvent(event);
}
@Override
public boolean onDown(MotionEvent arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onFling(MotionEvent arg0, MotionEvent arg1, float arg2,float arg3) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onLongPress(MotionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
float arg3) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onShowPress(MotionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean onSingleTapUp(MotionEvent arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onDoubleTap(MotionEvent event) {
zoomIn();
return true;
}
@Override
public boolean onDoubleTapEvent(MotionEvent event) {
return false;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent arg0) {
return false;
}
SimpleTwoFingerDoubleTapDetector detector = new SimpleTwoFingerDoubleTapDetector() {
@Override
public void onTwoFingerDoubleTap() {
Toast.makeText(getContext(), "Two Finger Double Tap", Toast.LENGTH_SHORT).show();
zoomOut();
}
};
}
Итак, теперь, когда вы будете получить доступ к MapView в вашей деятельности:
mapView = (MyMapView) findViewById(R.id.mapid);
//Here you can play with enabling/disabling pan.
mapView.setPanShouldEnabled(false);
Это могло бы помочь кто то. :)
Простой и худой. Это должен быть принятый ответ. –