Solved! Go to Solution.
// dojo.map returns an array // fl is your feature layer var geoms = dojo.map(fl.graphics, function(g) { return g.geometry; }); params.geometries = geoms
Take the geometries from your feature layer and specify them as your params.geometries. Something like this:// dojo.map returns an array // fl is your feature layer var geoms = dojo.map(fl.graphics, function(g) { return g.geometry; }); params.geometries = geoms
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <!-- The HEAD section is the section of code which references and loads all scripts before it is shown on the webpage --> <head> <title>XXX</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <meta http-equiv="X-UA-Compatible" content="IE=7" /> <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.8/js/dojo/dijit/themes/nihilo/nihilo.css"> <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.8/js/esri/dijit/css/Popup.css"/> <!--Script 1 loads the Javascript API files --> <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.8"></script> <!--Script 2 is where all the code written is executed --> <script type="text/javascript"> //The code script is split into three sections; //(1) Reference of a package: Packages are bundles of resources which enable features to work. For adding maps for example // the dojo (the underlying basis for Javascript) needs to pull in the 'map' package, hence dojo.require("esri.map") which // enables the browser to work with maps //(2) Initialisation function(s): The initialisation function(s) are in essence a loading function which adds layers to the map and executes // a range of code / processes. As layers can't be physically added, they are pulled from a webservice where appropriate. //(3) Script Load: This function runs the specified script, but ensures that the script only runs once the HTML webpage is loaded. This // is important as it stops the scripts running BEFORE the map baselayer is loaded. //(1) Packages import // .require is basically an 'include' function which brings in the resources to display maps dojo.require("esri.map"); // creates the map class for all elements to be loaded into dojo.require("esri.tasks.query"); // retrieves features from a map layer based on geography or attribute conditions. dojo.require("esri.tasks.geometry"); //gives you access to an ArcGIS Server geometry service that can buffer, project, and simplify geometries dojo.require("esri.layers.FeatureLayer"); //enables loading of feature layers //Pre-load the variables to be used in the script - saves time and memory in terms of processing //Base Variables var map var BaseMap //Layer Variables var Lyr_StrokeUnits var Lyr_UKPopData //Task Variables var queryTask var gsvc //(2) Initialisation functions //(2.1) Creates a function called init which adds the base map and feature layers used in the map function init() { //Set the map extent and spatial reference var ExtentAndSR = new esri.geometry.Extent(-65000,6000000,-800000,8700000,new esri.SpatialReference({"wkid":3857})); //Creates the Map container / object var map = new esri.Map("map",{extent:ExtentAndSR}); //Defines what the variable 'map' does. In this case, it is defined as a Map Class (esri.map) //and the 'map' segment provides it with a reference to be displayed in the webpage (ie: The DIV //is an object visible in the webpage. As map pulls map data, it is then 'translated' to the DIV //element so that it can be shown on the map //Listens for when the Map Container is loaded and then adds query functionality in a seperate function after the init script dojo.connect(map, "onLoad", initFunctionality); //Basemap //The underlying raster basemap used in the web portal var BaseMap = new //This line and the next defines the variable 'BaseMap' and what basemap will be used esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"); //Creates the reference for the variable (ie: where it is coming from) map.addLayer(BaseMap); //This adds this layer to the 'base' layer of "map" //Layers //Layers are loaded in succession - the last layer will be the 'top' layer and so on: //Lyr_UKPopData var Lyr_UKPopData = new esri.layers.FeatureLayer("xxx", { mode : esri.layers.FeatureLayer.MODE_ONDEMAND}); map.addLayer(Lyr_UKPopData); //Lyr_StrokeUnits var Lyr_StrokeUnits = new esri.layers.FeatureLayer("xxx", { mode : esri.layers.FeatureLayer.MODE_ONDEMAND}); map.addLayer(Lyr_StrokeUnits); } //(2.2) Creates a function called initFunctionality(map) which contains the querying scripts for buffer analysis function initFunctionality(map) { //Geometry Service Endpoint var gsvc = new esri.tasks.GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); } function drawBuffer() { var buffParams = new esri.tasks.BufferParameters(); var flgeom = dojo.map(Lyr_StrokeUnits.graphics, function(g) { return g.geometry; }); buffParams.geometries = flgeom; buffParams.distances = [dojo.byId('bufferDistance').value]; buffParams.unit = esri.tasks.GeometryService.UNIT_STATUTE_MILE; buffParams.bufferSpatialReference = new esri.SpatialReference({wkid:3857}); buffParams.outSpatialReference = map.spatialReference; gsvc.buffer(buffParams, bufferDraw); var bufferDraw = dojo.connect(gsvc, "onBufferComplete", function (geometries) { 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])); var graphic = new esri.Graphic(geometries[0], symbol); map.graphics.add(graphic); }); } //(3) Script Load dojo.addOnLoad(init); </script> </head> <!-- The BODY section which determines the style and positioning of elements in the webpage --> <body> <body class="nihilo"> TEST<br> Buffer distance (Miles): <input type="text" id="bufferDistance" value="10" size="5"/><input type='button' value='Draw Buffer' onclick='drawBuffer()'/><br> <div id="map" style="width: 100%; height: 800px; margin: 0;"></div> <span id="messages"></span> </body> </html>