MKOverlay order problems
I have a MKMapView with two overlays: an MKPolyline and a subclass of MKOverlay which is simply defined as an overlay with CLLocationCoordinate2D of 0,0 and a bounding rect of MKMapRectWorld.
I'm trying to initially add the MKPolyline overlay and the custom overlay afterwards, in response to a user action. The custom overlay needs to go under the MKPolyline overlay.
I add the custom overlay with:
[map insertOverlay:customOverlay atIndex:0];
However it doesn't work. The cusomOverlay is added on top of the existing one. The overlay array from MKMapView claims they are ordered correctly though.
The only way I've been able to enforce the correct order is to remove the MKPolyline, add the custom overlay and then put the MKPolyline back in.
Am I missing something obvious?
EDIT code snippets:
the custom overlay class:
@interface TransparencyOverlay : NSObject <MKOverlay>
{}
@end
@implementation TransparencyOverlay
- (CLLocationCoordinate2D)coordinate
{
return CLLocationCoordinate2DMake(0, 0);
}
- (MKMapRect)boundingMapRect
{
re开发者_运维知识库turn MKMapRectWorld;
}
@end
the adding of the custom overlay:
- (void)onUserAction
{
transparencyOverlay_ = [TransparencyOverlay new];
[context_.map insertOverlay:transparencyOverlay_ atIndex:0];
}
the overlay view callback:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
// if overlay is MKOverlay return a MKPolylineView
// the construction of that view is kind of complex and can't fit in here
// else:
CLLocationCoordinate2D coords[4] = {CLLocationCoordinate2DMake(89, 180),
CLLocationCoordinate2DMake(89, -180),
CLLocationCoordinate2DMake(-89, -180),
CLLocationCoordinate2DMake(-89, 180)};
MKPolygon *poly = [MKPolygon polygonWithCoordinates:coords count:4];
MKPolygonView *view = [[MKPolygonView alloc] initWithPolygon:poly];
view.fillColor = some color
return [view autorelease];
}
The MKPolyline is added as an overlay on viewDidLoad (again, it's too much code to list here).
Did you try the insertOverlay:aboveOverlay: and nsertOverlay:belowOverlay: methods?
精彩评论