Select to view content in your preferred language

Perfrom a queryTask onBufferComplete ??

1093
6
11-28-2011 07:05 AM
DonKang
Regular Contributor
Hello,
I am looking for a ways to create a buffer polygon and would like to select polygon features that are within the created buffer polygon.
Following are what I have so far.

1. Select a parcel polygon
2. With click of a button, "doBuffer" function gets called.
3. Based on the #1 selected parcel, a buffer polygon gets created and added to the map.
4. And then at the buffer "onBufferComplete" event, I would like to execute a query so select
all parcels within the buffer polygon.

This function works up until #3, but nothing happens on #4.

Can anyone see what is wrong with my doBuffer function.
Any suggestion of making this function work. Do any of you have working sample that would like to share?

thanks

Don Kang


function doBuffer() {
            var buffParams = new esri.tasks.BufferParameters();
            var extent = new esri.geometry.Extent(getGraphicsExtent(map.graphics.graphics));
            buffParams.geometries = [extent];  // var val = dojo.byId("txtSearchAPN").value
            buffParams.distances = [dojo.byId('bufferDistance').value];
            buffParams.unit = esri.tasks.GeometryService.UNIT_FOOT;
            buffParams.bufferSpatialReference = new esri.SpatialReference({ wkid: 3421 });
            buffParams.outSpatialReference = map.spatialReference;
            gsvc.buffer(buffParams);

            var link1 = dojo.connect(gsvc, "onBufferComplete", function (geometries) {
                var symbol1 = 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], symbol1);
                map.graphics.add(graphic);

                query.where = "";
                query.geometry = graphic.geometry;
                //query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
                query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_CONTAINS;
    queryTask.execute(query);
    //alert('Hello test');
            });

            var link2 = dojo.connect(queryTask, "onComplete", function (featureSet) {
                alert('Hello test');
                alert(featureSet.features.length);

                dojo.disconnect(link1);
                dojo.disconnect(link2);
            });
        }
0 Kudos
6 Replies
KellyHutchins
Esri Notable Contributor
There's a sample  here that shows this same scenario (Buffer then Select using Buffer):

http://help.arcgis.com/en/webapi/javascript/arcgis/demos/query/query_buffer.html
0 Kudos
DonKang
Regular Contributor
Yes, I've seen the sample and I was able to make the sample to work using my own data.

My task, however, is to query a parcel (or parcels) first.
Using selected parcels, create a buffer and then select parcels within created buffer.

So the difference between the sample and what I am trying to do is,
that I don't require user to click on a map, rather user will click on a button to select inital parcels
and then click on another button to perform a buffer and query.
Again, the buffer portion works but query after the buffer don't seemed to work.

Any thoughts??

Don
0 Kudos
KellyHutchins
Esri Notable Contributor
I modified the sample to use your code (doBuffer) and it worked for me. In my test I just use the map's extent to generate the buffer. Do you see any errors in Firebug or the Chrome Developer Tools console when you run  your 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,IE=9" />

    <!--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.5/js/dojo/dijit/themes/claro/claro.css">

    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.5"></script>

    <script type="text/javascript">

      dojo.require("esri.map");

      dojo.require("esri.tasks.query");

      dojo.require("esri.tasks.geometry");

      

      var queryTask;
      var map;
      var gsvc;


      function init() {

        var startExtent = new esri.geometry.Extent({"xmin":-10605514,"ymin":4712767,"xmax":-10600737,"ymax":4717545,"spatialReference":{"wkid":102100}});

        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.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer");

        map.addLayer(streetMap);

      }



      function initFunctionality(map) {

        queryTask = new esri.tasks.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/0");

        //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 = "http://localhost/proxy/proxy.ashx";

        esriConfig.defaults.io.alwaysUseProxy = false;


        //Geometry Service Endpoint

        gsvc = new esri.tasks.GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
    }

        function doBuffer() {
          var buffParams = new esri.tasks.BufferParameters();
          var extent = map.extent;
          buffParams.geometries = [extent]; 
          buffParams.distances = [dojo.byId('bufferDistance').value];
          buffParams.unit = esri.tasks.GeometryService.UNIT_FOOT;
          buffParams.bufferSpatialReference = new esri.SpatialReference({ wkid: 3421 });
          buffParams.outSpatialReference = map.spatialReference;
          gsvc.buffer(buffParams);

          var link1 = dojo.connect(gsvc, "onBufferComplete", function (geometries) {
            var symbol1 = 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], symbol1);
            map.graphics.add(graphic);

            query = new esri.tasks.Query();

            query.returnGeometry = true;

            query.outFields = ["POP2000","HOUSEHOLDS","HSE_UNITS", "TRACT", "BLOCK"];

            query.where = "";
            query.geometry = graphic.geometry;
 
            query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_CONTAINS;
            queryTask.execute(query);
   
          });

        var link2 = dojo.connect(queryTask, "onComplete", function (featureSet) {
          alert('Hello test');
          alert(featureSet.features.length);

          dojo.disconnect(link1);
          dojo.disconnect(link2);
        });
}

      dojo.addOnLoad(init);

    </script>

  </head>



  <body class="claro">

    Zoom to area and click on map to select census block points within the buffered circle.<br/>

    <input type='button' value='buffer' onclick='doBuffer();' />
    Buffer distance (in kilometers): <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
DonKang
Regular Contributor
Kelly,
thanks for your help.

Below was missing from my application.
Now it is working. thanks for your help.

Don Kang

//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 = "http://localhost/proxy/proxy.ashx";
        esriConfig.defaults.io.alwaysUseProxy = false;
0 Kudos
DonKang
Regular Contributor
Kelly,
Actually, I do get errors... something that you've mentioned on your last posting.
Please take a look at attached image.

I thought my problem was all resolved but after I've tested with Chrome and Firefox, buffer that
works in IE don't seem to work. And the image described error is what I am getting.

Do you have any idea of what is going on??
With your modified code, if works correctly, I should get two popup messages... But I don't get
that. So something is not working correctly.
Can this be related to the browser setting??

thanks

Don Kang
0 Kudos
KellyHutchins
Esri Notable Contributor
Don,

The code works for me (both the buffer and the query. Have you tried adding breakpoints to your code to see if the buffer is successful.
You can also view the requests in the net tab to see if the buffer and query were successful.
0 Kudos