2012年2月3日 星期五

iOS學習_ESRI iOS SDK_AGSMapView MapLayer的控制

一般利用ESRI SDK開發相關的地圖應用程式,最常使用的三種圖層類別,莫過於TiledMapService、DynamicMapService與Graphics,而對應到iOS當中的定義分別為:

*AGSTiledMapServiceLayer
*AGSDynamicMapServiceLayer
*AGSGraphicsLayer

加入地圖的方法:
AGSTiledMapServiceLayer

AGSTiledMapServiceLayer *tiledLayer = [[AGSTiledMapServiceLayer alloc] initWithURL:[NSURL URLWithString:kTiledMapServiceURL]];
[self.mapView addMapLayer:tiledLayer withName:@"ola Tile"];


AGSDynamicMapServiceLayer

self.dynamicLayer = [[[AGSDynamicMapServiceLayer alloc] initWithURL:[NSURL URLWithString:kDynamicMapServiceURL]];
NSArray *layerArray = [NSArray arrayWithObjects:[NSNumber numberWithInt:26],nil];
self.dynamicLayer.visibleLayers = layerArray;
[self.mapView addMapLayer:self.dynamicLayer withName:@"ola Dynamic"];


AGSGraphicsLayer

self.olagraphic = [AGSGraphicsLayer graphicsLayer];
[self.mapView addMapLayer:self.olagraphic withName:@"olagraphicsLayer"];


總之,不管是要加入那一種圖層,都是使用addMapLayer的方法,而在使用該方法時,都回返回一個UIView,如果想要一開始就設定透明度與顯示與否,就可以在接下來後設定alpha或是hidden的屬性。

UIView *dynamicLayerView = [self.mapView addMapLayer:self.dynamicLayer withName:@"Dynamic Layer"];
dynamicLayerView.alpha = 0.5;
dynamicLayerView.hidden = NO;


有時候我們可以會想要知道mapView到底目前有哪些圖層,就可以藉由mapLayers方法取得圖層列表,利用mapLayerViews方法取得圖層視圖。

NSArray *layerLists = [self.mapView mapLayers];
AGSDynamicMapServiceLayer *layerGroup = [layerLists objectAtIndex:i];

NSDictionary *layerLists = [self.mapView mapLayerViews];
dynamicLayerView = [layerLists objectForKey:@"ola Dynamic"];


取得對應的dynamicLayerView後,就可以動態的改變是否顯示與透明度。

沒有留言:

張貼留言