我使用以下代码在 iPad 上进行了测试。
如果我像下面的代码一样添加 MyOverlay,即使在 drawMapRect 中什么都不做,MKMapView 加载默认地图图块也会变慢。
如果我从 MKMapView 中删除 MyOverlay,默认地图图块的加载会再次变快。
我想知道调用 drawMapRect 时在后台做了什么。
或者下面的代码对性能有什么问题?
[代码]
@implementation MyOverlay
-(id) init
{
self = [super init];
boundingMapRect = MKMapRectWorld;
boundingMapRect.origin.x += 1048600.0;
boundingMapRect.origin.y += 1048600.0;
coordinate = CLLocationCoordinate2DMake(0, 0);
return self;
}
...
@end
@implementation MyOverlayView
- (id) initWithOverlay:(id<MKOverlay>)overlay
{
self = [super initWithOverlay:overlay];
...
return self;
}
- (BOOL) canDrawMapRect:(MKMapRect) sm zoomScale:(MKZoomScale)zoomScale
{
return true;
}
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext: CGContextRef)context
{
return; // do nothing, but map loading become slower 'much'.
}
@end