2011-08-02 1 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

Ahhhh, 마침내 (그렇지만 나에게 이것을 8 시간 동안 대답하지 않을 것입니다.) 대답은 그리기 전에 선 너비를 이렇게 설정해야한다는 것입니다. CGContextSetLineWidth (context, 0.5 * MKRoadWidthAtZoomScale (zoomScale)); – John

답변

4

아아는 마지막으로 ....

대답은 라인 폭이 이전에 그림처럼 설정해야한다는 것입니다 : '이 경우 당신이 할 수있는 이유

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

확실하지 않음 단지 선 너비에 대한 값을 설정하지 마십시오.

관련 문제