AnsweredAssumed Answered

Measurements with Geometry Service

Question asked by AlexSabrina on Oct 29, 2015
Latest reply on Oct 29, 2015 by rscheitlin

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";
                }

Outcomes