<?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: Get graphic attribute from GraphicsLayer using hitTest with 4.24 api in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-graphic-attribute-from-graphicslayer-using/m-p/1207891#M78512</link>
    <description>&lt;P&gt;This is probably due to the hiTest updates listed in the 4.24 release notes here.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/release-notes/#mapview-and-sceneview-hittest-updates" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/release-notes/#mapview-and-sceneview-hittest-updates&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You might want to check for the result type. If you have a repro of your issue, could take a closer look. Is this a TypeScript error? If you check the result.type first, it might help TypeScript narrow the type correct to a GraphicHit.&lt;/P&gt;&lt;P&gt;This sample still uses hitTest&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=view-hittest" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=view-hittest&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Aug 2022 20:13:07 GMT</pubDate>
    <dc:creator>ReneRubalcava</dc:creator>
    <dc:date>2022-08-30T20:13:07Z</dc:date>
    <item>
      <title>Get graphic attribute from GraphicsLayer using hitTest with 4.24 api</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-graphic-attribute-from-graphicslayer-using/m-p/1207884#M78511</link>
      <description>&lt;P&gt;Hi - I'm trying to access the graphic attribute of a hitTest on a graphicsLayer.&amp;nbsp; The code below was working with 4.22, but not now at 4.24&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;        // Search for graphics at the clicked location
        a.view.hitTest(screenPoint).then(function (response) {
          if (response.results.length) {
            var graphic = response.results.filter(function (result) {
              // check if the graphic belongs to the layer of interest
              return result.graphic.layer === a.graphicsLayer;//at 4.24 this does not compile Property 'graphic' does not exist on type 'ViewHit'
              //try this as hitTestResult is array of result objects at 4.24
              return result[0].graphic === a.graphicsLayer;// TypeError: Cannot read properties of undefined (reading 'graphic')
              
            })[0].graphic;
            //call method on form component to open closeout form work order
            a.comService.WorkOrderClickedOnMap(graphic.attributes.WorkOrderID);
          }
        });&lt;/LI-CODE&gt;&lt;P&gt;strangely, when I break on result I see a graphic property (see below).&amp;nbsp; Any ideas how to get this to work?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HitTestResult.jpg" style="width: 706px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/49852iB9308BBE296247EC/image-size/large?v=v2&amp;amp;px=999" role="button" title="HitTestResult.jpg" alt="HitTestResult.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pete&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 19:55:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-graphic-attribute-from-graphicslayer-using/m-p/1207884#M78511</guid>
      <dc:creator>PeteVitt</dc:creator>
      <dc:date>2022-08-30T19:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: Get graphic attribute from GraphicsLayer using hitTest with 4.24 api</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-graphic-attribute-from-graphicslayer-using/m-p/1207891#M78512</link>
      <description>&lt;P&gt;This is probably due to the hiTest updates listed in the 4.24 release notes here.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/release-notes/#mapview-and-sceneview-hittest-updates" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/release-notes/#mapview-and-sceneview-hittest-updates&lt;/A&gt;&lt;/P&gt;&lt;P&gt;You might want to check for the result type. If you have a repro of your issue, could take a closer look. Is this a TypeScript error? If you check the result.type first, it might help TypeScript narrow the type correct to a GraphicHit.&lt;/P&gt;&lt;P&gt;This sample still uses hitTest&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=view-hittest" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=view-hittest&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 20:13:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-graphic-attribute-from-graphicslayer-using/m-p/1207891#M78512</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2022-08-30T20:13:07Z</dc:date>
    </item>
    <item>
      <title>Re: Get graphic attribute from GraphicsLayer using hitTest with 4.24 api</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-graphic-attribute-from-graphicslayer-using/m-p/1207909#M78513</link>
      <description>&lt;P&gt;Thanks Rene - maybe this is a typescript thing -- do you know of any other methods I could try to access graphic attributes of a clicked graphicsLayer other than hitTest?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 21:14:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-graphic-attribute-from-graphicslayer-using/m-p/1207909#M78513</guid>
      <dc:creator>PeteVitt</dc:creator>
      <dc:date>2022-08-30T21:14:04Z</dc:date>
    </item>
    <item>
      <title>Re: Get graphic attribute from GraphicsLayer using hitTest with 4.24 api</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-graphic-attribute-from-graphicslayer-using/m-p/1207925#M78514</link>
      <description>&lt;P&gt;hitTest is right, you just need to access the results slightly differently as of 4.24.&lt;/P&gt;&lt;P&gt;The documentation explains the 4.24 change and has some snippets.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#hitTest" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#hitTest&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;view.on("click", async (e) =&amp;gt; {
  const response = await view.hitTest(e);
  const result = response.results[0];
  if (result.type === "graphic") {
    const graphic = result.graphic;
  }
  else if (result.type === "media") {
    const element = result.element;
  }
  else if (result.type === "route") {
    const networkFeature = result.networkFeature;
  }
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 22:03:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-graphic-attribute-from-graphicslayer-using/m-p/1207925#M78514</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2022-08-30T22:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: Get graphic attribute from GraphicsLayer using hitTest with 4.24 api</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-graphic-attribute-from-graphicslayer-using/m-p/1207929#M78515</link>
      <description>&lt;P&gt;no graphic property&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HitTestResultIntellisense.jpg" style="width: 913px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/49867iF2C6FA3C73366256/image-size/large?v=v2&amp;amp;px=999" role="button" title="HitTestResultIntellisense.jpg" alt="HitTestResultIntellisense.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 22:11:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-graphic-attribute-from-graphicslayer-using/m-p/1207929#M78515</guid>
      <dc:creator>PeteVitt</dc:creator>
      <dc:date>2022-08-30T22:11:58Z</dc:date>
    </item>
    <item>
      <title>Re: Get graphic attribute from GraphicsLayer using hitTest with 4.24 api</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-graphic-attribute-from-graphicslayer-using/m-p/1207938#M78516</link>
      <description>&lt;P&gt;Thanks Rene - that did the trick!&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 22:39:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-graphic-attribute-from-graphicslayer-using/m-p/1207938#M78516</guid>
      <dc:creator>PeteVitt</dc:creator>
      <dc:date>2022-08-30T22:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: Get graphic attribute from GraphicsLayer using hitTest with 4.24 api</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-graphic-attribute-from-graphicslayer-using/m-p/1572506#M86321</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;How can i make it so that i can use multiple layers? I have this onclick fucntion:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;view.on ("click", function (event)
            {
                // Handle feature selection here
                console.log ("Get Selected Features Data")
                $ ('#customWindow').jqxWindow ('close');
                 $ ('#assignedEmployeesTable').jqxGrid ('clear')        
                view.hitTest (event).then (function (response)
                {
                    if (response.results.length &amp;gt; 0) {
                        const features = response.results.filter (function (result)
                        {
                            return result.graphic.layer === roomsUseLayer;// Filter for your specific layer
                        });

                        // Extract attributes from the selected features
                        features.forEach (function (feature)
                        {
                            attributes = feature.graphic.attributes;
                            console.log (attributes.SPACEID);
                            
                        });
                        getSpaceObjectID ();
                    }
                });
            });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2025 18:10:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-graphic-attribute-from-graphicslayer-using/m-p/1572506#M86321</guid>
      <dc:creator>Mr_Kirkwood</dc:creator>
      <dc:date>2025-01-03T18:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: Get graphic attribute from GraphicsLayer using hitTest with 4.24 api</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-graphic-attribute-from-graphicslayer-using/m-p/1572902#M86331</link>
      <description>&lt;P&gt;The code below wroks well for a solution:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;view.on("click", function (event) {
    // Handle feature selection here
    console.log("Get Selected Features Data")
    view.hitTest(event).then(function (response) {
        for (let i = 0; i &amp;lt; response.results.length; i++) {
            const result = response.results[i];
            const graphic = result.graphic;
            attributes = graphic.attributes;
            const layer = result.layer;
            console.log("Layer:", layer.title);
            console.log("Attributes:", attributes);
            console.log(attributes.OBJECTID)
            getObjectID();
        }
    });
});&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 06 Jan 2025 20:17:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-graphic-attribute-from-graphicslayer-using/m-p/1572902#M86331</guid>
      <dc:creator>Mr_Kirkwood</dc:creator>
      <dc:date>2025-01-06T20:17:54Z</dc:date>
    </item>
  </channel>
</rss>

