Measurements with Geometry Service

3066
3
Jump to solution
10-29-2015 03:52 PM
AlexGole
Occasional Contributor II

Hi all,

I am using this sample​ to get the measurements for my draw toolbar. It works great. However, I would like, in addition to this to measure polylines as AreaandLength only take polygons as input. To achieve this I am using esri/tasks/LengthsParameters.

The combination of the two work but I keep getting this error: "Error: Unable to complete operation.(…)" altough it returns the right number.

Any idea?

Thanks, Alex

var geometryService = new GeometryService("http://webgisdevint1/arcgis/rest/services/Utilities/Geometry/GeometryServer");
                geometryService.on("areas-and-lengths-complete", outputAreaAndLength);
                var geometryServiceLength = new GeometryService("http://webgisdevint1/arcgis/rest/services/Utilities/Geometry/GeometryServer");
                geometryServiceLength.on("lengths-complete", outputLength);


                //Get graphics to Graphic Layer dedicated for draw
                function addGraphic(evt) {
                    
                    map.graphics.clear();
                    var geometry = evt.geometry;
                    var symbol = dom.byId("symbol").value;
                    if (symbol) {
                        symbol = eval(symbol);
                    } else {
                        switch (geometry.type) {
                            case 'point':
                                symbol = tb.markerSymbol;
                                break;
                            case 'polyline':
                                symbol = tb.lineSymbol;
                                break;
                            case 'polygon':
                                symbol = tb.fillSymbol;
                                break;
                            case 'freehandpolygon':
                                symbol = tb.fillSymbol;
                                break;
                            default:
                        }
                    }


                    var areasAndLengthParams = new AreasAndLengthsParameters();
                    areasAndLengthParams.areaUnit = GeometryService.UNIT_ACRES;
                    areasAndLengthParams.calculationType = "geodesic";
                    geometryService.simplify([geometry], function (simplifiedGeometries) {
                        areasAndLengthParams.polygons = simplifiedGeometries;
                        geometryService.areasAndLengths(areasAndLengthParams);
                    });


                    var lengthParams = new LengthsParameters();
                    lengthParams.polylines = [geometry];
                    lengthParams.lengthUnit = GeometryService.UNIT_METER;
                    lengthParams.geodesic = true;
                    geometryServiceLength.lengths(lengthParams);
                  
                    map.getLayer("drawGL").add(new Graphic(geometry, symbol));
                }
 function outputAreaAndLength(evtObj) {
                    var result = evtObj.result;
                    console.log(json.stringify(result));
                    dom.byId("area").innerHTML = result.areas[0].toFixed(3) + " acres";
                }
                function outputLength(evtObj) {
                    var result = evtObj.result;
                    console.log(json.stringify(result));
                    dom.byId("length").innerHTML = result.lengths[0].toFixed(3) + " feet";
                }
0 Kudos
1 Solution

Accepted Solutions
AlexGole
Occasional Contributor II

Nevermind I found the issue.I dont really know how to delete but here was my solution: put the params in the switch...case. Thanks, Alex

View solution in original post

3 Replies
AlexGole
Occasional Contributor II

Nevermind I found the issue.I dont really know how to delete but here was my solution: put the params in the switch...case. Thanks, Alex

RobertScheitlin__GISP
MVP Emeritus

Alex,

   I don't see an if statement in there where you are checking the geometry type and not sending it to areasAndLengths if it is polyline. So you would receive an unable to complete from areasAndLengths. Also there is no need to have two different GeometryServices you can do both areasAndLengths and lengths with one.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Alex,

   I forgot to refresh my page before I posted. Now I see that you already figured this one out on your own.

0 Kudos