Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change zoom controls in a MapView

I would like to change the predefined style of the zoom controls in my application to appear like the new zoom controls in the google maps application. See below:

enter image description here

How can I do it? I have been looking around and I haven't found anything.

Thanks in advance.

like image 579
jalv1039 Avatar asked Jan 18 '12 15:01

jalv1039


2 Answers

You should have four image drawables namely:

  1. Zoom in (+) enable/disable
  2. Zoom out (-) enable/disable

Put them in MapView layout an ImageView or Button with background image as the above drawables.

Then you should assign onClickListeners like:

zoomIn.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        mapView.getController.zoomIn()
        checkzoom();
    }
});

zoomOut.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        mapView.getController.zoomOut()
        checkzoom();
    }
});

public void checkzoom() {
    if(mapView.getZoomLevel()==1) // dont know if 0 or 1, just wrote it
    {
        zoomOut.setEnabled(false);
        // or u can change drawable and disable click
    }
    if(mapView.getZoomLevel()==18) {
        zoomIn.setEnabled(false);
        // or u can change drawable and disable click
    }
}

EDIT: zoom inzoom out

like image 120
Pratik Bhat Avatar answered Sep 30 '22 05:09

Pratik Bhat


I solved the problem this way: disabled built in zoom controls (setBuiltInZoomControls(false)), added my own buttons to UI and added handlers for click on button events.

like image 43
Sergey Glotov Avatar answered Sep 30 '22 06:09

Sergey Glotov