Objective c 自定义MKOverlayView/未修改的MKPolygonView在某些缩放级别进行剪裁
当有多个覆盖添加到地图时,自定义的MKOVERAYVIEW和标准的MKPolygonView都会在特定的缩放级别进行剪裁,这是我遇到的一个问题 一些意见:Objective c 自定义MKOverlayView/未修改的MKPolygonView在某些缩放级别进行剪裁,objective-c,ios,mapkit,Objective C,Ios,Mapkit,当有多个覆盖添加到地图时,自定义的MKOVERAYVIEW和标准的MKPolygonView都会在特定的缩放级别进行剪裁,这是我遇到的一个问题 一些意见: 无论我是否使用自定义MKOverlayView或返回具有相同多边形的MKPolygonView,都会发生这种情况 如果我只画一个叠加,这个问题就不会发生 并非所有覆盖层都会出现这种情况,只有部分覆盖层会出现这种情况 就代码而言:这会将覆盖添加到NSMutableArray(borderOverlays)中,然后在其他地方访问该数组以加
- 无论我是否使用自定义MKOverlayView或返回具有相同多边形的MKPolygonView,都会发生这种情况
- 如果我只画一个叠加,这个问题就不会发生
- 并非所有覆盖层都会出现这种情况,只有部分覆盖层会出现这种情况
CLLocationCoordinate2D mbrMin = CLLocationCoordinate2DMake(minY, minX);
CLLocationCoordinate2D mbrMax = CLLocationCoordinate2DMake(maxY, maxX);
MKMapPoint minPoint = MKMapPointForCoordinate(mbrMin);
MKMapPoint maxPoint = MKMapPointForCoordinate(mbrMax);
MKMapSize size = MKMapSizeMake(maxPoint.x - minPoint.x, maxPoint.y - minPoint.y);
MKMapRect rect = MKMapRectMake(minPoint.x, minPoint.y, size.width, size.height);
if ( spans180 ) {
rect = MKMapRectMake(minPoint.x, minPoint.y, MKMapSizeWorld.width * 2, size.height);
}
CustomMKOverlay* overlay = [[CustomMKOverlay alloc] initWithPolygon:polygon withBoundingMapRect:rect];
[borderOverlays addObject:overlay];
覆盖通过以下方式添加到地图:
[mapView addOverlay:overlay];
viewForOverlay:
- (MKOverlayView *)mapView:(MKMapView*)aMapView viewForOverlay:(id<MKOverlay>)overlay
{
if ( [overlay isKindOfClass:[CustomMKOverlay class]] ) {
/* Note: the behaviour if this chunk is not commented is the exact same as below.
CustomMKOverlayView* overlayView = [[[CustomMKOverlayView alloc] initWithOverlay:overlay withMapView:aMapView] autorelease];
[borderViews addObject:overlayView];
return overlayView; */
MKPolygonView* view = [[[MKPolygonView alloc] initWithPolygon:((CustomMKOverlay*)overlay).polygon] autorelease];
view.fillColor = [((CustomMKOverlay*)overlay).colour colorWithAlphaComponent:0.5f];
view.lineWidth = 5.0f;
view.strokeColor = [UIColor blackColor];
[borderViews addObject:view];
return view;
}
}
只需说一句,我在这一点上有点不知所措-这几乎就像正在加载的缩放平铺画在覆盖上一样。我已经列举了关于TileMap和HazardMap的各种示例,但是由于我没有加载自己的地图分幅,它们没有多大帮助
我可能错过了一些非常明显的东西。任何帮助都将不胜感激。如果有必要,我很乐意提供更多的代码/上下文。似乎罪魁祸首是:
CLLocationCoordinate2D mbrMin = CLLocationCoordinate2DMake(minY, minX);
CLLocationCoordinate2D mbrMax = CLLocationCoordinate2DMake(maxY, maxX);
MKOverlays的边界矩形显然需要基于边界区域的西北/东南坐标,而不是西南/东北坐标(ESRI shapefile存储其边界坐标的格式)。将有问题的代码更改为:
CLLocationCoordinate2D mbrMin = CLLocationCoordinate2DMake(maxY, minX);
CLLocationCoordinate2D mbrMax = CLLocationCoordinate2DMake(minY, maxX);
似乎可以解决缩放和奇怪轮廓异常的所有问题。我希望这对将来遇到这个问题的任何人都有帮助(如果没有,我想听听,因为这个解决方案对我来说很有用)
另外:如果有人能指出任何说明这一点的文档,我想看看
CLLocationCoordinate2D mbrMin = CLLocationCoordinate2DMake(maxY, minX);
CLLocationCoordinate2D mbrMax = CLLocationCoordinate2DMake(minY, maxX);