MKOverlayRenderer通过缩放iOS剪切和模糊

时间:2017-05-30 13:38:34

标签: ios objective-c mapkit

我正在努力解决与 MapKit 相关的问题。

我根据来自服务器的地理围栏数据创建 MKPolygon 列表。

+ (MKPolygon *)polygonFromPoints:(NSArray *)points interiorPolygons:(NSArray *)polygons{

     NSInteger numberOfCoordinates = [points count];
     CLLocationCoordinate2D *polygonPoints = malloc(numberOfCoordinates * sizeof(CLLocationCoordinate2D));

     NSInteger index = 0;
     for (NSArray *pointArray in points) {
          polygonPoints[index] = CLLocationCoordinate2DMake([pointArray[1] floatValue], [pointArray[0] floatValue]);
          index++;
     }

     MKPolygon *polygon;
     if (polygons) {
        polygon = [MKPolygon polygonWithCoordinates:polygonPoints count:numberOfCoordinates interiorPolygons:polygons];
     } else {
        polygon = [MKPolygon polygonWithCoordinates:polygonPoints count:numberOfCoordinates];
     }

     free(polygonPoints);
     return polygon;  }

并将其作为MKOverlayRender

添加到地图中
- (MKOverlayRenderer *) mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay{

    if([overlay isKindOfClass: [MKCircle class]]){
        MKCircleRenderer *circleRender = [[MKCircleRenderer alloc] initWithCircle:(MKCircle *)overlay];
        circleRender.fillColor = [ [Common colorWithHexString:BlueGeoFence] colorWithAlphaComponent:0.3];

        return circleRender;
    }else if([overlay isKindOfClass: [MKPolygon class]]){

        MKPolygonRenderer *polygonRenderer = [[MKPolygonRenderer alloc] initWithPolygon:(MKPolygon *)overlay];
        polygonRenderer.fillColor = [ [Common colorWithHexString:BlueGeoFence] colorWithAlphaComponent:0.3];

        return polygonRenderer;
    }

    return nil;
}

然而,当我放大或更改地图的位置时,叠加层剪切并具有某种模糊效果

enter image description here

enter image description here

知道如何解决这个问题吗?

提前致谢

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。问题的根源在于MKPolygon是使用内部多边形创建的,而内部多边形实际上并不是内部多边形。检查数据并确保内部多边形坐标实际上在较大多边形的边界内。