Untitled

 avatar
unknown
plain_text
a month ago
3.1 kB
4
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")
                                                this@MainScreen.selectedGeometryType = "Area"
                                                
                                                polygonPoints.clear()
                                                polygonPoints.addAll(linePoints)
                                                convertToArea(polygonSymbol, selectedUnit, polygonPoints, 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<Point>, graphicsOverlay: GraphicsOverlay, areaText: MutableState<String>) {
        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)

    }
Editor is loading...
Leave a Comment