<?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: Panning around the world - geometry contains() test fails in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/panning-around-the-world-geometry-contains-test/m-p/1326055#M82168</link>
    <description>&lt;P&gt;If your polygon won't cross the international dateline, then you can normalize it on the client-side by rebuilding it from normalized points.&amp;nbsp; If it could could cross it, then perhaps the recommended solution for normalizing the polygon would be to use &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-support-normalizeUtils.html#normalizeCentralMeridian" target="_self"&gt;normalizeUtils.normalizeCentralMeridian&lt;/A&gt;.&amp;nbsp; Whatever method you choose, I recommend you normalize the polygon before adding it to your GraphicsLayer.&lt;/P&gt;&lt;P&gt;Anyhow, assuming the polygon is normalized, then it would just be a matter of:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if (polygonFilter &amp;amp;&amp;amp; polygonFilter.geometry.contains(point.clone().normalize())) {
	// pop up the toolbar
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Sep 2023 17:58:23 GMT</pubDate>
    <dc:creator>JoelBennett</dc:creator>
    <dc:date>2023-09-06T17:58:23Z</dc:date>
    <item>
      <title>Panning around the world - geometry contains() test fails</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/panning-around-the-world-geometry-contains-test/m-p/1326000#M82164</link>
      <description>&lt;P&gt;Using the sketchviewmodel i have drawn a graphic which acts like a polygon filter on the map.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JonathanTiu_2-1694017947815.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/79996iB2575C8D2309EE92/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JonathanTiu_2-1694017947815.png" alt="JonathanTiu_2-1694017947815.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyways, i have added logic such that clicking inside the polygon pops up a custom toolbar etc.&lt;/P&gt;&lt;P&gt;To do all this, my code is something like this:&lt;/P&gt;&lt;P&gt;mapView.hitTest(clickCoordinates).then((response: any) =&amp;gt; {&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if (response.results.length === 0) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;const polygonFilter = getPolygonFilterGraphic(layer);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // check if the click coordinates is inside the polygon filter&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;const point = new esri.Point({&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; x: event.mapPoint.x, y: event.mapPoint.y, &lt;SPAN&gt;&amp;nbsp;spatialReference&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt; &lt;SPAN&gt;esri&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;SpatialReference&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;WebMercator&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (polygonFilter &amp;amp;&amp;amp; polygonFilter.geometry.contains(point)) {&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // pop up the toolbar&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works fine except in the case where i pan around the world. so in my screenshot above if i pan around the world and arrive at this polygon filter over japan again, if i click inside it, the mapPoint is never inside the polygonFilter.geometry&amp;nbsp; (ie. the contains() predicate always fails.)&lt;/P&gt;&lt;P&gt;I suspect it has to do with the mapPoint's x coordinate being outside the current extent xmin and xmax. do i need to be normalizing the mapPoint or the polygonFilter.geometry or both? and if so, how do i normalize it? Any help would be appreciated thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 16:38:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/panning-around-the-world-geometry-contains-test/m-p/1326000#M82164</guid>
      <dc:creator>JonathanTiu</dc:creator>
      <dc:date>2023-09-06T16:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Panning around the world - geometry contains() test fails</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/panning-around-the-world-geometry-contains-test/m-p/1326022#M82165</link>
      <description>&lt;P&gt;If your polygon is always a rectangle, then the issue is straightforward:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var extents = polygonFilter.geometry.extent.clone().normalize();
var nPoint = point.clone().normalize();

for (var x = 0; x &amp;lt; extents.length; x++) {
	if (extents[x].intersects(nPoint)) {
		//pop up the toolbar

		break;
	}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 17:28:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/panning-around-the-world-geometry-contains-test/m-p/1326022#M82165</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2023-09-06T17:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: Panning around the world - geometry contains() test fails</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/panning-around-the-world-geometry-contains-test/m-p/1326032#M82166</link>
      <description>&lt;P&gt;It won't always be a rectangle. we allow freeform filter like this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I see, you're normalizing the extent of the polygon filter's geometry.&amp;nbsp; does your approach not work for arbitrary shapes? i guess the extent is a rectangle...&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JonathanTiu_0-1694021944427.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/80004i79F1E80C89706A47/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JonathanTiu_0-1694021944427.png" alt="JonathanTiu_0-1694021944427.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 17:40:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/panning-around-the-world-geometry-contains-test/m-p/1326032#M82166</guid>
      <dc:creator>JonathanTiu</dc:creator>
      <dc:date>2023-09-06T17:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Panning around the world - geometry contains() test fails</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/panning-around-the-world-geometry-contains-test/m-p/1326055#M82168</link>
      <description>&lt;P&gt;If your polygon won't cross the international dateline, then you can normalize it on the client-side by rebuilding it from normalized points.&amp;nbsp; If it could could cross it, then perhaps the recommended solution for normalizing the polygon would be to use &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-geometry-support-normalizeUtils.html#normalizeCentralMeridian" target="_self"&gt;normalizeUtils.normalizeCentralMeridian&lt;/A&gt;.&amp;nbsp; Whatever method you choose, I recommend you normalize the polygon before adding it to your GraphicsLayer.&lt;/P&gt;&lt;P&gt;Anyhow, assuming the polygon is normalized, then it would just be a matter of:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if (polygonFilter &amp;amp;&amp;amp; polygonFilter.geometry.contains(point.clone().normalize())) {
	// pop up the toolbar
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 17:58:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/panning-around-the-world-geometry-contains-test/m-p/1326055#M82168</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2023-09-06T17:58:23Z</dc:date>
    </item>
  </channel>
</rss>

