<?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: Zoom to Query Results in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zoom-to-query-results/m-p/567490#M52949</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think I inserted your code correctly, however, if I have &lt;/SPAN&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;var extent = esri.graphicsExtent(results);&lt;/PRE&gt;&lt;SPAN&gt; anywhere in the "showResults" function, the map fails- even if I don't use extent anywhere else.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 04 Jun 2013 19:07:58 GMT</pubDate>
    <dc:creator>TrevorWeiland</dc:creator>
    <dc:date>2013-06-04T19:07:58Z</dc:date>
    <item>
      <title>Zoom to Query Results</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zoom-to-query-results/m-p/567488#M52947</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;HELP!&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am working on a JavaScript web page that does two things:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1) Query a rest service for the attribute information from a single record and then presents it in a table.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2) Builds a map and zooms to the results from the query. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I used the "Query State Info without Map" to start with and to accomplish the first task.&amp;nbsp; I added a map (basemap plus a couple of additional layers for display).&amp;nbsp; However, I am unable to extract the geometry from the query results as a point to use when creating the map.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The rest service I'm using for the query is not exposed to the internet so I have reworked and simplified my code (using just the sample code and internet services) to the basics so I can learn what I'm doing and apply it to my actual page:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;lt;!DOCTYPE html&amp;gt; &amp;lt;html&amp;gt;&amp;nbsp; &amp;lt;head&amp;gt; &amp;nbsp; &amp;lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&amp;gt; &amp;nbsp; &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10"&amp;gt; &amp;nbsp; &amp;lt;!--The viewport meta tag is used to improve the presentation and behavior of the samples on iOS devices--&amp;gt; &amp;nbsp; &amp;lt;meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"&amp;gt; &amp;nbsp; &amp;lt;link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/dojo/dijit/themes/claro/claro.css"&amp;gt; &amp;nbsp; &amp;lt;link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/esri/css/esri.css"&amp;gt; &amp;nbsp; &amp;lt;title&amp;gt;Query State Info with Map&amp;lt;/title&amp;gt; &amp;nbsp; &amp;lt;script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/"&amp;gt;&amp;lt;/script&amp;gt; &amp;nbsp; &amp;lt;script&amp;gt; &amp;nbsp;&amp;nbsp; dojo.require("esri.tasks.query"); &amp;nbsp;&amp;nbsp; dojo.require("esri.map");&amp;nbsp; &amp;nbsp;&amp;nbsp; var queryTask, query, centerPoint, stateName;&amp;nbsp; &amp;nbsp;&amp;nbsp; var stateName = "Colorado" /* stateName for QueryTask */&amp;nbsp; &amp;nbsp;&amp;nbsp; function init() { /* Setup query */ &amp;nbsp;&amp;nbsp;&amp;nbsp; queryTask = new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"); &amp;nbsp;&amp;nbsp;&amp;nbsp; query = new esri.tasks.Query(); &amp;nbsp;&amp;nbsp;&amp;nbsp; query.returnGeometry = true; &amp;nbsp;&amp;nbsp;&amp;nbsp; query.outSpatialReference = new esri.SpatialReference({wkid : 102100}); &amp;nbsp;&amp;nbsp;&amp;nbsp; query.outFields = ["STATE_NAME","SQMI","SUB_REGION"]; &amp;nbsp;&amp;nbsp;&amp;nbsp; query.text = stateName; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; queryTask.execute(query, showResults); &amp;nbsp;&amp;nbsp; }&amp;nbsp; &amp;nbsp;&amp;nbsp; function showResults(results) { &amp;nbsp;&amp;nbsp;&amp;nbsp; var s = ""; &amp;nbsp;&amp;nbsp;&amp;nbsp; for (var i=0, il=results.features.length; i&amp;lt;il; i++) { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var featureAttributes = results.features&lt;I&gt;.attributes; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for (att in featureAttributes) { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s = s + "&amp;lt;b&amp;gt;" + att + ":&amp;lt;/b&amp;gt; " + featureAttributes[att] + "&amp;lt;br /&amp;gt;"; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &amp;nbsp;&amp;nbsp;&amp;nbsp; } &amp;nbsp;&amp;nbsp;&amp;nbsp; dojo.byId("info").innerHTML = s; /* Extract Geometry From Query */ &amp;nbsp;&amp;nbsp;&amp;nbsp; centerPoint = new esri.geometry.Point(getPoint(results)); //Does NOT work- Actual use will be a point layer //&amp;nbsp;&amp;nbsp;&amp;nbsp; centerPoint = [-122.45, 37.75] //fake point for testing /* Build Map */ &amp;nbsp;&amp;nbsp;&amp;nbsp; map = new esri.Map("map",{ basemap: "topo", center:centerPoint, zoom:13 });&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; map.addLayer(new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer", { "opacity":0.2, spatialReference: map.spatialReference })); /* Add ESRI Census Map */ &amp;nbsp;&amp;nbsp; } &amp;nbsp;&amp;nbsp; dojo.ready(init); &amp;nbsp; &amp;lt;/script&amp;gt;&amp;nbsp; &amp;lt;/head&amp;gt;&amp;nbsp; &amp;lt;body class="claro"&amp;gt; &amp;nbsp; &amp;lt;div id="info" style="padding:5px; margin:5px; background-color:#eee;"&amp;gt;&amp;lt;/div&amp;gt; &amp;nbsp; &amp;lt;div id="map"&amp;gt;&amp;lt;/div&amp;gt;&amp;nbsp; &amp;lt;/body&amp;gt; &amp;lt;/html&amp;gt;&lt;/I&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Can someone please help me understand how to extract the geometry of the results to a variable that can then be used to create a center-point in a map?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you,&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Jun 2013 16:07:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zoom-to-query-results/m-p/567488#M52947</guid>
      <dc:creator>TrevorWeiland</dc:creator>
      <dc:date>2013-06-04T16:07:11Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to Query Results</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zoom-to-query-results/m-p/567489#M52948</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;A better way to do this would be to zoom to the extent of your graphics and expand a bit to zoom out.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;function showResults(results) { &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // This takes the graphics array you get back from your query and &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // gets the overall extent for them. Make sure return geometry is set to&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // true in your query. &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var extent = esri.graphicsExtent(results.features);&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Use that to set the extent, 1.5 is something I use in my app, but play with &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // it to find a setting you like, setting the second parameter to true will get you an extend &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // that is at the closest level of your cached service. &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map.setExtent(extent.expand(1.5), true); }&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I noticed in your code your map isn't initialized yet at this point. Your map initialize code would change to the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;following and you would skip the map.setExtent above.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; map = new esri.Map("map",{ basemap: "topo", extent: extent })&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hopefully this helps you out a bit. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Jun 2013 18:15:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zoom-to-query-results/m-p/567489#M52948</guid>
      <dc:creator>AdamSkoog</dc:creator>
      <dc:date>2013-06-04T18:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to Query Results</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zoom-to-query-results/m-p/567490#M52949</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think I inserted your code correctly, however, if I have &lt;/SPAN&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;var extent = esri.graphicsExtent(results);&lt;/PRE&gt;&lt;SPAN&gt; anywhere in the "showResults" function, the map fails- even if I don't use extent anywhere else.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Jun 2013 19:07:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zoom-to-query-results/m-p/567490#M52949</guid>
      <dc:creator>TrevorWeiland</dc:creator>
      <dc:date>2013-06-04T19:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to Query Results</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zoom-to-query-results/m-p/567491#M52950</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;to solve this problem you have to dig into the results in order to get a reference to the geometry of the returned polygon itself (ie.&amp;nbsp; "results" is a generic featureset, "results.features" is an array of graphics and "results.features&lt;I&gt;.geometry" is a geometry object for a specific graphic, where "i" refers to the index position of the item within an array).&lt;/I&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;in order to use our utility method to return the extent of a collection of graphics, you would do this&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;var extent = esri.graphicsExtent(results.features);&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;here's how to retrieve the same extent by calling the getExtent method of a single polygon geometry object (this works because there was only one graphic in the array)&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;//features[0] will always be the first item in an array
var extent = results.features[0].geometry.getExtent();

map = new esri.Map("map",{ basemap: "topo", extent: extent }); &lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;here's how you use the polygon geometry to retrieve a valid point from within the geometry instead&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;//in order to call the getPoint method of a polygon geometry object, you have to pass index positions to articulate which ring and specific point you want 
centerPoint = results.features[0].geometry.getPoint(0,0);

map = new esri.Map("map",{ basemap: "topo", center:centerPoint, zoom:13 });&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;i've always found it really helpful to set breakpoints within the callback so that i can inspect the results and use the console interactively to figure out how to get a reference to exactly what i need so that i can go back afterwards and modify the source code&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[ATTACH=CONFIG]24992[/ATTACH]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;hopefully all that helps!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:27:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zoom-to-query-results/m-p/567491#M52950</guid>
      <dc:creator>JohnGravois</dc:creator>
      <dc:date>2021-12-12T00:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to Query Results</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zoom-to-query-results/m-p/567492#M52951</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;jgravois was right, I was typing to fast and forgot to add the features property on there. I editted the post to reflect what it should be.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Jun 2013 12:07:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zoom-to-query-results/m-p/567492#M52951</guid>
      <dc:creator>AdamSkoog</dc:creator>
      <dc:date>2013-06-05T12:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to Query Results</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zoom-to-query-results/m-p/567493#M52952</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;thank you both very much.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Jun 2013 20:13:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zoom-to-query-results/m-p/567493#M52952</guid>
      <dc:creator>TrevorWeiland</dc:creator>
      <dc:date>2013-06-05T20:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: Zoom to Query Results</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zoom-to-query-results/m-p/567494#M52953</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;you're very welcome.&amp;nbsp; please feel free to mark Adam's post as the answer.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Jun 2013 20:45:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/zoom-to-query-results/m-p/567494#M52953</guid>
      <dc:creator>JohnGravois</dc:creator>
      <dc:date>2013-06-05T20:45:11Z</dc:date>
    </item>
  </channel>
</rss>

