Getting layer ID of table in dynamic map service

750
5
09-09-2011 04:17 PM
RobertMartin2
Occasional Contributor II
Hello,

I am trying to retrieve the layer ID of a non-spatial table in a dynamic map service. At the start of my app I am creating a dictionary of layer names and IDs by looping over AGSMapServiceLayerInfo objects. The table, however, is not included. (I imagine this is because it has no graphic component in the map view.)  Is there any built-in property or method I could use for this?

Thanks in advance,
Robert
0 Kudos
5 Replies
NimeshJarecha
Esri Regular Contributor
Yes, you should use AGSMapServiceInfo's tableInfos property which provides an array of AGSMapServiceTableInfo objects. You'll get table id from there.

Regards,
Nimesh
0 Kudos
RobertMartin2
Occasional Contributor II
Doh! That was easy. Thank you Nimesh.
0 Kudos
RickJones
Occasional Contributor II
Could I see a snippet of how this is done?

I've tried this:

    AGSDynamicMapServiceLayer* layer = [[AGSDynamicMapServiceLayer dynamicMapServiceLayerWithURL:[NSURL URLWithString:kWaterNetworkURL]] retain];
    layer.visibleLayers = [NSArray arrayWithObjects:[NSNumber numberWithInt:0], [NSNumber numberWithInt:1], [NSNumber numberWithInt:2], [NSNumber numberWithInt:3], [NSNumber numberWithInt:4], [NSNumber numberWithInt:5], nil];
    AGSMapServiceInfo* msi =  ((AGSDynamicMapServiceLayer*)layer).mapServiceInfo;
    NSLog(@"Tables belonging to service with 6 layers and 4 tables");
    for (int i=0; i < [msi.tableInfos count]; i++) {
        AGSMapServiceTableInfo* ti = [msi.tableInfos objectAtIndex:i];
        NSLog(@"%d: %@", i, ti.name);
    }
[self.mapView addMapLayer:layer withName:layer.name];

No tables are listed.
0 Kudos
RickJones
Occasional Contributor II
I changed my code to this:

    NSURL *url = [NSURL URLWithString:kWaterNetworkURL];
    AGSMapServiceInfo *msi = [AGSMapServiceInfo mapServiceInfoWithURL:url error:&error];
NSLog(@"Tables belonging to service with 6 layers and 4 tables");
for (int i=0; i < [msi.tableInfos count]; i++) {
   AGSMapServiceTableInfo* ti = [msi.tableInfos objectAtIndex:i];
   NSLog(@"%d: %@", i, ti.name);
}

and it now lists tables.
0 Kudos
NimeshJarecha
Esri Regular Contributor
Glad you figured out! 🙂 you were trying to read information before it was available.

Regards,
Nimesh
0 Kudos