Select features on feature layer

4384
3
12-02-2012 06:57 AM
PhilippFauser
New Contributor
Hi there,

I'm trying to select features on a AGSFeatureLayer, but that doesn't work.
Here's my code, maybe someone finds something that isn't right.

code in "viewDidLoad". This adds the 18 AGSFeatureLayers to my mapView:
for(int i = 0; i < 19; i++) {
        NSString *urlString = [@"http://www.geoportal.passau.de/ArcGIS/rest/services/APPDATEN/MapServer/" stringByAppendingFormat:@"%i", i];
        NSString *layerNameString = [@"feature" stringByAppendingFormat:@"%i", i];
        NSURL* url = [NSURL URLWithString: urlString];
        AGSFeatureLayer* featureLayer = [AGSFeatureLayer featureServiceLayerWithURL: url mode: AGSFeatureLayerModeSelection];
        self.lyrView = [self.mapView addMapLayer:featureLayer withName:layerNameString];
        featureLayer.queryDelegate = self;
        [self.featureLayerArray addObject:featureLayer];
    }


code in "mapView: didLoadLayerForLayerView:". Here I'm trying to select a feature on the FeatureLayer number 1:
AGSFeatureLayer *newLayer = (AGSFeatureLayer*)[self.featureLayerArray objectAtIndex:1];
    
    AGSQuery* query = [AGSQuery query];
    query.where = @"ID <> 0";
    //query.spatialRelationship = AGSSpatialRelationshipWithin;
    //query.geometry = californiaGeometry;
    [newLayer selectFeaturesWithQuery:query selectionMethod:AGSFeatureLayerSelectionMethodAdd];


The class is defined as AGSFeatureLayerQueryDelegate, but none of these delegate methods is called:
featureLayer: operation: didFailQueryFeaturesWithError:
featureLayer: operation: didFailSelectFeaturesWithError:
featureLayer: operation: didSelectFeaturesWithFeatureSet:
featureLayer: operation: didQueryFeaturesWithFeatureSet:

What am I doing wrong here?
Is there an example for that? I only found one with the editing of the FeatureLayer.

Thanks for any advice!!

Philipp
0 Kudos
3 Replies
PhilippFauser
New Contributor
Okay, I think it's not working because I generate the AGSFeatureLayers in the for-loop and add them to the array.
If I declare a public property for a AGSFeatureLayer in the header-file it's working (selecting the features).

Is there a way (I'm objective-c beginner, sometimes I don't get, maybe obvious, things...) to generate those 18 AGSFeatureLayers without declaring every single one as a property in the header-file?
0 Kudos
NimeshJarecha
Esri Regular Contributor
Try changing code in your "mapView: didLoadLayerForLayerView:" as following...

if ([layerView.agsLayer isKindOfClass:[AGSFeatureLayer class]]) {
     AGSFeatureLayer *fl = (AGSFeatureLayer*)layerView.agsLayer;
     fl.queryDelegate = self;

     AGSQuery* query = [AGSQuery query];
     query.where = @"ID <> 0";
     //query.spatialRelationship = AGSSpatialRelationshipWithin;
     //query.geometry = californiaGeometry;
     [fl selectFeaturesWithQuery:query selectionMethod:AGSFeatureLayerSelectionMethodAdd];
}


Hope this helps!

Regards,
Nimesh
0 Kudos
HrishikeshPol
New Contributor

Hi Nimesh,

Not able to get didLoadLayerForLayerView: this method. Will you please help me with this.

0 Kudos