views:

651

answers:

3

is there a way to update (i.e. moving around) a MKOverlay that is already added to the MKMapView. Removing a old one and adding a new one is terrible (slow).

i.e i would like to trigger the background function that is calling this function when an overlay moves on the screen: - (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id )overlay

(with MKAnnotions its a little better i think, but i cant use MKPolyline, MKPolygon, etc. and the whole information is reduced to a single point)

A: 

MKOverlayView has the following methods which force MapKit to re-render the given mapRect:

- (void)setNeedsDisplayInMapRect:(MKMapRect)mapRect

- (void)setNeedsDisplayInMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale

If you’re using a timer (or periodical HTTP request or some sort of other method for determining that your overlay should be updated), calling one of the above methods on the overlayView will cause it to re-render that spot on the map (i.e. -canDrawMapRect:zoomScale: will be called again, and then -drawMapRect:zoomScale:inContext: will be called if the former returns YES).


Update:

If you’re not sure what mapRect you need to re-render, you might be able to use the MKMapRectWorld constant as the mapRect — which I believe would cause the overlay across the entire map to reload (once visible).

Mike Tigas
A: 

I have the same problem. I want to change (or move) the position of MKOverlay (in face it is MKCircleOverlay). Anyone can show me the tip or sample code to do this ?

I have tried the above way using setNeedsDisplayInMapRect. But it does not work. I do not know why ?

Basically is it possible to move the position or resize the MKOverlay ?

Thanks in Advance.

A: 

I actually had to force the overlay view to invalidate the path, to clear out the old path before setting up a new one. [polygonView invalidatePath]. Telling the map view that it needs a display refresh was insufficient for me.

Greg Combs