我只是覆盖了 MKOverlay,所以我正在寻找 Apple 开发人员示例代码中的良好实践......当我看到这个时:
// bite off up to 1/4 of the world to draw into.
MKMapPoint origin = points[0];
origin.x -= MKMapSizeWorld.width / 8.0;
origin.y -= MKMapSizeWorld.height / 8.0;
MKMapSize size = MKMapSizeWorld;
size.width /= 4.0;
size.height /= 4.0;
boundingMapRect = (MKMapRect) { origin, size };
MKMapRect worldRect = MKMapRectMake(0, 0, MKMapSizeWorld.width, MKMapSizeWorld.height);
boundingMapRect = MKMapRectIntersection(boundingMapRect, worldRect);
许多问题
- 为什么苹果在计算好的 boundingMapRect 后会与 worldRect 相交?
- 通过安全?
- boundingMapRect inter worldRect 并不总是 boundingMapRect ?
- 如果我有两个 MKMapPoint 代表我的 CGRect,我不必这样做,对吗?
问候,
编辑
所以我必须这样做?
// set the smallest rectangle which able to contain this overlay
MKMapPoint leftTopPoint = MKMapPointForCoordinate(leftTopCorner);
MKMapPoint rightBottomPoint = MKMapPointForCoordinate([self bottomRightCoord]);
boundingMapRect = MKMapRectMake(leftTopPoint.x, leftTopPoint.y,
fabs(leftTopPoint.x - rightBottomPoint.x),
fabs(leftTopPoint.y - rightBottomPoint.y));