I am trying to create a buffer that will have the distance and units inputted by the user.

This is what displays on my program.

I'm having trouble getting the JavaScript to recognize the which Unit of Measurement the buffer is being set to. When I click on the map to generate the buffer nothing shows up. This is the JavaScript I wrote:

function doBuffer(evt) {
            var params = new esri.tasks.BufferParameters();
            params.geometries = [ evt.mapPoint ];

          //buffer in linear units such as meters, km, miles etc.
            params.distances = [ document.getElementById("distance").value];
            params.unit = document.getElementById("units").value;
            params.outSpatialReference = map.spatialReference;

            gsvc.buffer(params, showBuffer);

This is the HTML I wrote:

 <div id="featureCount">Enter the unit and distance to set the buffer.</div>
                <input id="distance" type="number" name="Distance">
                <p>Unit of Measurement</p>
                <select id="units">
                    <option value="esri.tasks.GeometryService.UNIT_FOOT">Feet (ft)</option>
                    <option value="esri.tasks.GeometryService.UNIT_METER">Meters (m)</option>
                    <option value="esri.tasks.GeometryService.UNIT_KILOMETER">Kilometers (km)</option>
                    <option value="esri.tasks.GeometryService.UNIT_STATUTE_MILE">Miles (mi)</option>
                    <option value="esri.tasks.GeometryService.UNIT_NAUTICAL_MILE">Nautical Miles (NM)</option>

How can I get my code to recognize which unit of measurement I am setting the buffer to so it can load correctly?

  • Without writing out a lot of JS to be sure, try: params.unit = document.getElementById("units").options[document.getElementById("units").selectedIndex].value; reference: stackoverflow.com/questions/1085801/…
    – KHibma
    Jul 17, 2019 at 19:30
  • @KHibma I put this into my code and it did not work. Thank you for trying to help though!
    – Emily Watt
    Jul 17, 2019 at 21:10
  • 1
    It might be your option value. Not sure that you need to pass esri.task..... in. Per the help doc pointing to this: resources.arcgis.com/en/help/arcobjects-cpp/componenthelp/… - it seems to suggest using the value. So unit foot is actually a value of 9002
    – KHibma
    Jul 18, 2019 at 12:17
  • 1
    Compare your code with this sample, which has the same sort of dropdown box for units. Also, are you seeing any messages in the console?
    – kenbuja
    Jul 18, 2019 at 12:43
  • @kenbuja That's actually what I was using to write my code, and no I am not receiving any messages in the console.
    – Emily Watt
    Jul 18, 2019 at 15:02

1 Answer 1


The Unit type for the geometry service accepts the code value. The code value can be found on the esriSRUnitType Constants page.

For example, if you want esriSRUnit_Meter, you can provide the value 9001

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.