2011-08-02 10 views
2

MKMapView内にカスタムオーバーレイとして一連の同心円を描画しようとしています。パフォーマンス上の理由から、一連のMKCircleViewsを単に追加するのではなく、カスタム描画メソッドを実装する必要があることに注意してください。MKMapView内のカスタムコアグラフィックスオーバーレイ:ストローク楕円を表示できません

私は次のようなコードを書いています。円が塗りつぶされているのはなぜわかりませんが、空の円(ストロークアウトラインのみ)を描こうとすると何も見えません。

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context { 
// draw series of concentric circles 

// I have tried all manner of line widths 
CGContextSetLineWidth(context, 5.0); 

CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor); 
CGContextSetStrokeColorWithColor(context, [UIColor yellowColor].CGColor); 

float radius; 

for (int i = 1; i < self.numberOfRings+1; i++) { 

    // code to calculate the radius here using i 
    // but this is fine, set to 1000 metres 
    radius = 1000.0; 

    // centre of circles 
    CLLocationCoordinate2D centre = {latitude: self.latitude, longitude: self.longitude}; 

    // create circle of appropriate geographical dimensions 
    MKCircle *circle = [MKCircle circleWithCenterCoordinate:centre radius:radius]; 

    // the next two lines don't work, I don't see anything drawn 
    CGContextStrokeEllipseInRect(context, [self rectForMapRect:[circle boundingMapRect]]); 
    CGContextStrokePath(context); 

    // but the dimensions of the rect are ok, because I see the filled in rect (below) perfectly if I uncomment this next line 
    //  CGContextFillEllipseInRect(context, [self rectForMapRect:[circle boundingMapRect]]); 

    } 
} 

、地球上のどのような私は表示するようにストロークの画像を取得するために行うことになっていますしてください?

+1

最後に(しかし、これで私はこれを8時間も返せません)答えは描画の前に線の幅を設定する必要があるということです: 'CGContextSetLineWidth(context、0.5 * MKRoadWidthAtZoomScale(zoomScale)); ' – John

答えて

4

えーえは、最終的には....

答えは、線幅が、この前の図面のように設定する必要があるということである。「これが事実であるとすることができますなぜ

CGContextSetLineWidth(context, 0.5 * MKRoadWidthAtZoomScale(zoomScale)); 

わかりませんライン幅の値を設定するだけです。

関連する問題