AnsweredAssumed Answered

Creating a customisable buffer around points in a feature layer - Javascript API

Question asked by rpudney on May 23, 2012
Latest reply on May 24, 2012 by DSwingley-esristaff
Hi,

I am sorry if this has been posted before - but I have searched the forums before posting and haven't come across anything so my apologies if there is a solution already. I am new to Javascript and am trying to put together a web page which enables me to do the following:


  • Show layers from my ArcGIS Server

  • Enable the user to draw a buffer around the point level feature layer I have in my map (and be able to determine the size of the buffer)

  • Do a query on another polygon layer I have from my Server which intersects with the buffer and provides a sum of the values in a given field column

I am only interested at this stage in finding out how to do the second point and wondered if anyone could help me? I have copy/pasted the ArcGIS resources code for creating a buffer on a click event and inserted into my code below.


The steps I need to understand are:

- How do I make the script draw the buffer around my point layer (it is named asa variable 'Lyr_StrokeUnits') ?

- How do I make the script draw the buffers without the 'onClick' event and instead to draw the buffers dependent on a user input? (Ideally I want the user to be able to input the buffer radius value as they can now and then to be able to press a button to redraw the buffers for all points)


I would be very grateful for any help anyone could give me on this issue.


Kind regards,

Ross



The relevant code below:


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.
        esri.config.defaults.io.proxyUrl = "/arcgisserver/apis/javascript/proxy/proxy.ashx";
        esri.config.defaults.io.alwaysUseProxy = false;


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

        //Listens for an onClick event in the map
        dojo.connect(map, "onClick", function(evt) {
          map.graphics.clear();
          var params = new esri.tasks.BufferParameters();
          params.geometries  = [ evt.mapPoint) ];

          //Sets the parameters for the buffer in miles and creates the buffer in code, but DOESNT display it
          params.distances = [ dojo.byId('bufferDistance').value ]; //'bufferDistance' is a variable which the user inputs on the main page - found in body code
          params.unit = esri.tasks.GeometryService.UNIT_STATUTE_MILE; // standard miles
          params.bufferSpatialReference = new esri.SpatialReference({wkid: 3857}); //Sets the SRID for the buffer
          params.outSpatialReference = map.spatialReference; //Sets the SRID for the output of the buffer service
          gsvc.buffer(params);
          dojo.byId('messages').innerHTML = "<b>Creating Buffer</b>";
        });

        //Listens for GeometryService onBufferComplete event and then draws the buffer onto the map
        dojo.connect(gsvc, "onBufferComplete", function(geometries) { //gsvc is the centrepoint location where the initial click is recorded
          var symbol = new esri.symbol.SimpleFillSymbol("none", new esri.symbol.SimpleLineSymbol("solid", new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.25])); // creates the buffer symbol
          var graphic = new esri.Graphic(geometries[0],symbol); //creates the buffer graphic which is actually displayed onto the map
          map.graphics.add(graphic); //Adds the buffer to the map
          dojo.byId('messages').innerHTML = "<b>Draw Buffer Complete.</b>";
        });

     }

Outcomes