Identify Task with Multiple LayerIDs

2746
6
Jump to solution
04-05-2012 03:33 PM
SteveLettau
New Contributor
Does anyone have any sample code for using the identify task on more than one layerId?  I have the code working with a single layerId (as with all the samples I can find).

self.identifyParams.layerIds = [NSArray arrayWithObjects:[NSNumber numberWithInt:0], nil];



I want to identify on multiple layers.  I've tried the following but it doesn't work.  Any ideas?

self.identifyParams.layerIds = [NSArray arrayWithObjects:[NSNumber numberWithInt:0], [NSNumber numberWithInt:1], [NSNumber numberWithInt:2],  nil];


Thanks,
Steve
0 Kudos
1 Solution

Accepted Solutions
NimeshJarecha
Esri Regular Contributor
Steve,

Just add a following code line in start of identifyTask::didExecuteWithIdentifyResults and you will see multiple results (see message on console). The sample shows callout and attributes for the first result only. You'll have to modify sample if you want to show attributes of all the results.

NSLog(@"results: %@",results);

Regards,
Nimesh

View solution in original post

0 Kudos
6 Replies
NimeshJarecha
Esri Regular Contributor
Your code looks correct. Here is the sample...

1. Download Identify Task Sample.
2. Comment out code line in viewDidLoad as shown below.

// set the visible layers on the layer
//dynamicLayer.visibleLayers = [NSArray arrayWithObjects:[NSNumber numberWithInt:5], nil];

3. Change code line as below in mapView::didClickAtPoint from one layerIds to multiple.

//self.identifyParams.layerIds = [NSArray arrayWithObjects:[NSNumber numberWithInt:5], nil];
self.identifyParams.layerIds = [NSArray arrayWithObjects:[NSNumber numberWithInt:1],[NSNumber numberWithInt:3],[NSNumber numberWithInt:4],[NSNumber numberWithInt:5], nil];

4. Test the sample. You'll see multiple results.

Hope this helps!

Regards,
Nimesh
0 Kudos
SteveLettau
New Contributor
Nimesh, thanks for the reply.  I did as suggested (see screenshot), and now can make out county outlines in the states.  When I identify, however, I only see the same 50 attributes shown by the original example.  I also noticed that after I made the changes to the code suggested, the state name disappeared from the callout.  Not sure if that's related, but bottom line, in my case changing the code didn't app earl to show attributes from additional layers.

One thing to add, I'm using Xcode 4.3.2.

Steve
0 Kudos
NimeshJarecha
Esri Regular Contributor
Steve,

Just add a following code line in start of identifyTask::didExecuteWithIdentifyResults and you will see multiple results (see message on console). The sample shows callout and attributes for the first result only. You'll have to modify sample if you want to show attributes of all the results.

NSLog(@"results: %@",results);

Regards,
Nimesh
0 Kudos
SteveLettau
New Contributor
Okay, I got it.  Thanks Nimesh.  I needed to step through the results to get each array.  Here's the code that worked:

        AGSIdentifyResult *layer0Results = [results objectAtIndex:0];
        AGSIdentifyResult *layer1Results = [results objectAtIndex:1];
        AGSIdentifyResult *layer2Results = [results objectAtIndex:2];


and then to get specific attribute values:


        NSString *prop_city = [layer2Results.feature.attributes objectForKey:@"City"];
        NSString *prop_state = [layer2Results.feature.attributes objectForKey:@"State"];
        NSString *prop_zip = [layer2Results.feature.attributes objectForKey:@"Zip"];



Thanks again,
Steve
0 Kudos
NimeshJarecha
Esri Regular Contributor
Great! Glad to know that you got it working! 🙂

Regards,
Nimesh
0 Kudos
LukePhilips
New Contributor III
How about identifying all visible layers? I'm guessing you can get which layers are currently visible from each of the (Dynamic/Tiled)MapServiceLayers and use that array for the identifyParams.layerIds?

**edit

nevermind, I found it. If we don't define layerIds and use layerOption = AGSIdentifyParametersLayerOptionVisible that should get what I need, though I'll have to get creative on iterating through all operational layers
0 Kudos