Select to view content in your preferred language

Drop down menu to select GeometryService units

2525
4
Jump to solution
10-30-2015 01:00 PM
AlexGole
Deactivated User

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

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Alex,

   Try

areasAndLengthParams.areaUnit = GeometryService[areasUnits];

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

Alex,

   The values of the combobox will have to change based on whether it is a polygon or a poly line.

Line 23 you have areasAndLengthParams.areaUnit = GeometryService.areasUnits; I think you are wanting:

areasAndLengthParams.areaUnit = areasUnits;

0 Kudos
AlexGole
Deactivated User

Robert, That is right I will differentiate between polygons and polylines later. I am testing on polygons for now. I tried your idea, I got "Invalid or missing input parameters.(…)" it seems like I need to "GeometryService.UNITNAME" to define the param correctly. Thanks, Alex

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Alex,

   Try

areasAndLengthParams.areaUnit = GeometryService[areasUnits];

AlexGole
Deactivated User

That is it! Thanks!

0 Kudos