Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 带有一个MKOverlayPathView的MKMapView会导致地图模糊_Objective C_Ios_Mkmapview_Mapkit_Mkoverlay - Fatal编程技术网

Objective c 带有一个MKOverlayPathView的MKMapView会导致地图模糊

Objective c 带有一个MKOverlayPathView的MKMapView会导致地图模糊,objective-c,ios,mkmapview,mapkit,mkoverlay,Objective C,Ios,Mkmapview,Mapkit,Mkoverlay,有人能回答以下两个问题中的任何一个吗 1) 如果我在MKOverlayPathView中根据覆盖对象的zoomScale动态调整覆盖对象的大小,我如何确保MKOverlay协议支持类在不知道zoomScale是什么的情况下返回正确的boundingMapRect 2) boundingMapRect太小有什么副作用 原创…… 我创建了一个带有一个MKOverlayPathView的MKMapView。将覆盖添加到地图中后,平移和缩放会使基础地图的各个部分变得模糊,有时甚至无法下载。叠加视图本身很

有人能回答以下两个问题中的任何一个吗

1) 如果我在MKOverlayPathView中根据覆盖对象的zoomScale动态调整覆盖对象的大小,我如何确保MKOverlay协议支持类在不知道zoomScale是什么的情况下返回正确的boundingMapRect

2) boundingMapRect太小有什么副作用

原创……

我创建了一个带有一个MKOverlayPathView的MKMapView。将覆盖添加到地图中后,平移和缩放会使基础地图的各个部分变得模糊,有时甚至无法下载。叠加视图本身很好,并且处于焦点位置,地图数据模糊(从上一个缩放级别)

如果不添加覆盖层,一切正常

MKOverlayPathView是子类化的,它有一个点和大小数组,它使用这些点和大小将填充圆绘制到单个覆盖中进行显示。边界矩形由所有点的并集形成,这些点占它们将生成的圆的半径

那么我错过了什么?是绘图过程、边界矩形还是其他什么

示例代码:

MapViewController代码

- (MKOverlayView *)mapView:(MKMapView *)map viewForOverlay:(id <MKOverlay>)overlay
{
    if ([overlay isKindOfClass:[MultiCluster class]]) {
        MKMultiClusterView *multiclusterView = [[MKMultiClusterView alloc] initWithOverlay:overlay];
        return multiclusterView;
    }

    return nil;
}
MKMultiClusterView.m

@implementation MultiCluster

@synthesize clusters = _clusters;

- (id)initWithClusters:(NSArray *)clusters {
    if (self = [super init]) {
        _clusters = [clusters copy];

        NSUInteger clusterCount = [_clusters count];
        if (clusterCount) {
            _boundingMapRect = [[_clusters objectAtIndex:0] boundingMapRect];
            NSUInteger i;
            for (i = 1; i < clusterCount; i++) {
                _boundingMapRect = MKMapRectUnion(_boundingMapRect, [[_clusters objectAtIndex:i] boundingMapRect]);
            }
        }
    }

    return self;
}

- (void)setClusters:(NSArray *)clusters {
    _clusters = [clusters copy];
    NSUInteger clusterCount = [_clusters count];
    if (clusterCount) {
        _boundingMapRect = [[_clusters objectAtIndex:0] boundingMapRect];
        NSUInteger i;
        for (i = 1; i < clusterCount; i++) {
            _boundingMapRect = MKMapRectUnion(_boundingMapRect, [[_clusters objectAtIndex:i] boundingMapRect]);
        }
    }
}

- (MKMapRect)boundingMapRect {
    return _boundingMapRect;
}

- (CLLocationCoordinate2D)coordinate {
    return MKCoordinateForMapPoint(MKMapPointMake(MKMapRectGetMidX(_boundingMapRect), MKMapRectGetMidY(_boundingMapRect)));
}

@end
@implementation MKMultiClusterView

// Create a table of possible colors to draw a grid cell with
- (void)initColors
{
    CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
    colors = malloc(sizeof(CGColorRef) * NUM_COLORS);
    int i = 0;
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ .588, .294, .78, OA }); // 1.00
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ .784, .471, .82, OA }); // 0.77
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ 1, 0, 0, OA }); // 0.59
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ 1, .392, 0, OA }); // 0.46
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ 1, .392, 0, OA }); // 0.35
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ 1, .784, 0, OA }); // 0.27
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ 1, 1, .5, OA }); // 0.21
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ .745, .941, .467, OA }); // 0.16
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ .122, 1, .31, OA }); // 0.12
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ .588, 1, .941, OA }); // 0.10
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ .784, 1, 1, OA }); // 0.08
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ .843, 1, 1, OA }); // 0.06
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ .902, 1, 1, OA }); // 0.04
    colors[i] = CGColorCreate(rgb, (CGFloat[]){ .784, .784, .784, OA }); // 0.03
    CGColorSpaceRelease(rgb);
}

// Look up a color in the table of colors for a peak ground acceleration
- (CGColorRef)colorForSize:(int)value
{
    if (value > 3000) return colors[0];
    if (value > 2500) return colors[1];
    if (value > 2000) return colors[2];
    if (value > 1500) return colors[3];
    if (value > 1000) return colors[4];
    if (value > 540) return colors[5];
    if (value > 480) return colors[6];
    if (value > 420) return colors[7];
    if (value > 360) return colors[8];
    if (value > 300) return colors[9];
    if (value > 240) return colors[10];
    if (value > 180) return colors[11];
    if (value > 120) return colors[12];
    if (value <= 120) return colors[13];
    return NULL;
}

- (id)initWithOverlay:(id<MKOverlay>)overlay {
    if (self = [super initWithOverlay:overlay])
    {
        [self initColors];
    }
    return self;
}

- (CGPathRef)createPath:(Cluster *)cluster zoomScale:(MKZoomScale)zoomScale {
    CGMutablePathRef path = CGPathCreateMutable();
    // Calculate radius for circle in map pixels.    
    double fudge = 2;
    double viewWidth = 320;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
        fudge = 5;
        viewWidth = 768;
    }
    // Radius of circle in pixels.
    int radiusPixels = 10 + (fudge * log([cluster.members count]));
    fudge = 1/zoomScale;
    double radiusPoints = radiusPixels * fudge;
    double diameterPoints = radiusPoints * 2;

    // Center of circle in map points.
    CGPoint relativePoint = [self pointForMapPoint:MKMapPointForCoordinate(cluster.coordinate)];
    CGRect ellipseRect = CGRectMake(relativePoint.x - radiusPoints, 
                                    relativePoint.y - radiusPoints, 
                                    10000, 
                                    10000);
    CGPathAddEllipseInRect(path, NULL, ellipseRect);

    return path;
}

- (void)drawMapRect:(MKMapRect)mapRect
          zoomScale:(MKZoomScale)zoomScale
          inContext:(CGContextRef)context
{
    MultiCluster *multiCluster = (MultiCluster *)self.overlay;
    for (Cluster *cluster in multiCluster.clusters) {
        CGPathRef path = [self createPath:cluster zoomScale:zoomScale];
        if (path) {
            self.fillColor = [UIColor colorWithCGColor:[self colorForSize:[cluster.members count]]];
            [self applyFillPropertiesToContext:context atZoomScale:zoomScale];
            CGContextBeginPath(context);
            CGContextAddPath(context, path);
            CGContextDrawPath(context, kCGPathEOFill);
            CGPathRelease(path);
        }
    }
}

@end
@implementation MKMultiClusterView
//创建一个可能的颜色表以绘制网格单元
-(空)初始颜色
{
CGColorSpaceRef rgb=CGColorSpaceCreateDeviceRGB();
颜色=malloc(sizeof(CGColorRef)*NUM_颜色);
int i=0;
颜色[i++]=CGColorCreate(rgb,(CGFloat[]){.588,294,78,OA});//1.00
颜色[i++]=CGColorCreate(rgb,(CGFloat[]){.784.471.82,OA};//0.77
颜色[i++]=CGColorCreate(rgb,(CGFloat[]){1,0,0,OA};//0.59
颜色[i++]=CGColorCreate(rgb,(CGFloat[]){1,392,0,OA};//0.46
颜色[i++]=CGColorCreate(rgb,(CGFloat[]){1,392,0,OA};//0.35
颜色[i++]=CGColorCreate(rgb,(CGFloat[]){1,784,0,OA};//0.27
颜色[i++]=CGColorCreate(rgb,(CGFloat[]){1,1,5,OA};//0.21
颜色[i++]=CGColorCreate(rgb,(CGFloat[]){.745.941.467,OA});//0.16
颜色[i++]=CGColorCreate(rgb,(CGFloat[]){.122,1,31,OA};//0.12
颜色[i++]=CGColorCreate(rgb,(CGFloat[]){.588,1,941,OA});//0.10
颜色[i++]=CGColorCreate(rgb,(CGFloat[]){.784,1,1,OA};//0.08
颜色[i++]=CGColorCreate(rgb,(CGFloat[]){.843,1,1,OA};//0.06
颜色[i++]=CGColorCreate(rgb,(CGFloat[]){.902,1,1,OA};//0.04
颜色[i]=CGColorCreate(rgb,(CGFloat[]){.784,784,784,OA});//0.03
CGB酶(rgb);
}
//在颜色表中查找峰值地面加速度的颜色
-(CGColorRef)colorForSize:(int)值
{
如果(值>3000)返回颜色[0];
如果(值>2500)返回颜色[1];
如果(值>2000)返回颜色[2];
如果(值>1500)返回颜色[3];
如果(值>1000)返回颜色[4];
如果(值>540)返回颜色[5];
如果(值>480)返回颜色[6];
如果(值>420)返回颜色[7];
如果(值>360)返回颜色[8];
如果(值>300)返回颜色[9];
如果(值>240)返回颜色[10];
如果(值>180)返回颜色[11];
如果(值>120)返回颜色[12];

如果(值您是否尝试将alpha组件从单个圆移动到层本身?

是,这解决了测试代码中的问题,但在项目本身中没有完全解决。尽管速度更快:/
@interface MKMultiClusterView : MKOverlayPathView {
    CGColorRef *colors;
}

@end
@implementation MKMultiClusterView

// Create a table of possible colors to draw a grid cell with
- (void)initColors
{
    CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
    colors = malloc(sizeof(CGColorRef) * NUM_COLORS);
    int i = 0;
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ .588, .294, .78, OA }); // 1.00
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ .784, .471, .82, OA }); // 0.77
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ 1, 0, 0, OA }); // 0.59
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ 1, .392, 0, OA }); // 0.46
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ 1, .392, 0, OA }); // 0.35
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ 1, .784, 0, OA }); // 0.27
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ 1, 1, .5, OA }); // 0.21
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ .745, .941, .467, OA }); // 0.16
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ .122, 1, .31, OA }); // 0.12
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ .588, 1, .941, OA }); // 0.10
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ .784, 1, 1, OA }); // 0.08
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ .843, 1, 1, OA }); // 0.06
    colors[i++] = CGColorCreate(rgb, (CGFloat[]){ .902, 1, 1, OA }); // 0.04
    colors[i] = CGColorCreate(rgb, (CGFloat[]){ .784, .784, .784, OA }); // 0.03
    CGColorSpaceRelease(rgb);
}

// Look up a color in the table of colors for a peak ground acceleration
- (CGColorRef)colorForSize:(int)value
{
    if (value > 3000) return colors[0];
    if (value > 2500) return colors[1];
    if (value > 2000) return colors[2];
    if (value > 1500) return colors[3];
    if (value > 1000) return colors[4];
    if (value > 540) return colors[5];
    if (value > 480) return colors[6];
    if (value > 420) return colors[7];
    if (value > 360) return colors[8];
    if (value > 300) return colors[9];
    if (value > 240) return colors[10];
    if (value > 180) return colors[11];
    if (value > 120) return colors[12];
    if (value <= 120) return colors[13];
    return NULL;
}

- (id)initWithOverlay:(id<MKOverlay>)overlay {
    if (self = [super initWithOverlay:overlay])
    {
        [self initColors];
    }
    return self;
}

- (CGPathRef)createPath:(Cluster *)cluster zoomScale:(MKZoomScale)zoomScale {
    CGMutablePathRef path = CGPathCreateMutable();
    // Calculate radius for circle in map pixels.    
    double fudge = 2;
    double viewWidth = 320;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
        fudge = 5;
        viewWidth = 768;
    }
    // Radius of circle in pixels.
    int radiusPixels = 10 + (fudge * log([cluster.members count]));
    fudge = 1/zoomScale;
    double radiusPoints = radiusPixels * fudge;
    double diameterPoints = radiusPoints * 2;

    // Center of circle in map points.
    CGPoint relativePoint = [self pointForMapPoint:MKMapPointForCoordinate(cluster.coordinate)];
    CGRect ellipseRect = CGRectMake(relativePoint.x - radiusPoints, 
                                    relativePoint.y - radiusPoints, 
                                    10000, 
                                    10000);
    CGPathAddEllipseInRect(path, NULL, ellipseRect);

    return path;
}

- (void)drawMapRect:(MKMapRect)mapRect
          zoomScale:(MKZoomScale)zoomScale
          inContext:(CGContextRef)context
{
    MultiCluster *multiCluster = (MultiCluster *)self.overlay;
    for (Cluster *cluster in multiCluster.clusters) {
        CGPathRef path = [self createPath:cluster zoomScale:zoomScale];
        if (path) {
            self.fillColor = [UIColor colorWithCGColor:[self colorForSize:[cluster.members count]]];
            [self applyFillPropertiesToContext:context atZoomScale:zoomScale];
            CGContextBeginPath(context);
            CGContextAddPath(context, path);
            CGContextDrawPath(context, kCGPathEOFill);
            CGPathRelease(path);
        }
    }
}

@end