Untitled
unknown
plain_text
8 months ago
2.7 kB
5
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, unit, linePoints.toList())
}
else {
println("Conditions not met for converting to Area")
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
}
val closedPoints = points.toMutableList().apply { add(points.first()) }
val polygon = Polygon(closedPoints)
graphicsOverlay.graphics.removeIf { it.geometry is Polyline }
val polygonGraphic = Graphic(polygon, polygonSymbol)
graphicsOverlay.graphics.clear()
graphicsOverlay.graphics.add(polygonGraphic)
val areaValue = GeometryEngine.areaGeodetic(
polygon,
getAreaUnit(selectedUnit),
GeodeticCurveType.Geodesic
)
originalArea = areaValue
originalAreaUnit = selectedUnit
areaText.value = formatMeasurementValue(areaValue, selectedUnit)
}Editor is loading...
Leave a Comment