how can i override default pinch zoom in osmdroid? - android

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

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.

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

Related

Lua: Simplest zoom button [Corona SDK]

What's the simplest zoom function featuring "+/-" button in Lua [Corona SDK]?
My point is to have button (2 buttons, + and -) that does not change its size while zooming and to have overally smooth zoom that allows you to scroll background when it is zoomed. I'm basically new to coding, so I'm having some trouble with handling that. I'm making my first project (piano app), so I'd like it to be simple, I have been searching how to do that long, but I still couldn't find any exact readable sample of code which I would be able to use. How about your ideas?
Thanks
I do not understood what you want to do. But if you want to zoom an image you can change the xScale and the yScale property of an object. And you should insert the image object into a scrollview object to scroalling.

Is it possible to move Zoom Controls to a different location on Screen in OSMdroid

I'm looking at moving default zoom controls of osmdroid to a different position. Is it possible to do this? If so, can anyone point me how?
I tried digging deep, through much of stackoverflow but no result. Or should I go with customizing by creating a custom zoom controls again for my app?
My intention is to relocate the already available zoom controls to a different place on screen.
You cannot relocate the MapView's integrated zoom control using the OSMDroid API.
The only way to do that without modifying the library's source code is to implement a FrameLayout over your MapView and that will include the controls you wish, where you wish. This also allows you to customize them (by showing a slider for example).
Once this done, you should ensure that MapView.setBuiltInZoomControls() is set to false.

Android maps setZoom(19)

I have one marker displayed and centered in my ItemizedOverlay in maps, currently I call setZoom(19).
But how can I control the zoom level? i.e. I want to zoom in as detailed as possible, but still showing the map in satellite mode clear.
I have noticed that if you zoom in to far everything just goes black. How can I zoom into the most detailed level without going to far?
Any help most appreciated...
Just use
setZoom(mapview.getMaxZoomLevel());
https://developers.google.com/maps/documentation/android/reference/com/google/android/maps/MapView
the solution is: look at the UiSettings in api v2 reference, there is the "setMaxZoomLevel" and "setMinZoomLevel".
Setup the max zoom level to the one that doesn't show a black screen (make some tests), then call the setZoom(mapview.getMaxZoomLevel());
Regards.

Zooming and directions services

I’m looking to force Google direction service to zoom to the final destination rather than show the entire route. Is this possible? If so how would you go about doing this? I would also like to remove the markers I set once the start and end locations have been set and the calculate route function is called is this possible? I don’t think any of the code will help it’s done in v3. I have been searching and found nothing related to the zoom issue. Can anyone please help…
Well this did help, now looking at it hough, i think maybe should have add my code. i'm going to try it in here first. I would like the "A" & "B" markers to stay i have built arrays for othere markers that i would like to suppress once the calculateroute function is handeld or have a button that turns them on and off that wont clear the map or add additional turn by turn directions.
First pass these options when intializing the directionsRenderer:
{suppressMarkers:true,preserveViewport:true}
...so you will not get markers and the map will not fit to the bounds of the route when rendering.
Then, after rendering the route( setDirections() ), call this:
directionsDisplay.setDirections(response);
//set the center of the map to the end of the route
map.setCenter(response.routes[0].legs[response.routes[0].legs.length-1].end_location);
//set the zoom to the desired value
(where directionsDisplay is the directionsRenderer-instance)

workaround for mapview overlays not pinch-zooming correctly

If a user does a "pinch zoom" on the map, my overlays don't properly size until the end. This has been noted in other posts, so i assume it is a known issue.
Problem is, my client finds it totally unacceptable, as I am tasked with making the android app look as good as the iphone version.
Is there any way to correct this, even if it is a horrible hack? For instance, can I subclass the mapview and handle drawing or override some other method?
The common solution is to not draw overlay during zoom animation.
UPDATED:
Sorry, I've confused zoom and move.
The problem with zoom is that you can't rely on zoom level. Instead you need to draw your overlay based on MapView.getProjection().

Categories

Resources