Feature layer callouts in iOS

4115
2
08-01-2014 11:19 AM
KunalMehta
New Contributor II

I am displaying one of the sample feature layers from ArcGIS online on my map and  I want to show a callout when a graphic on the feature layer is selected (tapped).

Following is a code snippet ..

- (void)viewDidLoad

{

    [super viewDidLoad];

     self.mapView.callout.delegate = self;

...

      NSURL *featureLayerURL =           [NSURL URLWithString:@"http://services.arcgis.com/oKgs2tbjK6zwTdvi/arcgis/rest/services/Major_World_Cities/FeatureServer/0"];

    AGSFeatureLayer *featureLayer = [AGSFeatureLayer featureServiceLayerWithURL:featureLayerURL mode:AGSFeatureLayerModeOnDemand];

    [self.mapView addMapLayer:featureLayer withName:@"CloudData"];

...

}

-(BOOL)callout:(AGSCallout *)callout willShowForFeature:(id<AGSFeature>)feature layer:(AGSLayer<AGSHitTestable> *)layer mapPoint:(AGSPoint *)mapPoint

{

    //Specify the callout's contents

   

     self.mapView.callout.title = (NSString*)[feature attributeForKey:@"NAME"];

     self.mapView.callout.detail =(NSString*)[feature attributeForKey:@"COUNTRY"];

    return YES;

}

However this sets title and details as nil, even though when I call this from the desktop browser (http://www.arcgis.com/home/webmap/viewer.html?url=http://services.arcgis.com/oKgs2tbjK6zwTdvi/ArcGIS...‌) it shows the name, country and other attributes.

What am I missing here? Is there a way to show the attributes/fields of the feature being selected? Any examples will be helpful too.

Thanks

2 Replies
by Anonymous User
Not applicable

One idea is to look at the feature attributes first and make sure the keys are not in lower case. You can always do [feature allAttributes] once to look at those and the key names. Hope the problem is a simple as that.

Cheers

Al

KunalMehta
New Contributor II

Actually, it turns out that I was missing setting outFields in the feature leayer:

    featureLayer.outFields = [NSArray arrayWithObject:@"*"];

Once I did this, all the fields were accessible as attributes in the graphic.