How to display entire list of attributes for a selected feature?

784
4
Jump to solution
05-20-2019 09:48 AM
JohnMoore1
New Contributor II

I'm trying to display a full list of attributes for some selected features, but the code below only prints a few of the attributes for each selected feature.  There should be about 20 different fields for each feature, but the code only prints 5 of their attributes.  How do I go about displaying the entire list of attributes for a selected feature?  Also, how would I display the popup for a selected feature obtained in this manner?  Thanks for any help!

let layers = self.mv.map?.operationalLayers as? [AGSLayer]

        for layer in layers! {

            if let featureLayer = layer as? AGSFeatureLayer {

                featureLayer.getSelectedFeatures { (queryResult: AGSFeatureQueryResult?, error: Error?) in

                    if let error = error {

                        print("Error: \(error.localizedDescription)")

                        return

                    }

                    

                    if let result = queryResult {

                        let selectedFeatures = result.featureEnumerator().allObjects

                        for feature in selectedFeatures {

                            print("Attributes: \(feature.attributes)")

                        }

                     }

                }

            }

        }

                   

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Nicholas-Furness
Esri Regular Contributor

You should call loadWithCompletion() on the AGSArcGISFeature.

Once loaded, you should see all the fields. We do this by default to ensure that we don't bring more down the wire than we need to.

Note, you can use AGSLoadObjects() to load all the items in your selectedFeatures array.

View solution in original post

0 Kudos
4 Replies
Nicholas-Furness
Esri Regular Contributor

You should call loadWithCompletion() on the AGSArcGISFeature.

Once loaded, you should see all the fields. We do this by default to ensure that we don't bring more down the wire than we need to.

Note, you can use AGSLoadObjects() to load all the items in your selectedFeatures array.

0 Kudos
JohnMoore1
New Contributor II

Thanks, Nicholas.  Do you know how I can get the popup for a selected feature?

Nicholas-Furness
Esri Regular Contributor

A Feature is a GeoElement, so you can use AGSPopup.popupWithGeoElement().

I believe this may be smart enough to look at the Feature's source table to derive its PopupDefinition, but if not you can read that from the feature table directly using AGSArcGISFeatureTable.popupDefinition, or from the layer in AGSFeatureLayer.popupDefinition, and pass that into AGSPopup.popupWithGeoElement:PopupDefinition().

Note you can get to the featureTable from the feature using the featureTable property.

If you just want to display the popup, you can use the AGSPopupsViewController.

This sample might help too.

0 Kudos
JohnMoore1
New Contributor II

Thanks again, Nicholas.  You're a huge help!