Mapbox Android disable scrolling and panning maps

I am trying to disable zoom and pan the map in a file cabinet. I am using mapbox 0.4.0. Currently, I can turn off the zoom, but I cannot turn off the pan

    MapView mv = (MapView) tab.findViewById(R.id.mapid);
    mv.setZoom(14);
    mv.setMaxZoomLevel(14);
    mv.setMinZoomLevel(14);
+4
source share
4 answers

In the current version (4.1), this should probably do:

map.getUiSettings().setZoomControlsEnabled(false);
map.getUiSettings().setZoomGesturesEnabled(false);
map.getUiSettings().setScrollGesturesEnabled(false);

Or, if you want to completely get rid of the interaction:

map.getUiSettings().setAllGesturesEnabled(false);
+9
source

, 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 = (MyMapView) findViewById(R.id.mapid);
//Here you can play with enabling/disabling pan. 
mapView.setPanShouldEnabled(false);

-.:)

+4

OnTouch true:

mapView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return true;
    }
});
+4

Unfortunately, the only solution is to put a transparent view on top of the card, which will consume touch. I use Buttonwith a transparent background. At the moment, MapBox still does not allow developers to turn off user interaction.

+1
source

All Articles