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)")
}
}
}
}
}
Solved! Go to Solution.
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.
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.
Thanks, Nicholas. Do you know how I can get the popup for a selected feature?
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.
Thanks again, Nicholas. You're a huge help!