ArcGIS Runtime SDK for iOS(一) – 实现地图的不同点的callout展示

ArcGIS Runtime SDK for iOS(一) – 实现地图的不同点的callout展示

by. SevenJohs
2016.4.13 武汉 晴

- 概述
主要通过对ArcGIS Runtime SDK的学习,了解AGSGraphic与AGSFeature的区别,并在地图中画线并渲染。

- 内容

  • AGSGraphic的相关基础知识和逻辑结构;
  • 添加AGSGraphicLayer;
  • 展示属性信息于Callout上;
  • 使用symbol和render对graphic进行画线渲染。

AGSGraphic的相关基础知识和逻辑结构

AGSFeature提供一个协议,所定义的功能可以保留在本地数据库AGSDBFeature或内存AGSGraphic。由于几何和属性是在基类中定义,Geodatabase的特征和图形,主要区别是feature存储在磁盘数据库中,而图形数据存储在内存中。但是他们生活在一个图形层,必须在运行时以编程方式实例化。

虽然feature也可以指一个图形,但是最常用来指像Geodatabase的特征或语义特征存储在数据库中。graphic通常被称为“图形”,但是“图形功能”将更精确。

Geodatabase的feature:
    在表中存储的属性;存储在磁盘上;
    通过AGSFeatureTableLayer显示;
    根据定义的包含feature service或featureTableLayer的渲染进行标记;
    可以通过featureTableLayer被选中。
Graphic:
    在Key-Value集合中存储的属性;
    存储在内存中;
    通过AGSGraphicsLayer显示;
    可单独标记或根据renderer渲染器应用于graphicsLayer中;
    一些显示属性可以被定义的图形,如可视性(visibility)和绘制顺序(draw order)。
    可以通过graphicsLayer被选中;

区分二者使用时机:

feature:

    因为数据库的特点是存储在数据库中,它们可以被用来显示数据的应用程序的所有用户和用户会话之间的普通设置。地理数据库功能,可以定义一个几何类型和属性的架构。
    即,创建一个数据集来包含你的功能,并指定的几何类型和属性,在一个功能服务中的layer可以显示在地图中,并使用属性、空间或时间标准进行查询。

Graphic:

    Graphic是在运行时以编程方式创建,不需要物理存储。这使得它们非常适合于在当前用户的会话中显示特定于应用程序的特定的东西,或者仅需要临时显示的任何东西。
    图形是常用来执行的事情,如:显示空间分析的结果,如输入特征的缓冲多边形、突出显示在地图上的选择、添加几何图形交互的用户、为数据提供快速变化的动画(如全球定位系统的位置或移动对象)、在地图上显示文本等。

Graphic逻辑结构:

Geometry & Symbol(几何颜色/宽度/透明度)-----> Graphic   
Attributes(key-value)                -----> Graphic
renderer(在layer中add/delete/redraw)----->GraphicLayer

一、添加AGSGraphicLayer:

//创建简单标记样式
AGSSimpleMarkerSymbol* myMarkerSymbol = [self createSimpleMarkSymbolwithColor:[UIColor magentaColor] withOutlineColor:[UIColor brownColor]];
AGSPoint* myMarkerPoint = [AGSPoint pointWithX:-100 y:50 spatialReference:_mapView.spatialReference];
AGSGraphic* myGraphic = [AGSGraphic graphicWithGeometry:myMarkerPoint symbol:myMarkerSymbol attributes:nil infoTemplateDelegate:self];
//添加graphic到layer上
[_graphicLayer addGraphic:myGraphic];

二、展示属性信息于Callout上

      第一步:继承协议AGSInfoTemplateDelegate(为了突出,已经将其他delegate暂时删去):
@interface MapViewDemoViewController : UIViewController<AGSInfoTemplateDelegate>

第二步:在viewDidLoad中设置代理为自身:

self.mapView.callout.delegate = self;

第三步:实现协议方法(为了方便,我使用随机数来生成不同的callout展示):

#pragma mark AGSInfoTemplateDelegate Delegate method
-(NSString *)detailForGraphic:(AGSGraphic *)graphic screenPoint:(CGPoint)screen mapPoint:(AGSPoint *)mapPoint{

    double  x = arc4random() % 100;
    NSString* detailForGraphic = [NSString stringWithFormat:@"detail:%lf",x];
    return detailForGraphic;
}

-(NSString *)titleForGraphic:(AGSGraphic *)graphic screenPoint:(CGPoint)screen mapPoint:(AGSPoint *)mapPoint{

    double  y = arc4random() % 150;
    NSString* titleForGraphic = [NSString stringWithFormat:@"title:%lf",y];
    return titleForGraphic;
}

第四步:在graphicLayer中添加symbol符号或者创建简单标记点:

/**
 *  在graphicLayer上添加symbol符号
 */
-(void)addSymbol{

    AGSPictureMarkerSymbol* symbol = [[AGSPictureMarkerSymbol alloc] initWithImageNamed:@"1.png"];

    symbol.size = CGSizeMake(16, 16);
    symbol.color = [UIColor redColor];
    int x = arc4random() % 150;
    int y = arc4random() % 100;
    _symbolGraphic = [[AGSGraphic alloc]initWithGeometry:[AGSPoint pointWithX:x y:y spatialReference:nil] symbol:symbol attributes:nil infoTemplateDelegate:self];
    [_graphicLayer addGraphic:_symbolGraphic];

}
/**
 *  创建简单标记点 createSimpleMarkSymbol
 *
 *  @return AGSSimpleMarkerSymbol* simpleMarkerSymbol
 */
-(AGSSimpleMarkerSymbol*)createSimpleMarkSymbolwithColor:(UIColor*)basicColor withOutlineColor:(UIColor*)outlineColor{

    AGSSimpleMarkerSymbol* simpleMarkerSymbol = [AGSSimpleMarkerSymbol simpleMarkerSymbol];
    simpleMarkerSymbol.color = basicColor;
    simpleMarkerSymbol.style = AGSSimpleMarkerSymbolStyleDiamond;
    simpleMarkerSymbol.outline.color = outlineColor;
    simpleMarkerSymbol.outline.width = 3;
    _markSymbol=simpleMarkerSymbol;

    return simpleMarkerSymbol;
}

第五步:设置callout外观,可以单独封装为一个函数,之后在viewDidLoad中调用:

/**
 *  设置callout外观
 */
-(void)calloutApperanceSet{

    self.mapView.callout.accessoryButtonHidden = YES;
    self.mapView.callout.accessoryButtonType = UIButtonTypeCustom;
    self.mapView.callout.accessoryButtonImage=[UIImage imageNamed:@"1.png"];
    self.mapView.callout.color = [UIColor brownColor];
    self.mapView.callout.titleColor = [UIColor redColor];
    self.mapView.callout.detailColor = [UIColor whiteColor];
    self.mapView.callout.autoAdjustWidth = YES;
}

第六步:图层分层加载(具体详见最下面私有方法):

    //底图加载
    [self addTiledLayer];
    //要素图层初始化与加载
    [self addGraphicsLayer];
    //草图初始化加载
    [self addSketchGraphicLayer];
   //设置按钮 addTarget for selector
   ... ...

ps : Private Method

#pragma mark Privated Method
/**
 *  底图加载
 */
-(void)addTiledLayer{

    AGSTiledMapServiceLayer *tiledLayer = [[AGSTiledMapServiceLayer alloc] initWithURL:[NSURL URLWithString:kTiledMapServiceURL]];
    [self.mapView addMapLayer:tiledLayer withName:@"Tiled Layer"];
}
/**
 *  要素图层的初始化与加载
 */
-(void)addGraphicsLayer{

    _graphicLayer=[AGSGraphicsLayer graphicsLayer];
    _graphicLayer.visible = YES;
    [self.mapView addMapLayer:_graphicLayer withName:@"Graphic layer"];
}
/**
 *  草图初始化加载
 */
-(void)addSketchGraphicLayer{

    _sketchLayer = [[AGSSketchGraphicsLayer alloc]initWithGeometry:nil];
    _sketchLayer.visible = YES;
    [self.mapView addMapLayer:_sketchLayer withName:@"Sketch layer"];
}

end …
继续工作了~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值