<?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 Is there any way to grab attributes of a selected feature without using/listening to the popup? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/is-there-any-way-to-grab-attributes-of-a-selected/m-p/1081995#M73992</link>
    <description>&lt;P&gt;I have a feature layer and I'm trying to grab an attribute from a feature the user clicked on.&lt;/P&gt;&lt;P&gt;The standard way to do that would be to do something like:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;myView.popup.watch("selectedFeature", function()
{
  if(myView.popup.selectedFeature != null)
  {
      var myVar = myView.popup.selectedFeature.attributes.Thing;
  }
}&lt;/LI-CODE&gt;&lt;P&gt;The problem with doing that is that &lt;STRONG&gt;every&lt;/STRONG&gt; time the popup pops up, it runs that code. For example, if you also have a search widget that searches for something and selects something in another layer, it thus has a popup, and then runs that code anyway simply &lt;EM&gt;because&lt;/EM&gt; it has a popup. But of course since that search is dealing with a totally different layer, you don't &lt;EM&gt;want&lt;/EM&gt; that code to be invoked. That is, it's running that listener for no reason at all.&lt;/P&gt;&lt;P&gt;What I would &lt;EM&gt;like&lt;/EM&gt; to do is something like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;myView.on("click", function ()
{
  var myVar = myView.selectedFeature.attributes.Thing;
}&lt;/LI-CODE&gt;&lt;P&gt;This would let me deal with the selected feature totally independent of any popup. Unfortunately, as far as I can tell that's impossible because for some reason ESRI decided to make the selected feature an attribute of the popup instead of an attribute of the view or the feature layer (which would make a ton more sense, but I digress).&lt;/P&gt;&lt;P&gt;Anybody have any ideas?&lt;/P&gt;</description>
    <pubDate>Thu, 22 Jul 2021 22:28:31 GMT</pubDate>
    <dc:creator>Jackson_CountyMissouri</dc:creator>
    <dc:date>2021-07-22T22:28:31Z</dc:date>
    <item>
      <title>Is there any way to grab attributes of a selected feature without using/listening to the popup?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/is-there-any-way-to-grab-attributes-of-a-selected/m-p/1081995#M73992</link>
      <description>&lt;P&gt;I have a feature layer and I'm trying to grab an attribute from a feature the user clicked on.&lt;/P&gt;&lt;P&gt;The standard way to do that would be to do something like:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;myView.popup.watch("selectedFeature", function()
{
  if(myView.popup.selectedFeature != null)
  {
      var myVar = myView.popup.selectedFeature.attributes.Thing;
  }
}&lt;/LI-CODE&gt;&lt;P&gt;The problem with doing that is that &lt;STRONG&gt;every&lt;/STRONG&gt; time the popup pops up, it runs that code. For example, if you also have a search widget that searches for something and selects something in another layer, it thus has a popup, and then runs that code anyway simply &lt;EM&gt;because&lt;/EM&gt; it has a popup. But of course since that search is dealing with a totally different layer, you don't &lt;EM&gt;want&lt;/EM&gt; that code to be invoked. That is, it's running that listener for no reason at all.&lt;/P&gt;&lt;P&gt;What I would &lt;EM&gt;like&lt;/EM&gt; to do is something like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;myView.on("click", function ()
{
  var myVar = myView.selectedFeature.attributes.Thing;
}&lt;/LI-CODE&gt;&lt;P&gt;This would let me deal with the selected feature totally independent of any popup. Unfortunately, as far as I can tell that's impossible because for some reason ESRI decided to make the selected feature an attribute of the popup instead of an attribute of the view or the feature layer (which would make a ton more sense, but I digress).&lt;/P&gt;&lt;P&gt;Anybody have any ideas?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jul 2021 22:28:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/is-there-any-way-to-grab-attributes-of-a-selected/m-p/1081995#M73992</guid>
      <dc:creator>Jackson_CountyMissouri</dc:creator>
      <dc:date>2021-07-22T22:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: Is there any way to grab attributes of a selected feature without using/listening to the popup?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/is-there-any-way-to-grab-attributes-of-a-selected/m-p/1082007#M73994</link>
      <description>&lt;P&gt;I think you can do exactly what you are talking about using the 'View.on("click"' and the 'hittest' to get selected features, like this:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Set up function to collect location if view is clicked 
view.on("click", (event) =&amp;gt; {
    // Pull selected features if any
    view.hitTest(event).then((response) =&amp;gt; {
        var results = response.results;
        if (results.length &amp;gt; 0) {
            for (var i = 0; i &amp;lt; results.length; i++) {
                 console.log(results[i]); 
            }
        }
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 22 Jul 2021 22:46:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/is-there-any-way-to-grab-attributes-of-a-selected/m-p/1082007#M73994</guid>
      <dc:creator>JeffreyWilkerson</dc:creator>
      <dc:date>2021-07-22T22:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: Is there any way to grab attributes of a selected feature without using/listening to the popup?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/is-there-any-way-to-grab-attributes-of-a-selected/m-p/1082200#M74000</link>
      <description>&lt;P&gt;Thanks, that works. Specifically I've got this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;	myView.on("click", (event) =&amp;gt;
	{
		myView.hitTest(event).then((response) =&amp;gt;
		{
			var result = response.results[0].graphic.attributes;
			var myVar = result.Thing;
		});
	});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jul 2021 15:00:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/is-there-any-way-to-grab-attributes-of-a-selected/m-p/1082200#M74000</guid>
      <dc:creator>Jackson_CountyMissouri</dc:creator>
      <dc:date>2021-07-23T15:00:28Z</dc:date>
    </item>
  </channel>
</rss>

