Pratik Bhat
Pratik Bhat

Reputation: 7614

how can i override default pinch zoom in osmdroid?

I m using Osmdroid to create an offline map

Now, i want to implement my own pinch to zoom functionality for offline maps

When user uses pinch, i would like to zoom in/ zoom out to only a particular zoom level and not increment/ decrement zoom level by 1

Is there a way to do it? how can i go about this ?

P.S : yes, there are zoom controls, but i would like to make zooming feature more intuitive

Thanks

Upvotes: 0

Views: 1386

Answers (2)

digerati32
digerati32

Reputation: 663

I dealt with a similar question here, and provided the code for custom functionality on pinch. So basically, expanding on what I had in the answer, just basically do:

int currentZoomLevel = mOsmv.getController().getZoomLevel();
if (currentZoomLevel < (mOsmv.getControler().getMaxZoomLevel()) - 2) 
    mOsmv.getController().setZoomLevel(currentZoomLevel + 2);

That is just an example of increasing the zoom level by 2, instead of just 1. I also wrote the code above from memory, so I'm not 100% sure if you call getController() to get the current and maximum zoom level, but I'm pretty sure that's it. mOsmv, just in case you don't get it, is an instance of the osmdroid map.

Upvotes: 1

Ifor
Ifor

Reputation: 2835

I think the way to do this will be to extend MapView.

Overriding setZoomLevel looks like one option but I don't think it will work. As I belive the code needs to be writen in a this.setZoomLevel style which it is not consistantly doing.

I think you should be able to override selectObject which looks like the place where a pinch trigers a call setZoomLevel

You will need to check the source code to see how to make the nessasary modifications

Upvotes: 1

Related Questions