How to retreive AGSFeatureTableLayer info from AGSFeature?

3358
7
02-16-2016 01:23 AM
DemoSurvey
New Contributor

On Clicking of feature on Map I receive call to the below delegate and also receive features as a argument.  Now I wanted to figure out these features belongs to which layer. Based on type of layer I have to do programmatically update other layer in the map.

- (void) mapView:(AGSMapView *)mapView didClickAtPoint:(CGPoint)screen mapPoint:(AGSPoint *)mappoint features:(NSDictionary *)features

Awaiting for reply!! Thanks in advance.

0 Kudos
7 Replies
ShiminCai
Occasional Contributor III

Hi,

- (void) mapView:(AGSMapView *)mapView didClickAtPoint:(CGPoint)screen mapPoint:(AGSPoint *)mappoint features:(NSDictionary *)features

{

     NSMutableArray *tappedFeatures = [[NSMutableArray alloc]init];

     NSEnumerator* keys = [features keyEnumerator];

       

     for (NSString* key in keys)

     {  

          [tappedFeatures addObjectsFromArray:[features objectForKey:key]];

     }

         NSString* layerName;

     for (id<AGSFeature> feature in tappedFeatures)

     {

          if ([feature isKindOfClass:[AGSGraphic class]])

          {

               AGSGraphic* graphic = (AGSGraphic*)feature;

               AGSFeatureLayer *featureLayer = (AGSFeatureLayer *)graphic.layer;

               layerName = graphic.layer.name;

          }

          else if ([feature isKindOfClass:[AGSGDBFeature class]])

          {

               AGSGDBFeature* gdbFeature = (AGSGDBFeature*)feature;

               AGSFeatureTable *featureTable = gdbFeature.table;

               layerName = gdbFeature.table.tableName;

          }

     }

}

The layerName should tell which layer a feature belongs to... Hope it helps.

Regards,

Shimin

0 Kudos
DemoSurvey
New Contributor

Hi Shimin,

Thanks for reply !!

But still is there a way to retrieve instance of AGSFeatureTableLayer  as in my case I have two layers in offline mode with same table name. So one layer is only in read only mode, but if user clicks on feature on layer and perform edit with read only mode layer , programmatically I have do the same changes in another layer which has both read and write mode. In short I am not allowed to do update data on read only mode layer.  So currently for both the layers there are two geodatabases only difference is in the URL even layer numbers  are same.

Awaiting for reply..

0 Kudos
ShiminCai
Occasional Contributor III

Not sure if an instance of AGSFeatureTableLayer can be retrieved but it can certainly be created based on a gdb feature's table:

AGSGDBFeature* gdbFeature = (AGSGDBFeature*)feature;

AGSFeatureTable *featureTable = gdbFeature.table;

AGSFeatureTableLayer *featureTableLayer = [[AGSFeatureTableLayer alloc]initWithFeatureTable:featureTable];

To get the service url from a gdb feature:

AGSGDBFeatureTable *gdbFeatureTable = (AGSGDBFeatureTable *)featureTable;

AGSGDBGeodatabase *gdb = gdbFeatureTable.geodatabase;

NSURL *url = gdb.serviceURL;

NSString *urlString = [url absoluteString];

Based on the difference of the URLs, I think you can tell which layer or featureTable you need to update upon...

Nicholas-Furness
Esri Regular Contributor

Actually, gdbFeature.table.tableName doesn't have to be the same as the layer name.

Instead, try this:

-(void)mapView:(AGSMapView *)mapView didClickAtPoint:(CGPoint)screen mapPoint:(AGSPoint *)mappoint features:(NSDictionary *)features {

    for (NSString *layerName in features.allKeys) {

        AGSLayer *layer = [mapView mapLayerForName:layerName];

        for (id<AGSFeature> feature in features[layerName]) {

            NSLog(@"Feature %@ belongs to layer %@ (named '%@').", feature, layer, layerName);

        }

    }

}

You get the layer from the map based off the layer name that's passed in its the features dictionary. If you want, you can then detect that this is an AGSFeatureTableLayer and get the table. As you mentioned, the same table can drive multiple layers, but each layer can only have one source table.

Hope this helps,

Nick.

MuruganandhamKuppan1
New Contributor III

Hi Shimin Cai,

Any idea to accomplish this identify process and differentiate the graphic and feature in arcgis version 100?

I have some feature layer and asset layer, both were added in mapview's operational layer. But i can fetch only features, not assets.

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Can you give me some more details please? It seems like you might be asking a different question to the one Shimin  was asking.

In Runtime 100, AGSGraphicsOverlays are added to the AGSMapView.graphicsOverlays collection and are always displayed over operational layers. Layers (e.g. Feature Layers) are added to the AGSMap.operationalLayers collection.

There are likewise now two groups of identify methods on AGSMapView (actually, AGSGeoView since they apply to both MapView and SceneView):

  • identifyGraphicsOverlay(s)
  • identifyLayer(s)

See them listed here.

If you need to identify Graphics, use the identifyGraphicsOverlay(s) methods. If you need to identify Features, use the identifyLayer(s) methods.

0 Kudos
Survey83Demo
New Contributor

Thanks Shimin and Nicholas for comments. Currently I have tried Shimin suggestion I will look into Nicholas comment too.

0 Kudos