views:

457

answers:

3

I'm trying to draw a route onto my MapView. I've extended Overlay and implemented the draw() method. The route is displayed properly, although while debugging, I added a breakpoint on draw(), and noticed it is being called constantly.

I only want it to be re-drawn if someone moves the map or zooms (the draw take into account these changes when drawing the route) What can cause this ?

A: 

i think the draw method is called repeatedly because the of the background being redrawn constantly. try setting the "MapView.ReticleDrawMode" to DRAW_RETICLE_UNDER. This basically tells the mapView to draw the reticle under the overlays. So overlay's draw method will not be called when the background is recalled. this fixed the issue for me.

for more info, look here: MapView Api

Santoash
A: 

There are 2 draw methods that can be overridden.

void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow)

Draw the overlay over the map.

boolean draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow, long when)
Draw call for animated overlays.

I overrided the second one. After changing the to the first method it worked out.

Itsik
A: 

I got tripped up when I didn't realize that the draw method get's called not only any markers that you draw, BUT also the shadow of those markers. So as an example, if you have two markers and you have shadows set to true (which is the default setting), then you'll have the draw method being called 4 times (once for each marker, once for each shadow of the markers)!

Theo