Adding Map Layers

1149
12
06-14-2010 06:17 AM
JeffPapirtis
New Contributor III
Since ESRI documentation on the Beta SDK is still a work in progress, can any one give me some help on adding individual map layers from a rest service?  I am pretty solid on adding the map service from the documentation thus far, but am not exactly sure on how to impelement individual layers within the map.

Ex: basemap rest service
(3) = roads

"http://server.maphost_example/ArcGIS/rest/services/basemap/MapServer/3"

I just want to add one layer from my map service.

Any Ideas?

Thanks in advance!
0 Kudos
12 Replies
JeremyBixby
New Contributor III
Use the addLayer method.  For example, this is from the header file from a map nib I have:

-(void) addLenexaTiledMapLayer:(NSString*)layerURL:(NSString*) lyrName;
-(void) addLenexaTiledMapLayerURL:(NSURL*)layerURL:(NSString*) lyrName;
-(void) removeLenexaMapLayer:(NSString*)layerName;
-(void) addLenexaDynamicMapLayer:(NSString*)layerURL:(NSString*) lyrName;


And here is the implementations of said functions, in the .m file:

-(void) addLenexaTiledMapLayerURL:(NSURL*)layerURL:(NSString*)lyrName{
 
 AGSTiledMapServiceLayer *tiledMapLyr = [[AGSTiledMapServiceLayer alloc] initWithURL:layerURL];
 [mapView addMapLayer:tiledMapLyr withName:lyrName];
 [tiledMapLyr release];
 
}

-(void) addLenexaTiledMapLayer:(NSString*)layerURL:(NSString*)lyrName{
 
 AGSTiledMapServiceLayer *tiledMapLyr = [[AGSTiledMapServiceLayer alloc] initWithURL:[NSURL URLWithString:layerURL]];
 [mapView addMapLayer:tiledMapLyr withName:lyrName];
 [tiledMapLyr release];

}
-(void) removeLenexaMapLayer:(NSString*)layerURL:(NSString*)lyrName{
 [mapView removeMapLayerWithName:lyrName];
}
-(void) addLenexaDynamicMapLayer:(NSString*)layerURL:(NSString*)lyrName{

 AGSDynamicMapServiceLayer *dynaMapLyr = [[AGSDynamicMapServiceLayer alloc] initWithURL:[NSURL URLWithString:layerURL]];
 dynaMapLyr.dpi = 96;
 [mapView addMapLayer:dynaMapLyr withName:lyrName];
 
 [dynaMapLyr release];
 
}


and then if you want to access the layer once it's been added to the map, use the appropriate layerview object:

 AGSTiledLayerView *basemapView = [self.mapView.mapLayerViews objectForKey:@"myBasemap"];
 basemapView.alpha = self.mySlider.value;
0 Kudos
NimeshJarecha
Esri Regular Contributor
The 1st layer (base layer) should be a tiled layer and then you�??ll be able to add your map service layers on top of it.

Regards,
Nimesh
0 Kudos
DiveshGoyal
Esri Regular Contributor
Jeff,

You cannot selectively add only one layer from your map service. You have to add the entire map service.

If you add the map service as a AGSDynamicMapServiceLayer, you can set it's visibleLayers property to only display the layer you want.

Hope this helps.
0 Kudos
JeffPapirtis
New Contributor III
Thanks Divesh,
I have all of my map services added, two tiled, and one Dynamic, but I am not sure what the proper syntax is to acomplish what is visible within the mapView within the dynamic map service. 

Where and how would the visibleLayers property be set?

Will I need to set up an array with the layers that are present in the rest service?

I appologize if I am not following, but I am very new at this.

Thanks
0 Kudos
NimeshJarecha
Esri Regular Contributor
Jeff,

Just before adding a layer to map view, add following line to set the visible layer.

dynamicLayer.visibleLayers = [NSArray arrayWithObjects:[NSNumber numberWithInt:0], nil];

Nimesh
0 Kudos
JeffPapirtis
New Contributor III
Thanks Nimesh!
after a lot of metal lifting I was able to load only the layers I wanted using the NSArray and your advice.  For everyone else interested I will post my solution this weekend.

Thanks Nimesh!!!!
0 Kudos
KOLDODUARTE
New Contributor
Finally, What was your solution?

Thanks !
0 Kudos
JeffPapirtis
New Contributor III
ok, sorry for the delay. 

Some real code, I am still figuring out how to read the documentation code, so looking at something that actually works in code helps me a lot. 

//Code below creates an array with the different layers within a dynamic service.

GSDynamicMapServiceLayer *facilityLayer = [[AGSDynamicMapServiceLayer alloc]
           initWithURL:[NSURL URLWithString:@"http://gis.shh.noaa.gov/ArcGIS.rest/services/coop/MapServer"]];

//define varible, initiate & populate the array.
NSArray *dynamicLayer;
dynamicLayer =[[NSArray alloc] initWithObjects:
       [NSNumber numberWithInt:0],
       [NSNumber numberWithInt:1],
       [NSNumber numberWithInt:2],
       [NSNumber numberWithInt:3],
       [NSNumber numberWithInt:4],
       [NSNumber numberWithInt:5],
       [NSNumber numberWithInt:6],
       [NSNumber numberWithInt:7],
       [NSNumber numberWithInt:8],
       [NSNumber numberWithInt:9],
       [NSNumber numberWithInt:10],
       [NSNumber numberWithInt:11],
       [NSNumber numberWithInt:12],
       nil
       ];
//set the facility layer visible layers property to equal the array.

facilityLayer.visibleLayers=dynamicLayer;
}

self.facilityView = [self.mapView addMapLayer:facilityLayer withName:@"dynamicLayer"];

[facilityLayer release];


So in order to show only certain layers just remove the corresponding value in the array.
example if 20 mile grid in the NOAA rest service is ....MapServer/8" then to remove the line in the array that defines that particular layer.

This is by no means a final working solution, but hopefully it will help to understand some of the structure behind it.
0 Kudos
KOLDODUARTE
New Contributor
Thank jpapirti !

I have the same problem, I hope to resolve with you solution !

Regards.
0 Kudos