AnsweredAssumed Answered

Zoom to Query Results

Question asked by weiland00 on Jun 4, 2013
Latest reply on Jun 5, 2013 by JGravois-esristaff
HELP!
I am working on a JavaScript web page that does two things:
1) Query a rest service for the attribute information from a single record and then presents it in a table.
2) Builds a map and zooms to the results from the query.

I used the "Query State Info without Map" to start with and to accomplish the first task.  I added a map (basemap plus a couple of additional layers for display).  However, I am unable to extract the geometry from the query results as a point to use when creating the map.

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:

<!DOCTYPE html> <html>  <head>   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">   <meta http-equiv="X-UA-Compatible" content="IE=7, IE=9, IE=10">   <!--The viewport meta tag is used to improve the presentation and behavior of the samples on iOS devices-->   <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">   <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/dojo/dijit/themes/claro/claro.css">   <link rel="stylesheet" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/js/esri/css/esri.css">   <title>Query State Info with Map</title>   <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.5/"></script>   <script>    dojo.require("esri.tasks.query");    dojo.require("esri.map");     var queryTask, query, centerPoint, stateName;     var stateName = "Colorado" /* stateName for QueryTask */     function init() { /* Setup query */     queryTask = new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5");     query = new esri.tasks.Query();     query.returnGeometry = true;     query.outSpatialReference = new esri.SpatialReference({wkid : 102100});     query.outFields = ["STATE_NAME","SQMI","SUB_REGION"];     query.text = stateName;          queryTask.execute(query, showResults);    }     function showResults(results) {     var s = "";     for (var i=0, il=results.features.length; i<il; i++) {      var featureAttributes = results.features[i].attributes;      for (att in featureAttributes) {       s = s + "<b>" + att + ":</b> " + featureAttributes[att] + "<br />";      }     }     dojo.byId("info").innerHTML = s; /* Extract Geometry From Query */     centerPoint = new esri.geometry.Point(getPoint(results)); //Does NOT work- Actual use will be a point layer //    centerPoint = [-122.45, 37.75] //fake point for testing /* Build Map */     map = new esri.Map("map",{ basemap: "topo", center:centerPoint, zoom:13 });      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 */    }    dojo.ready(init);   </script>  </head>  <body class="claro">   <div id="info" style="padding:5px; margin:5px; background-color:#eee;"></div>   <div id="map"></div>  </body> </html>


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?

Thank you,

Outcomes