使用MKPolyline& amp的覆盖问题MKPolylineView [英] Trouble with overlay using MKPolyline & MKPolylineView

查看:84
本文介绍了使用MKPolyline& amp的覆盖问题MKPolylineView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用addOverlay:方法为我的MKMapView添加了一个叠加层。使用MKPolyline制作覆盖层并使用MKPolylineView进行描边。笔触颜色为蓝色,alpha值为0.7。

I have added an overlay to my MKMapView using the addOverlay: method. The overlay was made using MKPolyline and stroked using MKPolylineView. The stroke color is blue, with an alpha value of 0.7.

最初加载视图时,正确绘制叠加层,但叠加层的周围区域也是蓝色...
当我捏&缩小,蓝色区域仍然存在,但它会调整到我的新缩放级别。这有点难以描述......但基本上我有一个小的矩形法线贴图被困在一个较大的蓝色矩形内。

When the view initially loads, the overlay is drawn correctly but the surrounding areas of the overlay are blue as well... When I pinch & zoom out, the blue area is still there but it adjusts to my new zoom level. This is somewhat hard to describe... but basically I have a small rectangle of "normal map" trapped inside a larger rectangle that is blue.

它会消失缩小以查看整个国家/地区,当我放大所有内容时,一切正常。

It will disappear when I zoom out to view the entire country and when I zoom back in everything is normal.

我认为这可能是因为我没有正确实施MKOverlayProtocol?

I think this may be caused by me not implementing the MKOverlayProtocol correctly?

如果有人有任何想法,请按我的方式抛出...

If anyone has any ideas please throw them my way...

编辑:

以下是创建MKPolyline和委托方法的代码。

Here is the code that creates the MKPolyline and the delegate method.

-(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;
}


推荐答案

我最终修复了我的问题通过实现 MKOverlay 协议方法:

I ended up fixing my problem by implementing the MKOverlay Protocol method:

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay; 

如下:

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    MKPolylineView *aView = [[MKPolylineView alloc] initWithPolyline:(MKPolyline *)overlay];

    if(overlay.title == @"Blue Route")
    {
        aView.lineWidth = 7.0;
        aView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.6];
    }
    if(overlay.title == @"Gold Route-A")
    {
        aView.lineWidth = 10.0;
        aView.strokeColor = [[UIColor yellowColor] colorWithAlphaComponent:0.6];
    }
    if(overlay.title == @"Gold Route-B")
    {
        aView.lineWidth = 7.0;
        aView.strokeColor = [[UIColor yellowColor] colorWithAlphaComponent:0.6];
    }
    return aView;

}

每个叠加层的创建位置在我的模型中的其他地方。

Where each overlay was created elsewhere in my model.

这篇关于使用MKPolyline&amp; amp的覆盖问题MKPolylineView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆