Select to view content in your preferred language

Getting a legend on one Mapservice layer

634
1
12-01-2011 03:53 AM
RickJones
Deactivated User
If we use a Mapservice with multiple layers:
Poles(0)
Parcels(1)
Addresses(2)
Water Mains(3)
  and load just 1 layer (Addresses, index 2), as http://server/ArcGIS/rest/services/General/MapServer/2,

the Legend sample code gives this error:

2011-12-01 09:42:46.841 CityView[12055:207] Error encountered while fetching legend : Error Domain=NSCocoaErrorDomain Code=400 "Unable to complete  operation." UserInfo=0x8170d30 {NSLocalizedFailureReason=Invalid URL, NSURL=http://server/ArcGIS/rest/services/General/MapServer/2/Legend?f=json, NSLocalizedDescription=Unable to complete  operation.}

If, on the other hand, we use individual Mapservices for each layer, it works.

Navigating to the arcgis/rest/services/General/Mapservices folder, we see a Legend link, which generates the entire legend for all layers.
There is no legend link for any of the individual layers.
0 Kudos
1 Reply
NimeshJarecha
Esri Regular Contributor
There is no legend available for one of the layer in a map service. If you are loading just one layer from a map service then it must be an AGSFeatureLayer, correct?

If yes, you should get the swatch from the renderer symbol. See below code...

CGSize swatchSize = CGSizeMake(20,20);

//check the renderer of feature layer
if ([self.featureLayer.renderer isKindOfClass:[AGSUniqueValueRenderer class]]) {
 
  AGSUniqueValueRenderer *uniqueValueRenderer = (AGSUniqueValueRenderer*)self.featureLayer.renderer;
//you can loop through all symbols and get swatchs
  AGSUniqueValue *uniqueValue = [uniqueValueRenderer.uniqueValues objectAtIndex:0];
  UIImage *image = [uniqueValue.symbol swatchForGeometryType:self.featureLayer.geometryType size:swatchSize];
}

Please let me know if you need any further help!

Regards,
Nimesh
0 Kudos