Question

I Have created a guidance application which consist a map. This map is drawn dynamically using the data from the database.[rectangle coordinates] To draw the map i have used a View class and overriden the Ondraw method.

The problem is that i cant find a way to implement the zoom in functionality. I have already used Gesture Detector class to handle OnLongPress and the OnTouchEvent methods. I was thinking of the Pinch-to-Zoom-in functionality but have no idea of how to do it.

Looking forward for some great ideas. Thank you!

Classes extends

  • View
  • GesturDetector
Was it helpful?

Solution

Can you give us some more information about how you are drawing this dynamic map? For now, I'll make an assumption and run with it. If you are drawing shapes on a canvas you can point the canvas at a Bitmap to draw onto:

Bitmap myDynamicMapBitmap = new Bitmap(MAP_WIDTH, MAP_HEIGHT, Bitmap.Config.ARGB_8888);
mapCanvas.setBitmap(myDynamicMapBitmap);
// Draw your map on the canvas here

Now that you have a bitmap representation of your map, you could utilize this open source project, which is basically an adaptation of the built in Android photo gallery app that allows users to pan and zoom images:

ImageViewZoom on GitHub

I've used that project before for an app, and it works really well. You may need to tweak it some to get your desired behavior (for example disabling panning, since you didn't say you wanted that).

Then all you have really have to do is:

imageViewZoomInstance.setImageBitmap(myDynamicMapBitmap);

That view includes built-in pinch zooming. You'll probably want to merge it with your current View that you've created.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top