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
Solved! Go to Solution.
Alex,
Try
areasAndLengthParams.areaUnit = GeometryService[areasUnits];
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;
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
Alex,
Try
areasAndLengthParams.areaUnit = GeometryService[areasUnits];
That is it! Thanks!