AnsweredAssumed Answered

Drop down menu to select GeometryService units

Question asked by AlexSabrina on Oct 30, 2015
Latest reply on Oct 30, 2015 by AlexSabrina

Hi all,

I am trying to create a drop down menu which would allow users to select the unit of their choice when measuring polygons and poly lines.

 

 

Drop down is here:

 

 

<select id="dropdown" class="selectpicker">
                    <option value="UNIT_SQUARE_MILES">Acres</option>
                    <option value="UNIT_ARES">Ares</option>
                    <option value="UNIT_HECTARES">hectares</option>
                    <option value="UNIT_SQUARE_FEET">Square Feet</option>
                    <option value="UNIT_SQUARE_KILOMETERS">Square Kilometers</option>
                    <option value="UNIT_SQUARE_METERS">Square Meters</option>
                    <option value="UNIT_SQUARE_MILES">Square Miles</option>
                </select>

Selected value:

 

var areasUnits = $('option:selected', $('#dropdown')).val();
                    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;
                                var lengthParams = new LengthsParameters();
                                lengthParams.polylines = [geometry];
                                lengthParams.lengthUnit = GeometryService.UNIT_FOOT;
                                lengthParams.geodesic = true;
                                geometryServiceLength.lengths(lengthParams);
                                break;
                            case 'polygon':
                                symbol = tb.fillSymbol;
                                
                                var areasAndLengthParams = new AreasAndLengthsParameters();
                                areasAndLengthParams.areaUnit = GeometryService.areasUnits;
                                areasAndLengthParams.calculationType = "geodesic";
                                geometryService.simplify([geometry], function (simplifiedGeometries) {
                                    areasAndLengthParams.polygons = simplifiedGeometries;
                                    geometryService.areasAndLengths(areasAndLengthParams);
                                });
                                break;
                            case 'freehandpolygon':
                                symbol = tb.fillSymbol;
                                var areasAndLengthParams = new AreasAndLengthsParameters();
                                areasAndLengthParams.areaUnit = GeometryService.UNIT_ACRES;
                                areasAndLengthParams.calculationType = "geodesic";
                                geometryService.simplify([geometry], function (simplifiedGeometries) {
                                    areasAndLengthParams.polygons = simplifiedGeometries;
                                    geometryService.areasAndLengths(areasAndLengthParams);
                                });
                                break;
                            default:
                        }
                    }

 

Any ideas

Outcomes