jonesra

Legend question

Discussion created by jonesra on Oct 21, 2011
Latest reply on Oct 28, 2011 by njarecha-esristaff
I have a question about getting legend info for a layer which is part of a frame with other layers.
The Legend info returned is all layers in the frame, not the one I passed.

So, if I ask for legend info on each of 5 layers, I get 5 lines returned each time (25 in the legend window).
Is there a way to get just the layer I sent back?

The sample legend code has been slightly modified to use the layer's View, so I can toggle it off/on, but that's irrelevant to the retrieveLegendInfo.

- (void) addLegendForLayer:(AGSLayer *)layer withView:(UIView*)view {
//Check type of layer
if ([layer isKindOfClass: [AGSDynamicMapServiceLayer class]]) {
 
  //Get the service info
  AGSMapServiceInfo* msi =  ((AGSDynamicMapServiceLayer*)layer).mapServiceInfo;
 
  //Legend only supported for services from  10 Service Pack 1 or above
  if(msi.version>=10.01){
   msi.delegate = self;
   [msi retrieveLegendInfo];
  }else {
   NSLog(@"Skipping layer [%@]. ArcGIS Service must be version 10 SP1 or above",msi.URL );
  }
<..snip..> 
 

- (void)mapServiceInfo:(AGSMapServiceInfo *)mapServiceInfo operationDidRetrieveLegendInfo:(NSOperation*)op {
NSArray* layerInfos = mapServiceInfo.layerInfos;
//Loop through all sub-layers
for (int i=0; i<[layerInfos count]; i++) {
 
  AGSMapServiceLayerInfo* layerInfo = (AGSMapServiceLayerInfo*)[layerInfos objectAtIndex:i];
  NSArray* legendLabels = layerInfo.legendLabels;
  NSArray* legendImages = layerInfo.legendImages;
 
  for(int j=0;j<[legendImages count];j++){
   //Store info for each legend item
   LegendInfo* legendInfo = [[[LegendInfo alloc] init] autorelease];
   legendInfo.name = layerInfo.name;
   legendInfo.detail = [legendLabels objectAtIndex:j];
   legendInfo.image = [legendImages objectAtIndex:j];
   legendInfo.view = nil;
   [self.legendInfos addObject:legendInfo];
  }
 
}
//Reload the table to display newly added legend items
[self reload];
}

PS. By frame, I mean in an ArcMap project.

Outcomes