2017-03-09 12 views
0

저는 iOS 개발에 익숙하지 않고 MKOverlay을 사용하는 일부 코드를 iOS6에서 포팅하는 데 어려움을 겪고 있습니다.MKOverlay를 렌더링 할 때 MKOverlayRenderer가 잘리지 않지만 축소하여 고정됩니다.

오버레이 반경 또는 좌표가 변경되면 렌더러가 실시간으로 그에 따라 디스플레이를 업데이트해야합니다.

이 부분은 작동하지만 오버레이를 너무 많이 드래그하면 경계에 이르면 렌더링이 잘립니다. 이 문제에 대한 문서 나 도움을 찾을 수 없습니다. 너무 오버레이를 드래그 할 때

문제 : CircleOverlay 클래스에서

- (id)initWithOverlay:(id<MKOverlay>)overlay 
{ 
    self = [super initWithOverlay:overlay]; 
    if (self) { 
     CircleZone *bOverlay = (CircleZone *)overlay; 
     [RACObserve(bOverlay, coordinate) subscribeNext:^(id x) { 
      [self setNeedsDisplay]; 
     }]; 
     [RACObserve(bOverlay, radius) subscribeNext:^(id x) { 
      [self setNeedsDisplay]; 
     }]; 
    } 
    return self; 
} 

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context 
{ 
    CGRect rect = [self rectForMapRect:[self.overlay boundingMapRect]]; 

    CGContextSaveGState(context); 

    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); 
    CGContextSetFillColorSpace(context, colorSpace); 
    CGColorSpaceRelease(colorSpace); 

    CGContextSetBlendMode(context, kCGBlendModeCopy); 

    CGContextSetFillColor(context, color); 
    CGContextSetAllowsAntialiasing(context, YES); 

    // outline 
    { 
     CGContextSetAlpha(context, 0.8); 
     CGContextFillEllipseInRect(context, rect); 
    } 

    // red 
    { 
     CGContextSetAlpha(context, 0.5); 
     CGRect ellipseRect = CGRectInset(rect, 0.01 * rect.size.width/2, 0.01 * rect.size.height/2); 
     CGContextFillEllipseInRect(context, ellipseRect); 
    } 

    CGContextRestoreGState(cox); 
} 

: 다음 CircleOverlayRenderer 클래스에서

여기

- (MKMapRect)boundingMapRect 
{ 
    MKMapPoint center = MKMapPointForCoordinate(self.coordinate); 
    double mapPointsPerMeter = MKMapPointsPerMeterAtLatitude(self.coordinate.latitude); 
    double mapPointsRadius = _radius * mapPointsPerMeter; 

    return MKMapRectMake(center.x - mapPointsRadius, center.y - mapPointsRadius, 
         mapPointsRadius * 2.0, mapPointsRadius * 2.0); 
} 

은 제가 보는 문제의 일부 스크린 샷입니다 많이 : Problem when dragging overlay too much

반경을 변경할 때의 문제 : Problem when changing the radius

지도를 계속 확대하면 문제가 해결됩니다. 맵 타일을 새로 고친 후에 오버레이가 더 이상 잘리지 않습니다 ...

누구나 비슷한 문제가 있다면, 제발 저를 미치게합니다!

답변

0

예를 들어 radius 예를 보면 boundingMapRect의 자르기 방법을 알고 나를 의심하게 만듭니다. boundingMapRect 구현을 보면 MKMapPointsPerMeterAtLatitude (큰 지역을 볼 때 특히 그렇다)에 의존하는 것이 걱정됩니다. 이 기능은 예를 들어 다른 좌표에서 10 미터 떨어진 곳의 좌표를 알아 내려고 할 때 유용하지만 실제로는 너무 길어서 항상 잘 작동하지는 않습니다.

그 대신 동그라미가있는 곳의 MKCoordinateRegion을 얻는 것이 좋습니다. 그런 다음 MKMapRect으로 변환 할 수 있습니다. 당신이 우아하게 180도 경선의 교차점과 원이 포함 북극을 처리 확인이 함께 조정할해야합니다

- (MKMapRect)boundingMapRect { 
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(self.coordinate, _radius * 2, _radius * 2); 

    CLLocationCoordinate2D upperLeftCoordinate = CLLocationCoordinate2DMake(region.center.latitude - region.span.latitudeDelta/2, region.center.longitude - region.span.longitudeDelta/2); 
    CLLocationCoordinate2D lowerRightCoordinate = CLLocationCoordinate2DMake(region.center.latitude + region.span.latitudeDelta/2, region.center.longitude + region.span.longitudeDelta/2); 

    MKMapPoint upperLeft = MKMapPointForCoordinate(upperLeftCoordinate); 
    MKMapPoint lowerRight = MKMapPointForCoordinate(lowerRightCoordinate); 

    return MKMapRectMake(MIN(upperLeft.x, lowerRight.x), 
         MIN(upperLeft.y, lowerRight.y), 
         ABS(upperLeft.x - lowerRight.x), 
         ABS(upperLeft.y - lowerRight.y)); 
} 

,하지만 기본 개념을 설명 : 같은 가장 단순한 구현 보일 수 있습니다 가져 오기 서클에 대해 MKCoordinateRegion을 입력 한 다음 MKMapRect으로 변환하십시오.

+0

원래 'boundingMapRect'에 의해 클리핑의 영향을 받았지만 실제로 'boundingMapRect' 만 변경하면 원의 크기 만 변경됩니다. 불행히도, 내 질문에 2 링크로만 제한되어 있지만 오버레이를 끌면 실제로 동일한지도 타일을 따라 클리핑됩니다. 'MKMapPointsPerMeterAtLatitude'의 부정확성에 대해 알려 주셔서 감사하지만 다른 줌 배율에서 클리핑이 크게 달라지는 것은 규모에 영향을받지 않는 것 같습니다. (더 크게 확대하면 더 작은 반경으로 클립됩니다.) – kudos

+0

여전히 잘못된 boundingMapRect (크기가 조정되는 동안 크기가 잘못되었거나 드래그 중에 잘못된 위치가 됨)가 질문에 설명 된 것처럼 정확하게 나타납니다. 'boundingMapRect'가 너무 작 으면 전체 오버레이를 렌더링하지 않고 직선 자르기로 표시 할 수 있지만 반드시 그런 것은 아닙니다. 맵은 직사각형 타일을 사용하기 때문에 'boundingMapRect'를 사용하여 어느 타일을 다시 렌더링해야하는지 알 수 있습니다. 크기가 잘못되었거나 잘못된 위치에 있습니다 (또는 둘 다). – Rob

+0

@kudos - 제스처 중에지도가 렌더링되는 것처럼 보이지만 'boundingMapRect'는 아마도 구식 값을 반환합니다. 또는 'boundingMapRect'가 현재'MKMapRect'를 계산하지만 제스처 전체에서 이전 계산 된 모든 값의 합을 반환해야합니다. 그러나 나중에지도를 축소 할 때 오버레이가 올바르게 렌더링된다는 결론을 바탕으로 결론을 내릴 것을 주저합니다. 타일이 더 커질 수 있습니다. 그것은 많은 것들이 될 수 있습니다. 문제의 재현 가능한 예 없이는 말하기 어렵습니다. – Rob