我将这些方法放入 MKOverlayView 子类中,但我不明白为什么填充路径有效,以及为什么抚摸同一条路径不起作用......
- (id) init {
if (!(self = [super init])) return nil;
self.opaque = NO; // If not set, just black squares are drawn
return self;
}
- (void) drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
// CGRect rects[2] = {[self rectForMapRect:mapRect], [self rectForMapRect:self.country.boundingMapRect]};
// CGContextClipToRects(context, rects, 2);
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);
CGContextSetRGBFillColor(context, 1.0, 0.0, 1.0, 0.9);
CGContextSetLineWidth(context, 1.0);
for (MKPolygon* poly in self.polygons) {
CGPoint origin = [self pointForMapPoint:poly.points[0]];
CGContextMoveToPoint(context, origin.x, origin.y);
for (int i=1; i<poly.pointCount; i++) {
CGPoint point = [self pointForMapPoint:poly.points[i]];
CGContextAddLineToPoint(context, point.x, point.y);
}
//CGContextFillPath(context);
CGContextStrokePath(context);
}
}
-(BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale {
return YES;
}