<?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 Selecting a feature from FeatureCollectionLayer in Kotlin Maps SDK Questions</title>
    <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/selecting-a-feature-from-featurecollectionlayer/m-p/1311211#M145</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm using a FeatureCollectionLayer to load custom geometry and attributes on my map. I have no problem displaying points on the map. But I do have an issue when selecting a feature.&lt;/P&gt;&lt;P&gt;Here is how I'm calling the tap method:&lt;/P&gt;&lt;LI-CODE lang="kotlin"&gt;lifecycleScope.launch {
            mapView.onSingleTapConfirmed.collect { event -&amp;gt;
                selectFeature(event.screenCoordinate)
            }
        }&lt;/LI-CODE&gt;&lt;P&gt;Here's the method to select feature:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;private suspend fun selectFeature(coordinate: ScreenCoordinate) {
        val layer = featureCollectionLayer.layers.value[0]
        layer.clearSelection()
        val layerResult = mapView.identifyLayer(layer, coordinate, 25.0, false, -1)
        layerResult.apply {
            onSuccess { result -&amp;gt;
                val features = result.geoElements.filterIsInstance&amp;lt;Feature&amp;gt;()
                if (features.isEmpty()) {
                    Log.d(localClassName, "No feature selected")
                    return@onSuccess
                }
                val selectedFeature = features[0]
                layer.selectFeatures(features)
                Snackbar.make(
                    mapView,
                    "${selectedFeature.attributes["Name"]} selected",
                    Snackbar.LENGTH_SHORT
                ).show()
            }
            onFailure {
                val errorMessage = "Select feature failed: " + it.message
                Log.e(localClassName, errorMessage)
                Snackbar.make(mapView, errorMessage, Snackbar.LENGTH_SHORT).show()
            }
        }
    }&lt;/LI-CODE&gt;&lt;P&gt;Based on what I have logged ("No feature selected"), it seems there are no features, but the points do display. If anyone can see an issue, that would be greatly appreciated.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Dave&lt;/P&gt;</description>
    <pubDate>Mon, 24 Jul 2023 20:43:41 GMT</pubDate>
    <dc:creator>DavidCasillas</dc:creator>
    <dc:date>2023-07-24T20:43:41Z</dc:date>
    <item>
      <title>Selecting a feature from FeatureCollectionLayer</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/selecting-a-feature-from-featurecollectionlayer/m-p/1311211#M145</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm using a FeatureCollectionLayer to load custom geometry and attributes on my map. I have no problem displaying points on the map. But I do have an issue when selecting a feature.&lt;/P&gt;&lt;P&gt;Here is how I'm calling the tap method:&lt;/P&gt;&lt;LI-CODE lang="kotlin"&gt;lifecycleScope.launch {
            mapView.onSingleTapConfirmed.collect { event -&amp;gt;
                selectFeature(event.screenCoordinate)
            }
        }&lt;/LI-CODE&gt;&lt;P&gt;Here's the method to select feature:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;private suspend fun selectFeature(coordinate: ScreenCoordinate) {
        val layer = featureCollectionLayer.layers.value[0]
        layer.clearSelection()
        val layerResult = mapView.identifyLayer(layer, coordinate, 25.0, false, -1)
        layerResult.apply {
            onSuccess { result -&amp;gt;
                val features = result.geoElements.filterIsInstance&amp;lt;Feature&amp;gt;()
                if (features.isEmpty()) {
                    Log.d(localClassName, "No feature selected")
                    return@onSuccess
                }
                val selectedFeature = features[0]
                layer.selectFeatures(features)
                Snackbar.make(
                    mapView,
                    "${selectedFeature.attributes["Name"]} selected",
                    Snackbar.LENGTH_SHORT
                ).show()
            }
            onFailure {
                val errorMessage = "Select feature failed: " + it.message
                Log.e(localClassName, errorMessage)
                Snackbar.make(mapView, errorMessage, Snackbar.LENGTH_SHORT).show()
            }
        }
    }&lt;/LI-CODE&gt;&lt;P&gt;Based on what I have logged ("No feature selected"), it seems there are no features, but the points do display. If anyone can see an issue, that would be greatly appreciated.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Dave&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2023 20:43:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/selecting-a-feature-from-featurecollectionlayer/m-p/1311211#M145</guid>
      <dc:creator>DavidCasillas</dc:creator>
      <dc:date>2023-07-24T20:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting a feature from FeatureCollectionLayer</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/selecting-a-feature-from-featurecollectionlayer/m-p/1311821#M158</link>
      <description>&lt;P&gt;Maybe the points that are displaying are on a different FeatureLayer that you are performing the Identify operation on ?&lt;BR /&gt;You can try using&amp;nbsp;&lt;A href="https://developers.arcgis.com/kotlin/api-reference/arcgis-maps-kotlin/com.arcgismaps.mapping.view/-geo-view/identify-layers.html" target="_self"&gt;identify layers&lt;/A&gt;&amp;nbsp;function instead. This will perform identify operation on all layers in the view.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 23:39:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/selecting-a-feature-from-featurecollectionlayer/m-p/1311821#M158</guid>
      <dc:creator>PuneetPrakash</dc:creator>
      <dc:date>2023-07-25T23:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting a feature from FeatureCollectionLayer</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/selecting-a-feature-from-featurecollectionlayer/m-p/1311832#M161</link>
      <description>&lt;P&gt;Thank you for the response. I was able to identify the feature collection layers on my map with no issues. I'm still not getting anything when tapping on a feature.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 00:21:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/selecting-a-feature-from-featurecollectionlayer/m-p/1311832#M161</guid>
      <dc:creator>DavidCasillas</dc:creator>
      <dc:date>2023-07-26T00:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting a feature from FeatureCollectionLayer</title>
      <link>https://community.esri.com/t5/kotlin-maps-sdk-questions/selecting-a-feature-from-featurecollectionlayer/m-p/1311928#M167</link>
      <description>&lt;P&gt;I was able to figure out how to select the features. Here's an updated code:&lt;/P&gt;&lt;LI-CODE lang="kotlin"&gt;private suspend fun selectFeature(coordinate: ScreenCoordinate) {
        val layer = featureCollectionLayer.layers.value[0]
        layer.clearSelection()
        val layerResult = mapView.identifyLayer(featureCollectionLayer, coordinate, 25.0, false, -1)
        layerResult.apply {
            onSuccess { result -&amp;gt;
                val features = mutableListOf&amp;lt;Feature&amp;gt;()
                    result.sublayerResults.forEach { subResults -&amp;gt;
                        features.addAll(subResults.geoElements.filterIsInstance&amp;lt;Feature&amp;gt;())
                    }
                if (features.isEmpty()) {
                    Log.d(localClassName, "No feature selected")
                    return@onSuccess
                }
                val selectedFeature = features[0]
                layer.selectFeatures(features)
                Snackbar.make(
                    mapView,
                    "${selectedFeature.attributes["Name"]} selected",
                    Snackbar.LENGTH_SHORT
                ).show()
            }
            onFailure {
                val errorMessage = "Select feature failed: " + it.message
                Log.e(localClassName, errorMessage)
                Snackbar.make(mapView, errorMessage, Snackbar.LENGTH_SHORT).show()
            }
        }
    }&lt;/LI-CODE&gt;&lt;P&gt;I guess when selecting features from a &lt;STRONG&gt;FeatureCollectionLayer&lt;/STRONG&gt;, you must identify those features from the &lt;STRONG&gt;sublayerResults&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 09:35:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/kotlin-maps-sdk-questions/selecting-a-feature-from-featurecollectionlayer/m-p/1311928#M167</guid>
      <dc:creator>DavidCasillas</dc:creator>
      <dc:date>2023-07-26T09:35:50Z</dc:date>
    </item>
  </channel>
</rss>

