原文地址连接:http://blog.sina.com.cn/s/blog_921dfd9b010165i3.html
图层是空间数据的载体,如果你对ArcGIS Server稍有了解的话,就能明白API里不同类型的图层对应了服务器端发布的不同Service,可以分成两大类:静态图层和动态图层。
表3-2-1 不同类型图层的继承关系
表3-2-2图层类的属性和方法
1 静态图层
表3-2-3 静态图层的继承关系
表3-2-4 静态图层的方法和属性
注意:如果静态服务图层的空间参考与MapView的不一致,就无法显示。
1.1 切片地图服务图层(AGSTiledMapServiceLayer)
“虽然图层已经初始化并添加到地图中,但切片信息还是空值?”,建议先判断加载成功与否,尤其是在网速不好的情况下:
1.2 微软Bing服务图层(AGSBingMapLayer)
由于Esri与微软之间的合作关系,保证了ArcGIS用户也能使用最新的微软Bing全球影像地图服务,当然这也是静态服务,加入用户的密匙(在ArcGISServer Manager页面可获取)就能使用:
- NSString*
bingMapsKey = @"--your--key--"; - AGSBingMapLayer*
layer = [[AGSBingMapLayeralloc]initWithAppID:bingMapsKeystyle:AGSBingMapLayerStyleAeri al];
*Bing服务空间参考为横轴Web摩卡托:
WGS1984 Web Mercator (Auxiliary Sphere) ,WKID=102100:
1.3 OSM服务图层(AGSOpenStreetMapLayer)
Esri与OpenStreetMap之间也建立了合作关系,
*OpenStreetMap服务空间参考为横轴Web摩卡托:
WGS1984 Web Mercator (Auxiliary Sphere) ,WKID=102100:
1.4 自定义切片图层(Custom TiledLayer)
图3-2-6 自定义切片图层的调用流程
- //继承了AGSTiledLayer
- @interface
OfflineTiledLayer :AGSTiledLayer { -
... - }
- //自定义切片服务元数据
- @implementation
OfflineTiledLayer - -(AGSUnits)
units { //todo } - -(AGSSpatialReference*)
spatialReference {//todo } - -(AGSEnvelope*)
fullEnvelope { //todo } - -(AGSEnvelope*)
initialEnvelope { //todo } -
- -(AGSTileInfo*)
tileInfo { //todo } - (NSOperation*)retrieveImageAsyncForTil
e:(AGSTile*)tile { -
//todo } - //初始化方法-path:切片路径
- -
(id)initWithDataFramePath:(NSString*)patherror:(NSError**)outError; -
... - @end
*关于切片规则的详细介绍,请参考网上其他资料。
图3-2-7 松散型切片的组织结构
1.
- -
(id)initWithDataFramePath:(NSString *)path error:(NSError**) outError { -
if (self = [super init]) { -
self.dataFramePath = path; -
//解析 conf.cdi -
NSString* confCDI = [[NSBundlemainBundle] pathForResource:@"conf" ofType:@"cdi"inDirectory: _dataFramePath ]; -
NSXMLParser* xmlParser = [[NSXMLParser alloc]initWithContentsOfURL:[NSURL fileURLWithPath:confCDI]]; -
OfflineCacheParserDelega te*parserDelegate = [[[OfflineCacheParserDelega te alloc] init] autorelease] ; -
[xmlParsersetDelegate:parserDelegate]; -
[xmlParser parse]; -
[xmlParser release]; -
//解析 conf.xml -
NSString* confXML = [[NSBundlemainBundle] pathForResource:@"conf" ofType:@"xml"inDirectory: _dataFramePath]; -
... - }
- -(void)parser:(NSXMLParser
*)parser didEndElement:(NSString *)elementNamenamespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName - {
-
if ([elementNameisEqualToStri ng:@"LODInfo"]){ -
self.lod = [[[AGSLODalloc]initWithLevel:_level resolution:_resolution scale:_scale] autorelease]; -
[self.lods addObject:_lod]; -
}else if ([elementNameisEqualToStri ng:@"CacheInfo"]){ -
_tileSize = CGSizeMake(_tileWidth,_tileHeight); -
self.spatialReference =[[[AGSSpatialReference alloc] initWithWKID:_WKID WKT:_WKT] autorelease]; -
self.tileOrigin = [[[AGSPointalloc] initWithX:_tileOriginX y:_tileOriginYspatialRefere nce:_spatialReference] autorelease]; -
self.fullEnvelope = [AGSEnvelopeenvelopeWithX min:_xmin -
ymin:_ymin -
xmax:_xmax -
ymax:_ymax -
spatialReference:_spatialReference]; -
self.tileInfo = [[[AGSTileInfoalloc] initWithDpi: _dpi -
format:_tileFormat -
lods:_lods -
origin:_tileOrigin -
spatialReference:_spatialReference -
tileSize:_tileSize] autorelease]; -
} - }
2.
- //根据
Level, Row,Column获取切片 -
@try { -
//Level ('L' followed by 2 digits) -
NSString *decLevel = [NSStringstringWithFormat :@"Ld",self.tile.level]; -
//Row ('R' followed by 8hexadecimal digits) -
NSString *hexRow = [NSStringstringWithFormat :@"Rx",self.tile.row]; -
//Column ('C' followed by 8hexadecimal digits) -
NSString *hexCol = [NSStringstringWithFormat :@"Cx",self.tile.column]; -
NSString*dir = [_allLayersPathstringByApp endingFormat:@"/%@/%@",decLevel,hexRow]; -
//查找PNG格式切片 -
NSString *tileImagePath =[[NSBundle mainBundle] pathForResource:hexCol ofType:@"png"inDirectory:dir]; -
... -
} -
@catch (NSException *exception) { -
NSLog(@"main: Caught Exception%@: %@", [exception name], [exception reason]); -
} -
@finally { -
//Invoke the layer's action method -
[_target performSelector:_actionwithObject:self]; -
}"font-size:10px;color:windowtext;">
*OfflineTiledLayer用来解释自定义切片服务图层设计原理,不适合大规模离线使用,因为松散型的切片小文件分发、更新非常耗时,建议采用下一节的AGSLocalTiledLayer接口+切片包TPK压缩格式。
*加载其他在线切片地图(百度地图、天地图和谷歌地图)的方法和代码,我会在后续章节专门做介绍。
1.5 本地切片图层(AGSLocalTiledLayer)