Untitled
unknown
plain_text
7 days ago
2.7 kB
2
Indexable
Text(text = "Select Unit", color = Color.Blue) units.forEach { unit -> Row(verticalAlignment = Alignment.CenterVertically) { Checkbox( checked = selectedUnit == unit, onCheckedChange = { isChecked -> if (isChecked) { // selectedUnit = unit onUnitChange(unit) if (selectedGeometryType == "Distance" && areaUnits.contains(unit) &&linePoints.size >= 3){ onGeometryTypeChange("Area") convertToArea(polygonSymbol, selectedUnit, linePoints.toList()) } if (selectedGeometryType == "Distance") { updateDistanceUnits(unit) } else if (selectedGeometryType == "Area") { updateAreaUnits(unit) } } } ) Text(text = unit, modifier = Modifier.padding(4.dp)) } } } } } } } private fun convertToArea(polygonSymbol: Symbol?, selectedUnit: String, points: List<Point>) { if (points.size < 3 || polygonSymbol == null) return // Ensure at least 3 points exist before converting to area val closedPoints = points.toMutableList() closedPoints.add(points.first()) val polygon = Polygon(closedPoints) // Convert the line points into a polygon val polygonGraphic = Graphic(polygon, polygonSymbol) // Remove previous distance-related graphics graphicsOverlay.graphics.clear() // Add the polygon graphic to the overlay graphicsOverlay.graphics.add(polygonGraphic) // Calculate the area of the polygon val areaValue = GeometryEngine.areaGeodetic( polygon, getAreaUnit(selectedUnit), GeodeticCurveType.Geodesic ) // areaText.value = formatMeasurementValue(areaValue, selectedUnit) originalArea = areaValue originalAreaUnit = selectedUnit updateAreaUnits(selectedUnit) }
Editor is loading...
Leave a Comment