<?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: view.goTo() for Polygons in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/view-goto-for-polygons/m-p/1222236#M79036</link>
    <description>&lt;P&gt;I'm not at my PC at the moment but maybe you could return the extent of the layer? That will make sure both (or more) features are in the map view.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;extent:&lt;/PRE&gt;&lt;P&gt;Add this under the target with the feature geometry in it.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Sorry I'm on my phone so formatting is not great.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Oct 2022 23:13:24 GMT</pubDate>
    <dc:creator>GeoJason</dc:creator>
    <dc:date>2022-10-14T23:13:24Z</dc:date>
    <item>
      <title>view.goTo() for Polygons</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/view-goto-for-polygons/m-p/1222210#M79034</link>
      <description>&lt;P&gt;What I'm trying to achieve:&lt;BR /&gt;I'm attempting to load only polygons associated with a specific ID.&amp;nbsp; If only one record exists for that ID, I would like for the map to automatically center that polygon in the view.&amp;nbsp; If there are multiple records with the specified ID, I would like for the view to be the center of all polygons.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I believe I have a disconnect on how to use the view.goTo() method and would love if someone could help me sort it out!&lt;/P&gt;&lt;P&gt;I'll have a code snippet at the bottom but here is my thought process in case this helps analyze what I've got going on any.&lt;/P&gt;&lt;P&gt;- Grab layer URL&lt;BR /&gt;- Create new Feature Layer from URL, using Definition Expression to only return associated records&lt;BR /&gt;- Add layer to map&lt;BR /&gt;- Create an array to hold geometries in case there are multiple records (multiple polygons) associated with record&lt;BR /&gt;- Query the layer to return the geometry&lt;BR /&gt;- Loop over results and fill array created with geometry from each result.&lt;BR /&gt;- Pass&amp;nbsp;the array of geometries to the view.goTo() method.&lt;/P&gt;&lt;P&gt;I was previously keying into layer.geometry.rings and that didn't work so I thought maybe it wants the whole geometry object.&amp;nbsp; So instead of "featureGeometry" being an array of arrays, it's currently an array of objects.&lt;/P&gt;&lt;P data-unlink="true"&gt;I have been referencing &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#goTo" target="_self"&gt;this documentation&lt;/A&gt; but can't quite seem to figure out where I'm going wrong.&amp;nbsp; I am not getting any errors whatsoever.&amp;nbsp;&amp;nbsp;&amp;nbsp;All of my console logs are printing as I would expect them to.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;Side question: Is there a way I could just return the geometries in the Feature Layer definition instead of needing to make an extra query?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;Any help getting the view to go to the center of polygon(s) is MUCH appreciated!&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const programURL = "https://services3.arcgis.com/YCgdaDV3RW2dDPyk/arcgis/rest/services/program/FeatureServer/0"; 

const programLayer = new FeatureLayer({
      url: programURL,
      outfields: ["*"],
      definitionExpression: `recordID = ${recordId}`,
    });

    // Add layer to map
    map.add(programLayer);

    let featureGeometry = [];

    if (recordId) {
      const query = {
        where: `recordId = ${recordId}`,
        returnGeometry: true,
        outFields: ["*"],
      };

      programLayer.queryFeatures(query).then((results) =&amp;gt; {
        if (results.features.length &amp;gt; 0) {
          results.features.forEach((layer) =&amp;gt; {
            console.log(layer.geometry);
            featureGeometry = [...featureGeometry, layer.geometry];
          });
        }
      });
    }

    console.log(featureGeometry);

    view.goTo({
      target: featureGeometry
    }).catch(function (error) {
      if (error.name != "AbortError") {
        console.error(error);
      }
    });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2022 20:30:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/view-goto-for-polygons/m-p/1222210#M79034</guid>
      <dc:creator>DaltonR121</dc:creator>
      <dc:date>2022-10-14T20:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: view.goTo() for Polygons</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/view-goto-for-polygons/m-p/1222236#M79036</link>
      <description>&lt;P&gt;I'm not at my PC at the moment but maybe you could return the extent of the layer? That will make sure both (or more) features are in the map view.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;extent:&lt;/PRE&gt;&lt;P&gt;Add this under the target with the feature geometry in it.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Sorry I'm on my phone so formatting is not great.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Oct 2022 23:13:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/view-goto-for-polygons/m-p/1222236#M79036</guid>
      <dc:creator>GeoJason</dc:creator>
      <dc:date>2022-10-14T23:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: view.goTo() for Polygons</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/view-goto-for-polygons/m-p/1222500#M79047</link>
      <description>&lt;P&gt;If you just want to get the extent of the queried features, use &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#queryExtent" target="_self"&gt;queryExtent&lt;/A&gt; instead of queryFeatures.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;layer.queryExtent(query).then(function(results){
  view.goTo(results.extent);  // go to the extent of the results satisfying the query
});&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 17 Oct 2022 14:29:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/view-goto-for-polygons/m-p/1222500#M79047</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-10-17T14:29:25Z</dc:date>
    </item>
    <item>
      <title>Re: view.goTo() for Polygons</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/view-goto-for-polygons/m-p/1222564#M79048</link>
      <description>&lt;P&gt;Wow.&amp;nbsp; That was incredibly simple.&amp;nbsp; Thank you so much for your help.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Oct 2022 17:50:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/view-goto-for-polygons/m-p/1222564#M79048</guid>
      <dc:creator>DaltonR121</dc:creator>
      <dc:date>2022-10-17T17:50:29Z</dc:date>
    </item>
  </channel>
</rss>

