<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to determine if AGSFeature is selected in ArcGIS Runtime SDK for iOS Questions</title>
    <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1362273#M7689</link>
    <description>&lt;P&gt;Thanks for the reply Ting. &amp;nbsp;The solution you provided is what I was trying to avoid. 'result.featureEnumerator().allObjects" will load all of those selected features into memory, and if we're talking about thousands or 10s of thousands of selected features (very possible in our scenario) the device will run out of memory pretty quick. &amp;nbsp;What I was looking for was some sort of "isSelected" property that I could get from the geoElements that get returned from "mapView.identifyLayer".&lt;/P&gt;</description>
    <pubDate>Mon, 18 Dec 2023 21:10:41 GMT</pubDate>
    <dc:creator>TravisYordi</dc:creator>
    <dc:date>2023-12-18T21:10:41Z</dc:date>
    <item>
      <title>How to determine if AGSFeature is selected</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1362035#M7687</link>
      <description>&lt;P&gt;I have a use case where I need to be able to toggle whether a single feature is selected or not. &amp;nbsp;To do that, I need to be able to determine if it already selected, but I cannot seem to find anywhere in the code or documentation a quick/easy way such as a property on AGSFeature (doesn't exist). &amp;nbsp;Reaching out to see if there is a way outside of gathering all selected features and checking if the feature I tapped is included. That route will be too slow as there may be quite a few already selected features. &amp;nbsp;Any help would be appreciated, thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2023 15:42:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1362035#M7687</guid>
      <dc:creator>TravisYordi</dc:creator>
      <dc:date>2023-12-18T15:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if AGSFeature is selected</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1362151#M7688</link>
      <description>&lt;P&gt;Thanks for reaching out. You may use the&amp;nbsp;&lt;A href="https://developers.arcgis.com/ios/api-reference/interface_a_g_s_feature_layer.html#aaff4717e3f8b8efbe2f592bf4c691b13" target="_self"&gt;getSelectedFeaturesWithCompletion&lt;/A&gt;&amp;nbsp;method to get an iterator of all selected features in the feature layer, and then find if the feature is in there or not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;featureLayer.getSelectedFeatures { result, error in
    if let result {
        let selectedFeatures = result.featureEnumerator()
        let isSelected = selectedFeatures.contains { ($0 as? AGSFeature) == /* someFeature */ }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;The alternative way, as you mentioned, is to maintain a collection (Set) of all selected features locally, and check if a feature is selected, or add/remove the features when select/unselect.&lt;/P&gt;&lt;P&gt;Hope it helps. Please let me know if you have other questions.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2023 21:26:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1362151#M7688</guid>
      <dc:creator>Ting</dc:creator>
      <dc:date>2023-12-18T21:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if AGSFeature is selected</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1362273#M7689</link>
      <description>&lt;P&gt;Thanks for the reply Ting. &amp;nbsp;The solution you provided is what I was trying to avoid. 'result.featureEnumerator().allObjects" will load all of those selected features into memory, and if we're talking about thousands or 10s of thousands of selected features (very possible in our scenario) the device will run out of memory pretty quick. &amp;nbsp;What I was looking for was some sort of "isSelected" property that I could get from the geoElements that get returned from "mapView.identifyLayer".&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2023 21:10:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1362273#M7689</guid>
      <dc:creator>TravisYordi</dc:creator>
      <dc:date>2023-12-18T21:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if AGSFeature is selected</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1362303#M7690</link>
      <description>&lt;P&gt;mapView.identifyLayer(layer, screenPoint: screenPoint, tolerance: 20, returnPopupsOnly: false) { result in layer.getSelectedFeatures { selectedResults, _ in let results: [Bool] = result.geoElements.compactMap { geoElement in selectedResults?.featureEnumerator().contains(where: { ($0 as? AGSFeature) == (geoElement as! AGSFeature) }) ?? false } } }&lt;/P&gt;&lt;P&gt;I ran this test based on your suggestion with 25 selected features on my map. &amp;nbsp;Unfortunately the results object is empty in my test. The feature that I tap on (geoElement) is selected on my map, but the selectedResults.featureEnumerator() doesn't find any equality with that object (both cast to AGSFeature).&lt;/P&gt;</description>
      <pubDate>Mon, 18 Dec 2023 21:59:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1362303#M7690</guid>
      <dc:creator>TravisYordi</dc:creator>
      <dc:date>2023-12-18T21:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if AGSFeature is selected</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1362306#M7691</link>
      <description>&lt;P&gt;My mistake - I've edited the code a bit. To find a feature, you don't need to load all the features into memory using &lt;SPAN&gt;&lt;EM&gt;allObjects&lt;/EM&gt;. Loop through the iterator would only consume the memory for 1 object at a time.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In terms of why a feature doesn't have &lt;EM&gt;isSelected&lt;/EM&gt; property, I think it might come down to the fact that a feature can be both offline (e.g., from a shapefile feature table) and online (e.g. from a service feature table). It is not easy to store the selection state on the feature object itself. If a user pans away from a selected feature, it may also be removed from memory in order to query and draw the new features and keep the memory footprint low.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;This is not a definitive answer though, and I'll ask our team to see if other options have been considered in terms of the&amp;nbsp;&lt;EM&gt;isSelected&lt;/EM&gt; property on a feature.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 17:19:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1362306#M7691</guid>
      <dc:creator>Ting</dc:creator>
      <dc:date>2023-12-19T17:19:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if AGSFeature is selected</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1362661#M7692</link>
      <description>&lt;P&gt;I may have mislead you in the previous reply. By looping through the iterator, each element is instantiated on the fly, so comparing it against the geo element held in the memory won't work. Consider this snippet - as soon as the feature is selected, test and see if it can be retrieved with the&amp;nbsp;&lt;EM&gt;&lt;A href="https://developers.arcgis.com/ios/api-reference/interface_a_g_s_feature_layer.html#aaff4717e3f8b8efbe2f592bf4c691b13" target="_self" rel="nofollow noopener noreferrer"&gt;getSelectedFeaturesWithCompletion&lt;/A&gt;&lt;/EM&gt; method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="swift"&gt;import UIKit
import ArcGIS

class ViewController: UIViewController {
    @IBOutlet var mapView: AGSMapView! {
        didSet {
            let map = AGSMap(basemapStyle: .arcGISLightGray)
            map.operationalLayers.add(featureLayer)
            mapView.map = map
            mapView.setViewpointCenter(AGSPointMakeWGS84(34.56, -118.37), scale: 4e5)
            mapView.touchDelegate = self
        }
    }
    
    let featureLayer = AGSFeatureLayer(
        featureTable: AGSServiceFeatureTable(
            url: URL(string: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/Energy/Geology/FeatureServer/9")!
        )
    )
    
    var selectedFeature: AGSArcGISFeature?
}

extension ViewController: AGSGeoViewTouchDelegate {
    func geoView(_ geoView: AGSGeoView, didTapAtScreenPoint screenPoint: CGPoint, mapPoint: AGSPoint) {
        featureLayer.clearSelection()
        
        geoView.identifyLayer(
            featureLayer,
            screenPoint: screenPoint,
            tolerance: 10,
            returnPopupsOnly: false
        ) { [unowned self] result in
            if let feature = result.geoElements.first as? AGSArcGISFeature {
                featureLayer.select(feature)
                selectedFeature = feature
            } else if let error = result.error {
                print(error)
            }
            
            // Test if the selected feature can be retrieved.
            featureLayer.getSelectedFeatures { result, _ in
                if let result {
                    let isSelected = result.featureEnumerator().contains {
                        self.objectID(of: $0 as? AGSArcGISFeature) == self.objectID(of: self.selectedFeature)
                    }
                    print(isSelected)
                }
            }
        }
    }
    
    func objectID(of feature: AGSArcGISFeature?) -&amp;gt; String? {
        feature?.attributes["OBJECTID"] as? String
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 17:26:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1362661#M7692</guid>
      <dc:creator>Ting</dc:creator>
      <dc:date>2023-12-19T17:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if AGSFeature is selected</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1363253#M7696</link>
      <description>&lt;P&gt;var selectedFeatures: Set = [] func selectFeaturesFromSelection(layerName: String, completion: (() -&amp;gt; Void)? = nil) { if let layer = (map.operationalLayers as? [AGSFeatureLayer])?.first(where: { $0.name == layerName }), let selectionGeometry = sketchEditor.geometry { let params = AGSQueryParameters() params.geometry = selectionGeometry layer.selectFeatures(withQuery: params, mode: .add) { [unowned self] result, error in if let result = result { for case let feature as AGSFeature in result.featureEnumerator() { if let id = feature.attributes["OBJECTID"] as? String, !selectedFeatures.contains(id) { selectedFeatures.insert(id) } } } completion?() } }else{ completion?() } }&lt;/P&gt;&lt;P&gt;Based on your reply I made this code above to try and save off the "OBJECTID" from any selected features, but it doesn't appear that the attribute exists in the geodatabase file I'm working with. &amp;nbsp;Is that a standard/system/ESRI attribute, or am I doing something incorrectly above?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 20:04:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1363253#M7696</guid>
      <dc:creator>TravisYordi</dc:creator>
      <dc:date>2023-12-20T20:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if AGSFeature is selected</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1363258#M7697</link>
      <description>&lt;P&gt;For service geodatabases, object ID is the primary key for the tables. The point is to find a unique identifier for your feature to compare to. Feel free to pick the identifier that suit your data.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 20:19:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1363258#M7697</guid>
      <dc:creator>Ting</dc:creator>
      <dc:date>2023-12-20T20:19:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if AGSFeature is selected</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1363347#M7698</link>
      <description>&lt;P&gt;actually yes, it appears we do have OBJECTID, but it's not a string so the cast was failing. &amp;nbsp;I think I'll be able to maintain my own list of selected object IDs and make it work. &amp;nbsp;Thank you for the help!&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 22:25:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-ios-questions/how-to-determine-if-agsfeature-is-selected/m-p/1363347#M7698</guid>
      <dc:creator>TravisYordi</dc:creator>
      <dc:date>2023-12-20T22:25:52Z</dc:date>
    </item>
  </channel>
</rss>

