Select to view content in your preferred language

GeometryService (2.0) buffer fails

1316
1
10-13-2010 08:27 AM
TimRourke
Emerging Contributor
I had a function that buffered a point clicked by the user. It worked fine in JSAPI 1.6, and still does. It worked OK in JSAPI 2.0 until a couple of days ago, though the code didn't change. I've had to roll back from 2.0 to 1.6 to keep working but I need to figure this out. Here's the code:

        var geometryService = new esri.tasks.GeometryService(_thisMap.GeometryServiceUrl);
        var params = new esri.tasks.BufferParameters();
        params.geometries = [centerPointGraphic.geometry];
        params.distances = [radius];
        params.unit = esri.tasks.GeometryService.UNIT_STATUTE_MILE;
        params.bufferSpatialReference = new esri.SpatialReference({ wkid: 4326 });
        params.outSpatialReference = new esri.SpatialReference({ wkid: 4326 });
        dojo.connect(geometryService, "onBufferComplete", this, "geometryBufferCompleteCallback");
        geometryService.buffer(params);


If I specify the geometries parameter using centerPointGraphic (as opposed to centerPointGraphic.geometry) (which I did in JSAPI 1.6), I get the error '_837[0].spatialReference is undefined'.

When I set the geometries parameter equal to centerPointGraphic.geometry, the geometryService.buffer call raises an error saying "TypeError: _943.toJson is not a function". It appears that the resulting geometry sees the distance as degrees, even though the units are specified as statute miles (I have tried specifying the units as esri.tasks.BufferParameters.UNIT_STATUTE_MILE (which worked in 1.6) and as esri.tasks.GeometryService.UNIT_STATUTE_MILE (which is in the samples) with the same results.

The input geometry is always a point graphic, with values like x = -93.60528441619863, y = 41.52957219910621. These parameters all work fine when I test the service in the server's ArcGIS/rest/services/Maps/Geometry/GeometryServer/buffer form.

Does anybody have any idea what I'm doing wrong here?
0 Kudos
1 Reply
TimRourke
Emerging Contributor
The problem appears to be related to how Dojo is interpreting objects passed as parameters from one script to another, or in a callback. A center point graphic and a radius get passed to a function after a user enters a map point. Then for some reason, the buffer parameters object doesn't recognize either the graphic or its geometry as valid objects.

I've been able to make this work by changing the script to explicitly create the geometry from the input object:

function getCircleFromPoint(centerPointGraphic, radius)
{
    var geometryService = new esri.tasks.GeometryService(_thisMap.GeometryServiceUrl);
    var point = new esri.geometry.Point(centerPointGraphic.geometry.x,
                                        centerPointGraphic.geometry.y,
                                        new esri.SpatialReference({ wkid: 4326 })
                                        );
    var params = new esri.tasks.BufferParameters();
    params.geometries = [point];
    params.distances = [new Number(radius)];
    params.unit = esri.tasks.GeometryService.UNIT_STATUTE_MILE;
    params.bufferSpatialReference = new esri.SpatialReference({ wkid: 4326 });
    params.outSpatialReference = map.spatialReference;
    var obj = this;
    dojo.connect(geometryService, "onBufferComplete", obj, "geometryBufferCompleteCallback");
    geometryService.buffer(params);
}
The same problem prevented a QueryTask from executing with the circle produced by the buffer call. The solution there was to create a new Polygon and loop through the circle's rings, adding them to the new Polygon's rings and using the new Polygon in the query task.
0 Kudos