1

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

Pratik Bhat
  • 7,166
  • 2
  • 35
  • 57

5 Answers5

3

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
        }
    }
NickT
  • 23,844
  • 11
  • 78
  • 121
  • That DummyOverlay is an entire "map sized" transparent overlay? I've been trying to detect a click on the marker of a DirectedLocationOverlay - does this mean I have to implement the "was the click inside the marker" myself? – David Doria Sep 16 '13 at 12:10
1

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.

Community
  • 1
  • 1
Enrique Diaz
  • 573
  • 4
  • 13
0

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

zIronManBox
  • 4,967
  • 6
  • 19
  • 35
0

you can use just add below line

mMapView.setMultiTouchControls(true);

mahsa k
  • 555
  • 6
  • 9
0

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

Pratik
  • 30,639
  • 18
  • 84
  • 159
  • well, i have implemented zoom controls, but double-tap has to be implemented coz its a tendency of any user , so cant neglect it for UX – Pratik Bhat Jan 04 '12 at 11:46
  • i understand what u r trying to say , but mapview already has a default double-tap implementation which i want to change – Pratik Bhat Jan 04 '12 at 11:57