Untitled

 avatar
unknown
plain_text
a month ago
3.3 kB
4
Indexable
var area:Double = 0.0
 var cumulativeDistance = 0.0

 var originalArea: Double = 0.0
 var originalDistanceUnit: String = "Meter"
 var originalAreaUnit: String = "Acre"
if (showActionBar.value) {
 CustomTopBar(
 selectedGeometryType = selectedGeometryType,
 onGeometryTypeChange = { selectedGeometryType = it },
 selectedUnit = selectedUnit,
// onUnitChange = { selectedUnit = it },
 onUnitChange = { unit ->
 selectedUnit = unit
// if (selectedGeometryType == "Distance") {
// updateDistanceUnits(unit)
// } else if (selectedGeometryType == "Area") {
// updateAreaUnits(originalArea, unit)
// }
 },
 distanceUnits = distanceUnits,
 areaUnits = areaUnits,
 onShowActionBarChange = { showActionBar.value = it },
 onClearGraphics = {
 clearGraphics()
 linePoints.clear()
 polygonPoints.clear()
 calloutLocation.value = null // Reset callout location
 distanceText.value = " " // Reset distance text
// distanceTextState.value = " "
 areaText.value = " " // Reset area text
 cumulativeDistance = 0.0 // Reset cumulative distance
 },
 pointsDrawn = pointsDrawn,
 polygonSymbol = polygonSymbol

 )
 }
@Composable
 fun CustomTopBar(
 selectedGeometryType: String,
 onGeometryTypeChange: (String) -> Unit,
 selectedUnit: String,
 onUnitChange: (String) -> Unit,
 distanceUnits: List,
 areaUnits: List,
 onShowActionBarChange: (Boolean) -> Unit,
 onClearGraphics: () -> Unit,
 pointsDrawn: Boolean,
 polygonSymbol : Symbol?


 )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")
 polygonPoints.clear()
 polygonPoints.addAll(linePoints)
 convertToArea(polygonSymbol, unit, linePoints.toList(), graphicsOverlay, areaText)
 }
 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, graphicsOverlay: GraphicsOverlay, areaText: MutableState) {
 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.add(polygonGraphic)

 val areaValue = GeometryEngine.areaGeodetic(
 polygon,
 getAreaUnit(selectedUnit),
 GeodeticCurveType.Geodesic
 )

// originalArea = areaValue
// originalAreaUnit = selectedUnit
 areaText.value = formatMeasurementValue(areaValue, selectedUnit)

 }

when 3 or more points drawn in distance either meter or kilometere when area is clicked and the unit might be acre or other it hsould relect the units of area with polygon the above is not reflecting why give correct code shouw gighlights
Editor is loading...
Leave a Comment