jmaxwell1562

Trouble with buffer query not returning results

Discussion created by jmaxwell1562 on Apr 6, 2011
Latest reply on Apr 11, 2011 by sli-esristaff
Hi:  I am following the example query with buffer example: http://help.arcgis.com/en/webapi/javascript/arcgis/demos/query/query_buffer.html

I am getting the buffer to draw, but no results are being returned.

I can't figure out what's wrong and would appreciate any help.

Thanks.

________________________________

Here is my code: 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=7" />
    <!--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"/>
    <title>QueryTask with query geometry from another task</title>
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.1/js/dojo/dijit/themes/claro/claro.css">

    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.1"></script>
    <script type="text/javascript">
      dojo.require("esri.map");
      dojo.require("esri.tasks.query");
      dojo.require("esri.tasks.geometry");

      var queryTask
     
   /*Initialize map, buffer, & query params*/
      function init() {
    var startExtent = new esri.geometry.Extent({"xmin":3336800.8350631,"ymin":2636200.25720764,"xmax":6477996.0793392,"ymax":5025218.13686783,"spatialReference":{"wkid":3089}});
    var map = new esri.Map("mapDiv", {extent:startExtent});
    //listen for when map is loaded and then add query functionality
        dojo.connect(map, "onLoad", initFunctionality);

        var streetMap = new esri.layers.ArcGISDynamicMapServiceLayer("http://dingo.gapanalysisprogram.com/ArcGIS/rest/services/PADUS/PADUS_status/MapServer");
        map.addLayer(streetMap);
       
         
var gap = new esri.layers.ArcGISDynamicMapServiceLayer("http://dingo.gapanalysisprogram.com/ArcGIS/rest/services/PADUS/Ancillary/MapServer");
       map.addLayer(gap);
       }

      function initFunctionality(map) {
        //identify proxy page to use if the toJson payload to the geometry service is greater than 2000 characters.
        //If this null or not available the buffer operation will not work.  Otherwise it will do a http post to the proxy.
    //esriConfig.defaults.io.proxyUrl = "/arcgisserver/apis/javascript/proxy/proxy.ashx";
        //esriConfig.defaults.io.alwaysUseProxy = false;
    //esriConfig.defaults.io.proxyUrl = "/arcgisserver/proxy/proxy.ashx";
                esriConfig.defaults.io.proxyUrl = "http://www.gap.uidaho.edu/proxy_ags.jsp";

   
    esriConfig.defaults.io.alwaysUseProxy = false;

        //Geometry Service Endpoint
        var gsvc = new esri.tasks.GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
    queryTask = new esri.tasks.QueryTask("http://dingo.gapanalysisprogram.com/ArcGIS/rest/services/PADUS/PADUS_status/MapServer/0");

    // Query
    var query = new esri.tasks.Query();

        // +++++Listen for map onClick event+++++
        dojo.connect(map, "onClick", function(evt) {
     map.graphics.clear();
          var params = new esri.tasks.BufferParameters();
          params.geometries  = [ evt.mapPoint ];
          // Buffer in linear units such as meters, km, miles etc.
          params.distances = [ dojo.byId('bufferDistance').value ];
          params.unit = esri.tasks.GeometryService.UNIT_STATUTE_MILE;
          params.bufferSpatialReference = new esri.SpatialReference({"wkid": 3089});
         params.outSpatialReference = new esri.SpatialReference({"wkid": 3089});
          gsvc.buffer(params);
          dojo.byId('messages').innerHTML = "<b>Creating Buffer Using Geometry Service...</b>";
        });

        // +++++Listen for GeometryService onBufferComplete event+++++
        dojo.connect(gsvc, "onBufferComplete", function(geometries) {
          var symbol = new esri.symbol.SimpleFillSymbol("none", new esri.symbol.SimpleLineSymbol("dashdot", new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.25]));
          var graphic = new esri.Graphic(geometries[0],symbol);
     map.graphics.add(graphic);

       query.returnGeometry = true;
              
      query.outFields =  ["P_Des_Nm","P_Loc_Nm","Own_Name","Mang_Name"];
     query.outSpatialReference = map.spatialReference;
     query.geometry = geometries[0];
     //query.where = "quadrangle_name='Adairville'"
     queryTask.execute(query);
          dojo.byId('messages').innerHTML = "<b>Executing Query with Result Buffer Geometry...</b>";
        });

        // +++++Listen for QueryTask executecomplete event+++++
        dojo.connect(queryTask, "onComplete", function(fset) {
          //create symbol for selected features
          var symbol = new esri.symbol.SimpleMarkerSymbol();
          symbol.style = esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE;
          symbol.setSize(8);
          symbol.setColor(new dojo.Color([255,255,0,0.5]));

          //var infoTemplate = new esri.InfoTemplate("Block: ${BLOCK}", "${*}");
          var resultFeatures = fset.features;
          for (var i=0, il=resultFeatures.length; i<il; i++) {
      console.log(resultFeatures[i])
            var graphic = resultFeatures[i];
            graphic.setSymbol(symbol);
            map.graphics.add(graphic);
          }
     var pareas = returnRecordNums(fset);
     var r = "";
     r = "<b>The record numbers within the buffer are <i>" + pareas + "</i>.</b>";
     dojo.byId('messages').innerHTML = r;
        });
      }

   function returnRecordNums(fset){
    var features = fset.features;
    var pas = "";
    for (var x = 0; x < features.length; x++) {
     pas = pas + ", " + features[x].attributes['P_Des_Nm'];
    }
    return pas;
   }


      dojo.addOnLoad(init);
    </script>
  </head>

  <body class="claro">
    Zoom to area and click on map to select protected areas within the buffered circle.<br/>
    Buffer distance (in miles): <input type="text" id="bufferDistance" value="1" size="5"/>

    <div id="mapDiv" style="width: 500px; height:500px;"></div>
    <span id="messages"></span>
  </body>
</html>

Outcomes