<?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 View hitTest wrong GRAPHIC in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/view-hittest-wrong-graphic/m-p/1230350#M79284</link>
    <description>&lt;P&gt;I'm using the&amp;nbsp;&lt;STRONG&gt;view hitTest function&amp;nbsp;&lt;/STRONG&gt;to determine which feature is selected. But it seems like there are some issues with the hitTest for a dynamic updating layer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Reproduce steps:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;- A FeatureLayer displaying 40 graphics. Each 100ms a mocked update will be processed by &lt;STRONG&gt;ApplyEdits&lt;/STRONG&gt;.&amp;nbsp;&lt;BR /&gt;- HitTest function with hitResults[ =&amp;gt; The first result will be used for the content and location of the popup.&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Why we're using hitTest:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;We're creating a custom web element for displaying a popup instead of displaying the default popupTemplate. (should be created each time an asset changes)&lt;/P&gt;&lt;P&gt;=&amp;gt; A wrong popup is displayed when clicking a feature/graphic.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="wrongpopup.gif" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/55680iD7A906BDBF11CF11/image-size/medium?v=v2&amp;amp;px=400" role="button" title="wrongpopup.gif" alt="wrongpopup.gif" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="wrongpopup2.gif" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/55681i2E9ADAFF0BEB20B9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="wrongpopup2.gif" alt="wrongpopup2.gif" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Codepen&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://codepen.io/michaelk95/pen/abKoGxz?editors=1000" target="_blank"&gt;https://codepen.io/michaelk95/pen/abKoGxz?editors=1000&lt;/A&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Thu, 10 Nov 2022 09:51:00 GMT</pubDate>
    <dc:creator>MichaelK1</dc:creator>
    <dc:date>2022-11-10T09:51:00Z</dc:date>
    <item>
      <title>View hitTest wrong GRAPHIC</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/view-hittest-wrong-graphic/m-p/1230350#M79284</link>
      <description>&lt;P&gt;I'm using the&amp;nbsp;&lt;STRONG&gt;view hitTest function&amp;nbsp;&lt;/STRONG&gt;to determine which feature is selected. But it seems like there are some issues with the hitTest for a dynamic updating layer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Reproduce steps:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;- A FeatureLayer displaying 40 graphics. Each 100ms a mocked update will be processed by &lt;STRONG&gt;ApplyEdits&lt;/STRONG&gt;.&amp;nbsp;&lt;BR /&gt;- HitTest function with hitResults[ =&amp;gt; The first result will be used for the content and location of the popup.&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Why we're using hitTest:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;We're creating a custom web element for displaying a popup instead of displaying the default popupTemplate. (should be created each time an asset changes)&lt;/P&gt;&lt;P&gt;=&amp;gt; A wrong popup is displayed when clicking a feature/graphic.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="wrongpopup.gif" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/55680iD7A906BDBF11CF11/image-size/medium?v=v2&amp;amp;px=400" role="button" title="wrongpopup.gif" alt="wrongpopup.gif" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="wrongpopup2.gif" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/55681i2E9ADAFF0BEB20B9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="wrongpopup2.gif" alt="wrongpopup2.gif" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Codepen&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://codepen.io/michaelk95/pen/abKoGxz?editors=1000" target="_blank"&gt;https://codepen.io/michaelk95/pen/abKoGxz?editors=1000&lt;/A&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2022 09:51:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/view-hittest-wrong-graphic/m-p/1230350#M79284</guid>
      <dc:creator>MichaelK1</dc:creator>
      <dc:date>2022-11-10T09:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: View hitTest wrong GRAPHIC</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/view-hittest-wrong-graphic/m-p/1230685#M79293</link>
      <description>&lt;P&gt;The problem isn't so much with hitTest as it is with the workflow.&amp;nbsp; On a click, the popup is natively opened for the clicked feature, and your handler simply updates its location (without need).&amp;nbsp; Then, as applyEdits is repeatedly called, it seems the location gets out of sync with the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Popup.html#features" target="_self"&gt;features&lt;/A&gt; value (which was natively set).&lt;/P&gt;&lt;P&gt;I recommend making the following adjustments (the first line of each has not been changed from what you wrote, but the rest have):&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;layer.applyEdits(edits).then((res) =&amp;gt; {
	if ((view.popup.visible) &amp;amp;&amp;amp; (popupID === graphicForUpdate.attributes.ObjectID))
		view.popup.location = graphicForUpdate.geometry.centroid;
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;view.on('click', (event) =&amp;gt; {
	popupID = 0;
	view.hitTest(event).then((hitResult) =&amp;gt; {
		if ((Array.isArray(hitResult.results)) &amp;amp;&amp;amp; (hitResult.results.length !== 0) &amp;amp;&amp;amp; (hitResult.results[0].type == "graphic"))
			popupID = hitResult.results[0].graphic.attributes.ObjectID;
	});
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2022 20:24:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/view-hittest-wrong-graphic/m-p/1230685#M79293</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2022-11-10T20:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: View hitTest wrong GRAPHIC</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/view-hittest-wrong-graphic/m-p/1232120#M79342</link>
      <description>&lt;P&gt;When applying your changes in a codepen, I still see the same issues.&amp;nbsp;&lt;BR /&gt;Seems like the results of the hitTest function returns the wrong feature. (Because the layer is updating at the same time)&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2022 08:27:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/view-hittest-wrong-graphic/m-p/1232120#M79342</guid>
      <dc:creator>MichaelK1</dc:creator>
      <dc:date>2022-11-16T08:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: View hitTest wrong GRAPHIC</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/view-hittest-wrong-graphic/m-p/1234437#M79424</link>
      <description>&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-api-for-javascript-questions/selected-feature-popup-not-correct/td-p/1234432" target="_blank"&gt;https://community.esri.com/t5/arcgis-api-for-javascript-questions/selected-feature-popup-not-correct/td-p/1234432&lt;/A&gt;&lt;/P&gt;&lt;P&gt;New issue (selected feature)&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 09:36:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/view-hittest-wrong-graphic/m-p/1234437#M79424</guid>
      <dc:creator>MichaelK1</dc:creator>
      <dc:date>2022-11-23T09:36:51Z</dc:date>
    </item>
  </channel>
</rss>

