Need help activating buffer query with button

Discussion created by jmaxwell1562 on Apr 22, 2011
Latest reply on Apr 22, 2011 by hzhu
I have tried a few ways to activate my buffer query with a button, but (being a newbie), I have failed. The buffer I have set up works, but since I'm also going to have an identify button on the page, I need to have the user activate the buffer query with a button as well. Otherwise the buffer will run everytime the user clicks to identify a feature. I know how to toggle an identify task off and on, but I can't figure out how to control the buffer.

Anyhelp would be appreciated.

Here's the code

<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="">

<script type="text/javascript" src=""></script>
<script type="text/javascript">

var bufferqueryTask;

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

//after map loads, connect to listen to mouse move & drag events
          dojo.connect(map, "onMouseMove", showCoordinates);
var streetMap = new esri.layers.ArcGISDynamicMapServiceLayer("");

var gap = new esri.layers.ArcGISDynamicMapServiceLayer("");

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.
// = "/arcgisserver/apis/javascript/proxy/proxy.ashx";
// = false;
// = "/arcgisserver/proxy/proxy.ashx";
// = ""; = "";
// = ""; = false;

//Geometry Service Endpoint
var gsvc = new esri.tasks.GeometryService("");
bufferqueryTask = new esri.tasks.QueryTask("");

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

// +++++Listen for map onClick event+++++
dojo.connect(map, "onClick", function(evt) {;
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});
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);;

bufferquery.returnGeometry = true;

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

// +++++Listen for QueryTask executecomplete event+++++
dojo.connect(bufferqueryTask, "onComplete", function(fset) {
//create symbol for selected features
var symbol = new esri.symbol.SimpleMarkerSymbol(); = esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE;
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++) {
var graphic = resultFeatures[i];
var pareas = returnRecordNums(fset);
var r = "";
r = "<b>The protected areas 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;

function showCoordinates(evt) {
        //get mapPoint from event
        var mp = evt.mapPoint;
        //display mouse coordinates
        dojo.byId("info").innerHTML = mp.x + ", " + mp.y;

<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" onkeydown="if (event.keyCode == 13) document.getElementById('btnSearch').click()"/>
   <form action="">
      Buffer distance :
      <input type="text" id="bufferDistance" value="1" />
      <input type="button" value="Get Details"
onclick="execute(dojo.byId('b').value);" />

<div id="job"></div>
<div id="mapDiv" style="width: 850px; height:500px; position:relative;">
        <span id="info" style="position:absolute; right:25px; bottom:5px; color:#000; z-index:50;"></span>

<span id="messages"></span>