Itsik
Itsik

Reputation: 3930

Weird Overlay draw behaviour when zooming in the MapView

I've extended Overlay and implemented draw() in order to draw some stuff onto the map. When zooming is done through mapController.zoomIn() (called when doubleTapping the map), the overlay is drawn properly onto the map.

But whenever I zoom in/out with the built in zoom controller, the overlay is not drawn properly and panning the map is needed to get the overlay refreshed.

Upvotes: 18

Views: 2026

Answers (6)

RobinHood
RobinHood

Reputation: 10969

    mapView.setBuiltInZoomControls(true);
    mapView.getController().setZoom(15);

    controller = mapView.getController();




    mapOverlays = mapView.getOverlays();

this.

Upvotes: 1

Rajeswari Kotikalapudi
Rajeswari Kotikalapudi

Reputation: 592

public class MyMap_MapControllerActivity extends MapActivity {

    private MapView mapView;
    //private MapController mapController;
     MapView.LayoutParams lp;
     int y = 10;
        int x = 10;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mapView = (MapView)findViewById(R.id.map_view);
        mapView.setSatellite(true);
        mapView.setStreetView(true);
        mapView.setTraffic(true);



    GeoPoint center = mapView.getMapCenter();
    int latSpan = mapView.getLatitudeSpan();
    int longSpan = mapView.getLongitudeSpan();




    lp = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT,
    MapView.LayoutParams.WRAP_CONTENT,
    x, y,
    MapView.LayoutParams.TOP_LEFT);
    View zoomControls = mapView.getZoomControls();
    mapView.addView(zoomControls, lp);
    mapView.displayZoomControls(true);
    }



    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
    }

Upvotes: 1

Droid Chris
Droid Chris

Reputation: 3783

I created a lot of custom drawables in my map view. Unfortunately the drawables expanded when zoomed out (when they should have shrunk). To get around this, I monitored the user zooming in or out in a runnable. If the zoom changed, I redrew the map. Here is my code:

private Runnable zoomChecker = new Runnable()
{
    public void run()
    {
        //check for updates
        if((mLastUpdate>UPDATE_INTERVAL)&&(!DISPLAY_RED_CIRCLE)&&(!DISPLAY_ROUTE_LAYOUT)){
            updateRouteInformation();
            mLastUpdate = 0; 
        }else{
            mLastUpdate += 200;
        }
        //check for zoom level changes
        int testZoomLevel = mMapView.getZoomLevel();
        if((testZoomLevel!=mZoomLevel)&&(DISPLAY_RED_CIRCLE)){
            //set that user is zooming 
            mStillZooming = true;

            //remove overlays and clear map
            removeOverlayItems();       
            mMapView.invalidate();

            //set zoom level as same
            mZoomLevel = testZoomLevel;
        }
        if((testZoomLevel==mZoomLevel)&&(mStillZooming)){
            displayDriverBoundaries(MAP_DRIVER);
        }
        handler.removeCallbacks(zoomChecker); // remove the old callback
        handler.postDelayed(zoomChecker, zoomCheckingDelay); // register a new one
    }
};

Upvotes: 1

johann316
johann316

Reputation: 63

I've found in my mapview app that I want to track my own position, so in the code I set a geopoint to my current gps position,then I use the following code to move the map center to that point and found that it works wonderfully:

MapController mc = mapView.getController(); 
               mc.animateTo(point);

You could create a function which zooms and animates to the overlay point. Hope that helps.

Upvotes: 1

Yilmaz Guleryuz
Yilmaz Guleryuz

Reputation: 9755

I've been using zoom controllers with no problem at all. even having drawn multi layers on the map and zoom in/out has no bad effect at all.

I suggest to use as below

mapController = mapView.getController();
mapController.zoomIn();// or .zoomOut()

instead of using setZoom(XX) please use zoomIn() / zoomOut() which makes zooming smoother, this may help making it work better esp with multiple overlays.

Upvotes: 1

Droidand
Droidand

Reputation: 176

You can use zoom controller and get rid of this problem.. (ex: zoomView = (LinearLayout) mapView.getZoomControls(); )

check with this link

http://developer.android.com/reference/android/widget/ZoomButtonsController.html

Upvotes: 1

Related Questions