不同的彩色多边形叠加 [英] different coloured polygon overlays

查看:178
本文介绍了不同的彩色多边形叠加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用以下方法在地图视图上创建不同的彩色多边形?

is it possible to create different coloured polygons on a map view using the following method?

-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id )overlay{

说如果我有2个多边形设置一个为红色,另一个为黄色?

say if i had 2 polygons could i set one to red and the other to yellow?

推荐答案

一种方法是使用标题属性可以从另一个多边形告诉一个多边形。

One way is to use the title property to tell one polygon from another.

添加多边形时,相应地设置标题:

When adding the polygons, set their title accordingly:

pone.title = @"one";
[mapView addOverlay:pone];

pother.title = @"other";
[mapView addOverlay:pother];

然后在 viewForOverlay 中,您可以设置颜色基于标题:

Then in viewForOverlay, you can set the color based on title:

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
    MKPolygonView *pv = [[[MKPolygonView alloc] initWithPolygon:overlay] autorelease];

    if ([overlay.title isEqualToString:@"one"])
        pv.fillColor = [UIColor redColor];
    else if ([overlay.title isEqualToString:@"other"])
        pv.fillColor = [UIColor yellowColor];
    else
        pv.fillColor = [UIColor blueColor];

    return pv;
}

这篇关于不同的彩色多边形叠加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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