Select to view content in your preferred language

Buffer query result polygon

2119
15
08-01-2012 09:05 AM
DonCaviness
Occasional Contributor
I am trying to buffer the result of a query which is a polygon.  I have tried several different approaches but my code always fails when calling the geometry service's buffer function.  Once I buffer the selected polygon (the query result) I'm going to use the geometry of the buffer to do a spatial query.  Can anyone see what is the issue with my code?  Thanks, Don.

function performParcelSearch(){
    var parcelVal = $("#inputParcel").val();
    var bufferDist = $("#inputBuffer").val();
    var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]));
    var queryTask = new esri.tasks.QueryTask(searchLayer);
    if (!parcelVal) {
        alert("Please enter a parcel number.");
    }
    else {
        var qryExp = "parcel_f = '" + parcelVal + "'";
        //initialize query
        var parcelQuery = new esri.tasks.Query();
        parcelQuery.returnGeometry = true;
        parcelQuery.outFields = ["*"];
        parcelQuery.where = qryExp;
        
        //execute query
        queryTask.execute(parcelQuery, function showResults(featureSet){
            //remove all graphics on the maps graphics layer
            map.graphics.clear();
            var features = featureSet.features;
            
            //QueryTask returns a featureSet.  Loop through features in the featureSet and add them to the map.
            dojo.forEach(features, function(feature){
                var graphic = feature;
                graphic.setSymbol(symbol);
                console.log("BB");
                
                //Add graphic to the map graphics layer.
                var featureextent = graphic.geometry.getExtent();
                map.setExtent(featureextent, true);
                map.graphics.add(graphic);
                
                /*------------------------------------*/
                // Performs Buffer Search
                /*------------------------------------*/
                if (bufferDist > 0) {
                
                    $("#exportDiv").show("slow");
                    $("#bufferResultsDiv").show("slow");
                    var params = new esri.tasks.BufferParameters();
                    params.distances = bufferDist;
                    params.bufferSpatialReference = map.spatialReference;
                    params.outSpatialReference = map.spatialReference;
                    params.unit = esri.tasks.GeometryService.UNIT_FOOT;
                    params.geometries = feature.geometry;
                    
     geometryService.buffer(params, showBuffer);
                }
            });
        });
    }
}
0 Kudos
15 Replies
StephenLead
Honored Contributor
my code always fails when calling the geometry service's buffer function.
geometryService.buffer(params, showBuffer);


I haven't stepped through your code, but are you sure that there's a showBuffer function (I can't see it in your extract)? This is what will run once the buffer operation is complete.

If so, can you put a breakpoint on the first line of showBuffer and let us know what you see? According to the help file you should receive back an array of geometries.

Steve
0 Kudos
DonCaviness
Occasional Contributor
Thanks Steve.  However I only posted a snippet of my code and I didn't include the showBuffer function, that is why you don't see it.  With that being said, the function is never getting called.  In fact, the geometry service is not getting called at all.
geometryService.buffer(params, showBuffer);
I have used firebug and fiddler but the code is never calling the service.  I am beginning to think there is a bug in the JS API.  The generic error that I get is always with the api.  I think that when I get the geometry from the query featureSet, the geometry isn't formatted correctly for the geometry service.  Of course, I could be missing something all together.  I welcome any suggestions.
0 Kudos
ReneRubalcava
Honored Contributor
Try parseInt on your bufferDist value.
This line is returning your value as a string.
var bufferDist = $("#inputBuffer").val();
0 Kudos
DonCaviness
Occasional Contributor
I tried your suggestion Rene but that didn't seem to have an effect on anything.  The geometry service still isn't being called.  From looking at the code, do you any reason why what I'm trying to do wouldn't work?  I have seen the Esri samples that pass an user drawn geometry to the geometry service to perform a buffer.  I just don't see why what I'm trying to do won't work.  I have tried everything I know to try.  I have done this exact thing using the flex api but I just can't get it to work  with the js api.  What am I missing?
0 Kudos
ReneRubalcava
Honored Contributor
Without running it the only thing that stands out as a possibility is this line.
params.geometries = feature.geometry;


I think it needs to be passed as an array.
params.geometries = [ feature.geometry ];


That's how the ref shows it.
http://help.arcgis.com/EN/webapi/javascript/arcgis/help/jsapi/bufferparameters.htm#geometries

Other than that, not too sure.
0 Kudos
DonCaviness
Occasional Contributor
I have tried that before but I just tried it again and it still had no effect.  The geometry service still isn't getting called.  I have attached the error I'm getting in firebug.


[ATTACH=CONFIG]16601[/ATTACH]
0 Kudos
ReneRubalcava
Honored Contributor
This is v3.0 right? I heard someone comment that if your dojo.Config has { async: true }, that the geometry service may not work properly. I was never able to confirm it, but I just remembered right now.
0 Kudos
DonCaviness
Occasional Contributor
I do not have async: true in the dojo.config.  I am using version 3.0 but I was having the same issues with version 2.8.  This has just completely confused/frustrated me as to why it isn't working.  It seems so simple what I'm trying to accomplish.
0 Kudos
DonCaviness
Occasional Contributor
I've tested this in versions 2.8, 3.0 and 3.1 of the JS api and the geometry service still isn't getting called.  Does anyone have any ideas on how to get this to work?
0 Kudos