ArcGIS API For IOS 实现图层显示控制分两个粒度,分别是服务的显示控制,然后是图层的显示控制。
1)服务的显示控制
服务的显示控制用AGSMapView Class实现。每个UIViewController界面如果加载地图都会有一个AGSMapView对象实例,那么设置这个AGSMapView 实例的hidden=TRUE;
比如:
AGSTiledMapServiceLayer *tiledLayer = [[AGSTiledMapServiceLayer alloc] initWithURL:[NSURL URLWithString:kTiledEMapZoneMapService URL ]];
UIView *emapzoneTiledMap = [self.mapView addMapLayer:tiledLayer withName:@"Tiled Layer"];
emapzoneTiledMap.hidden = NO;
UIView *emapzoneTiledMap = [self.mapView addMapLayer:tiledLayer withName:@"Tiled Layer"];
emapzoneTiledMap.hidden = NO;
2)地图视图上服务的显示控制
单个地图服务的显示控制用AGSDynamicLayerView或AGSTiledLayerView实现,比如:
NSDictionary *dict=self.mapView.mapLayerViews;
NSArray *arr=[dict allValues];
for (int i = 0; i < [arr count]; i++) {
AGSDynamicLayerView *mapLayerView=[arr objectAtIndex:i];
if (显示控制条件) {
mapLayerView.hidden=TRUE;
}
}
3)单个服务内有多个图层的显示控制
NSURL* url = [NSURL URLWithString: @" http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer"];AGSDynamicMapServiceLaye r* layer = [AGSDynamicMapServiceLaye
r dynamicMapServiceLayerWi
thURL: url];
// only display ‘ushigh’ (id=0) and ‘states’ (id=1) layer
layer.visibleLayers = [NSArray arrayWithObjects:[NSNumber numberWithInt:0],[NSNumber numberWithInt:1], nil];
通过设置visibleLayers 来确定图层是否可见。
4) 小结
单个地图服务的显示控制用AGSDynamicLayerView或AGSTiledLayerView实现,比如:
NSDictionary *dict=self.mapView.mapLayerViews;
NSArray *arr=[dict allValues];
for (int i = 0; i < [arr count]; i++) {
}
3)单个服务内有多个图层的显示控制
NSURL* url = [NSURL URLWithString: @" http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer"];AGSDynamicMapServiceLaye
// only display ‘ushigh’ (id=0) and ‘states’ (id=1) layer
layer.visibleLayers = [NSArray arrayWithObjects:[NSNumber numberWithInt:0],[NSNumber numberWithInt:1], nil];
通过设置visibleLayers 来确定图层是否可见。
4) 小结
对象模型图如下:
实际上AGSMapView 、AGSLayerView对象都是UIView的子类,所以最终控制的是UIView是否可见。这样通过设置UIView是否隐藏来进行图层显示的控制。