Untitled
unknown
plain_text
8 months ago
2.6 kB
5
Indexable
var selectedUnit by remember { mutableStateOf("Meter") }
if (selectedGeometryType == "Area" && selectedUnit !in areaUnits) {
selectedUnit = "Acre"
}
Text(text = "Select Unit", color = Color.Blue)
units.forEach { unit ->
Row(verticalAlignment = Alignment.CenterVertically) {
Checkbox(
checked = selectedUnit == unit,
onCheckedChange = {
if (it) {
selectedUnit = unit
onUnitChange(unit)
if (selectedGeometryType == "Distance" && areaUnits.contains(unit) &&linePoints.size >= 3){
selectedGeometryType = "Area"
convertToArea()
}
if (selectedGeometryType == "Distance") {
updateDistanceUnits(unit)
} else if (selectedGeometryType == "Area") {
updateAreaUnits(unit)
}
}
}
)
Text(text = unit, modifier = Modifier.padding(4.dp))
}
}
}
}
}
}
}
private fun convertToArea() {
if (linePoints.size < 3) return // Ensure at least 3 points exist before converting to area
val polygon = Polygon(linePoints) // 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
)
area = areaValue
areaText.value = formatMeasurementValue(areaValue, selectedUnit)
}
Editor is loading...
Leave a Comment