Pratik Bhat
Pratik Bhat

Reputation: 7614

how can i implement my own double-tap in mapview?

I have been working on an offline map using OSMdroid

I have map tiles of two zoom levels namely 12 and 15

Now the usual double tap zooms the mapview by 1 level

What i m trying to do is to setZoomLevel() as 15 after the user double taps on the map,

Is it possible?

I tried using onGestureListener , but somehow it is not working

Any hint or clues in that direction or sample codes would be a big help , Thanks

Upvotes: 1

Views: 2404

Answers (5)

mahsa k
mahsa k

Reputation: 655

you can use just add below line

mMapView.setMultiTouchControls(true);

Upvotes: 0

zIronManBox
zIronManBox

Reputation: 5067

In the latest OSMdroid library 4.0 has inbuilt automatic double tap zoom in. But nothing is better than having a zoom control.

Upvotes: 0

NickT
NickT

Reputation: 23873

I had a similar requirement with the Osmdroid MapView, in that I didn't want it to do the 'centre on the double tapped location and zoom in' default functionality. I wanted it to pop up a Toast. In my case I had an overlay on top of the MapView, so I just had the overlay consume the double tap in its onDoubleTap method. For your purposes you could just add an overlay which draws nothing but has its own double tap functionality.

So at the end of your onCreate, you could add the overlay. This little app seems to demonstrate what you want - (you'll need to add conditional code for checking zoom level and other tinkering):

public class OsmdroidDemoMap extends Activity {

    private MapView         mMapView;
    private MapController   mMapController;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.osm_main);
        mMapView = (MapView) findViewById(R.id.mapview);
        mMapView.setTileSource(TileSourceFactory.MAPNIK);
        mMapView.setBuiltInZoomControls(true);
        mMapController = mMapView.getController();
        mMapController.setZoom(13);
        GeoPoint gPt = new GeoPoint(51500000, -150000);
        mMapController.setCenter(gPt);
        DummyOverlay dumOverlay = new DummyOverlay(this);
        List<Overlay> listOfOverlays = mMapView.getOverlays();
        listOfOverlays.clear();
        listOfOverlays.add(dumOverlay);
    }

    public class DummyOverlay extends org.osmdroid.views.overlay.Overlay {

        public DummyOverlay(Context ctx) {
            super(ctx); // TODO Auto-generated constructor stub
        }

        @Override
        protected void draw(Canvas c, MapView osmv, boolean shadow) {}

        @Override
        public boolean onDoubleTap(MotionEvent e, MapView mapView) {
            // This stops the 'jump to, and zoom in' of the default behaviour
            int zoomLevel = mMapView.getZoomLevel();
            mMapController.setZoom(zoomLevel + 3);
            return true;// This stops the double tap being passed on to the mapview
        }
    }

Upvotes: 3

Enrique Diaz
Enrique Diaz

Reputation: 573

If you need to manage the double-tap in an MapView, i suggest you to check this thread:

android maps: How to Long Click a Map?

You can see my answer and how i adapted mapview-overlay-manager.

Upvotes: 1

Pratik
Pratik

Reputation: 30855

you can override the zoom control with its event, for that you need to define into the xml layout or you get the zoom control from the mapview

ZoomControls zoomControls = (ZoomControls)findViewById(R.id.zoomControl);

View zoomOut = zoomControls.getChildAt(0);
zoomOut.setBackgroundDrawable(getResources().getDrawable(R.drawable.zoom_out_icon));
zoomOut.setPadding(5, 5, 5, 5);

View zoomIn = zoomControls.getChildAt(1);
zoomIn.setBackgroundDrawable(getResources().getDrawable(R.drawable.zoom_in_icon));
zoomIn.setPadding(5, 5, 5, 5);

zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mc.zoomIn();
            mapView.invalidate();
        }
});
zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mc.zoomOut();
            mapView.invalidate();
        }
});

now you can implement your own zoom control

Upvotes: 0

Related Questions