Ismail Sahin
Ismail Sahin

Reputation: 2710

osmdroid mapview disabling zoom in/out

I'm trying to disabling mapview zoom functionality by calling

map.setFocusable(false);

why this doesn't work and is there any way to do that

Upvotes: 0

Views: 1692

Answers (1)

Ismail Sahin
Ismail Sahin

Reputation: 2710

Finally I find a way

    public class MapActivity extends Activity{
        protected MapView mapView;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            mapView = (MapView) findViewById(R.id.map);

            mapView .setTileSource(TileSourceFactory.MAPNIK);
            MyOverlay myOverlay = new MyOverlay(getApplicationContext());


            //disable double tap
            appendOverlay(myOverlay);

            //do something here

            //enable double top
            removeOverlay(myOverlay);
    }
    protected void removerOverlay(Overlay overlay) {
        final OverlayManager mng = map.getOverlayManager();

        if(mng.contains(overlay)) {
                mng.remove(overlay);
        }

   }
    protected void appendOverlay(Overlay overlay) {
        final OverlayManager mng = map.getOverlayManager();

        if(!mng.contains(overlay)) {
                mng.add(overlay);
        }

   }

}

Here is the class to enable/disable double tap actually mapView.setFocusable(false) would not meet my need like this solution

public class MyOverlay extends Overlay{

    public MyOverlay(Context ctx) {
        super(ctx);
        this.mapView = mapView;
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void draw(Canvas arg0, MapView arg1, boolean arg2) {

    }

    @Override
    public boolean onDoubleTap(MotionEvent e, MapView mapView) {
            //here return true means that I handled double tap event no
            //one need to do anything for this event

            //if you do not do anything here double tap will be disable.
        return true;
    }
}

Upvotes: 1

Related Questions