我使用 addOverlay: 方法向我的 MKMapView 添加了一个叠加层。覆盖是使用 MKPolyline 制作的,并使用 MKPolylineView 进行描边。描边颜色为蓝色,alpha 值为 0.7。
当视图最初加载时,覆盖被正确绘制,但覆盖的周围区域也是蓝色的......当我捏和缩小时,蓝色区域仍然存在,但它会调整到我的新缩放级别。这有点难以描述......但基本上我有一个“法线贴图”的小矩形被困在一个更大的蓝色矩形内。
当我缩小查看整个国家时,它会消失,当我放大时一切正常。
我认为这可能是由于我没有正确实施 MKOverlayProtocol 造成的?
如果有人有任何想法,请按照我的方式提出......
编辑:
下面是创建 MKPolyline 和委托方法的代码。
-(MKPolyline *)bluePolyline
{
CLLocationCoordinate2D bluePoints[16];
bluePoints[0] = CLLocationCoordinate2DMake(27.526483, -97.882454);
bluePoints[1] = CLLocationCoordinate2DMake(27.526407, -97.887883);
bluePoints[2] = CLLocationCoordinate2DMake(27.527244, -97.887905);
bluePoints[3] = CLLocationCoordinate2DMake(27.527282, -97.887304);
bluePoints[4] = CLLocationCoordinate2DMake(27.527577, -97.887304);
bluePoints[5] = CLLocationCoordinate2DMake(27.527596, -97.885727);
bluePoints[6] = CLLocationCoordinate2DMake(27.530194, -97.88577); //Seale St. & Corrale Ave.
bluePoints[7] = CLLocationCoordinate2DMake(27.530213, -97.883892); //Retama & Corral Ave.
bluePoints[8] = CLLocationCoordinate2DMake(27.530279,-97.881907);
bluePoints[9] = CLLocationCoordinate2DMake(27.530337,-97.880201);
bluePoints[10] = CLLocationCoordinate2DMake(27.530356,-97.877959);
bluePoints[11] = CLLocationCoordinate2DMake(27.52753,-97.877884); //West C Ave. & Armstrong
bluePoints[12] = CLLocationCoordinate2DMake(27.527492,-97.878367);
bluePoints[13] = CLLocationCoordinate2DMake(27.527397,-97.878817);
bluePoints[14] = CLLocationCoordinate2DMake(27.527349,-97.882454);
bluePoints[15] = CLLocationCoordinate2DMake(27.526483, -97.882453);
if(bluePolyline == nil)
{
bluePolyline = [MKPolyline polylineWithCoordinates:bluePoints count:16];
}
bluePolyline.title = @"Blue Route";
_bluePolyline = bluePolyline;
return _bluePolyline;
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKPolylineView *aView = [[MKPolylineView alloc] initWithPolyline:(MKPolyline *)overlay];
//aView.fillColor = [[UIColor cyanColor] colorWithAlphaComponent:0.2];
aView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.6];
aView.lineWidth = 10;
return aView;
}