Select to view content in your preferred language

Trouble with buffer query not returning results

1907
8
04-06-2011 03:15 PM
JillMaxwell
Emerging Contributor
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)
            var graphic = resultFeatures;
            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.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>
0 Kudos
8 Replies
SiqiLi
by Esri Contributor
Esri Contributor
After I change your proxy page to mine, the code works fine. Please see the attached screen shot.
e.g. esriConfig.defaults.io.proxyUrl = "http://<server name>/proxy/proxy.ashx";

In the proxy.config file, make sure you have set the serverURL of your ArcGIS services:
e.g.
    <serverUrl url="http://dingo.gapanalysisprogram.com/ArcGIS/rest/services/"
               matchAll="true"></serverUrl>

Try to run your application via server URL in the browser: e.g. http://<server name>/bufferTest.html , instead of just double clicking the html file.

Use firebug or fiddler to check if there is any error returns while running the application.
0 Kudos
JillMaxwell
Emerging Contributor
After I change your proxy page to mine, the code works fine. Please see the attached screen shot.
e.g. esriConfig.defaults.io.proxyUrl = "http://<server name>/proxy/proxy.ashx";

In the proxy.config file, make sure you have set the serverURL of your ArcGIS services:
e.g.
    <serverUrl url="http://dingo.gapanalysisprogram.com/ArcGIS/rest/services/"
               matchAll="true"></serverUrl>

Try to run your application via server URL in the browser: e.g. http://<server name>/bufferTest.html , instead of just double clicking the html file.

Use firebug or fiddler to check if there is any error returns while running the application.


If my webserver is IIS, can I use the proxy.ashx configuration, or do I need the javascript.  Here's a link to the proxy file I wrote yesterday, which is apparently not working. Http://www.gap.uidaho.edu/proxy_ags/jsp.  Is it sitting in the wrong place?
0 Kudos
SiqiLi
by Esri Contributor
Esri Contributor
If my webserver is IIS, can I use the proxy.ashx configuration, or do I need the javascript.  Here's a link to the proxy file I wrote yesterday, which is apparently not working. Http://www.gap.uidaho.edu/proxy_ags/jsp.  Is it sitting in the wrong place?


If your server is IIS, then you need to use proxy.ashx. If your service is Java, e.g. Tomcat, then you need to to use proxy.jsp. I can't download your proxy page via the above link.

Here is the proxy page documentation, you need to download the one under the ASP.NET section (proxypage_net.zip). Put both of them onto the IIS root folder.
http://help.arcgis.com/en/webapi/javascript/arcgis/help/jshelp_start.htm#jshelp/ags_proxy.htm
0 Kudos
S_Ector
Emerging Contributor
After I change your proxy page to mine, the code works fine. Please see the attached screen shot.
e.g. esriConfig.defaults.io.proxyUrl = "http://<server name>/proxy/proxy.ashx";

In the proxy.config file, make sure you have set the serverURL of your ArcGIS services:
e.g.
    <serverUrl url="http://dingo.gapanalysisprogram.com/ArcGIS/rest/services/"
               matchAll="true"></serverUrl>

Try to run your application via server URL in the browser: e.g. http://<server name>/bufferTest.html , instead of just double clicking the html file.

Use firebug or fiddler to check if there is any error returns while running the application.


I've been stumped on a similar issue for a week and this suggestion fixed my problem!!  Thanks!!
0 Kudos
JillMaxwell
Emerging Contributor
After I change your proxy page to mine, the code works fine. Please see the attached screen shot.
e.g. esriConfig.defaults.io.proxyUrl = "http://<server name>/proxy/proxy.ashx";

In the proxy.config file, make sure you have set the serverURL of your ArcGIS services:
e.g.
<serverUrl url="http://dingo.gapanalysisprogram.com/ArcGIS/rest/services/"
matchAll="true"></serverUrl>

Try to run your application via server URL in the browser: e.g. http://<server name>/bufferTest.html , instead of just double clicking the html file.

Use firebug or fiddler to check if there is any error returns while running the application.


Thanks for all your help.  I am making progress.  I had the proxy in the wrong place.  The query is working fine now within my development environment. (I'm using Aptana Studio.)

So, here's the new problem.  When I run the query in Aptana it works great, but when I try to run it through the browser, the query fails.  Here's the error message from Firefox:

  "Error: Unable to load http://dingo.gapanalysisprogram.com/proxy.ashx?http://dingo.gapanalysisprogram.com/ArcGIS/rest/servi... status:0
Error(undefined=""Unable to load http://...erver/0/query status:0"") (line 0)
undefined = ""Unable to load http://...erver/0/query status:0""

I am getting this same error when I point the query at a different mapservice, and when I try to run a different query in a different app:  http://gap.uidaho.edu/temp/querybycounty.htm.

What should I try now?
0 Kudos
SiqiLi
by Esri Contributor
Esri Contributor
When I run the query in Aptana it works great, but when I try to run it through the browser, the query fails.  Here's the error message from Firefox:

  "Error: Unable to load http://dingo.gapanalysisprogram.com/proxy.ashx?http://dingo.gapanalysisprogram.com/ArcGIS/rest/servi... status:0
Error(undefined=""Unable to load http://...erver/0/query status:0"") (line 0)
undefined = ""Unable to load http://...erver/0/query status:0""


Here are something you can check:
1. Did you put your html in the IIS wwwroot folder?
2. Did you run the html via http://gap.uidaho.edu/xxx.html
3. Did you put both the proxy.ashx and proxy.config files in the IIS wwwroot folder?
4. Did you change the code in the html to refer to the correct proxy page.
5. Try to clear the browser cache.
6. I just checked your other application. Firebug returns error shows not able to load the proxy page.
0 Kudos
JillMaxwell
Emerging Contributor
Here are something you can check:
1. Did you put your html in the IIS wwwroot folder?
2. Did you run the html via http://gap.uidaho.edu/xxx.html
3. Did you put both the proxy.ashx and proxy.config files in the IIS wwwroot folder?
4. Did you change the code in the html to refer to the correct proxy page.
5. Try to clear the browser cache.
6. I just checked your other application. Firebug returns error shows not able to load the proxy page.


Thank you so much!  When I put the html file into the IIS wwwroot folder of the same computer that is hosting the arcgis services, it works perfectly.   I can live with this!  However, how would I need to configure this if the webserver and the arcgis servers are different machines?
0 Kudos
SiqiLi
by Esri Contributor
Esri Contributor
Thank you so much!  When I put the html file into the IIS wwwroot folder of the same computer that is hosting the arcgis services, it works perfectly.   I can live with this!  However, how would I need to configure this if the webserver and the arcgis servers are different machines?


If your web server and ArcGIS Server are two different machines, then put your html and proxy page on the IIS wwwroot of the web server. In the html and proxy page,  point to the services which are hold on the ArcGIS Server.
0 Kudos