Untitled

 avatar
unknown
plain_text
4 days ago
5.0 kB
3
Indexable
"Distance" -> {
                                    val pointGraphic = Graphic(mapPointNotNull, pointSymbol)
                                    graphicsOverlay.graphics.add(pointGraphic)
                                    relatedGraphics.add(pointGraphic)

                                    linePoints.add(mapPointNotNull)

                                    if (linePoints.size > 1) {
                                        val polyline = Polyline(linePoints)
                                        val lineGraphic = Graphic(polyline, lineSymbol)
                                        graphicsOverlay.graphics.add(lineGraphic)
                                        relatedGraphics.add(lineGraphic)

                                        val distanceValue = GeometryEngine.lengthGeodetic(
                                            polyline,
                                            getLinearUnit(selectedUnit),
                                            GeodeticCurveType.Geodesic
                                        )
                                        cumulativeDistance += distanceValue
                                    }

                                    // Remove previous text symbols
                                    graphicsOverlay.graphics.removeAll { it.symbol is TextSymbol }

                                    // Only add the text symbol at the last point
                                    if (linePoints.size > 1) {
//                                        linePoints.last()
//                                        distance = cumulativeDistance
                                        distanceText.value = formatMeasurementValue(cumulativeDistance, selectedUnit)
//                                        distanceTextState.value = distanceText.valueprivate fun undoLastGraphic() {

        if (graphicsStack.isNotEmpty()) {
            val lastGraphics = graphicsStack.removeAt(graphicsStack.size - 1)
            lastGraphics.forEach { graphic ->
                graphicsOverlay.graphics.remove(graphic)
            }

            if (selectedGeometryType == "Area" && polygonPoints.isNotEmpty()) {
                polygonPoints.removeAt(polygonPoints.size - 1)
                if (polygonPoints.size < 3) {
                    calloutLocation.value = null
                    areaText.value = ""
                } else {
                    convertToArea(polygonSymbol, originalAreaUnit, polygonPoints)
                    val polygon = Polygon(polygonPoints)
                    calloutLocation.value = GeometryEngine.labelPointOrNull(polygon)
                }
            }

            if (selectedGeometryType == "Distance" && linePoints.isNotEmpty()) {
                linePoints.removeAt(linePoints.size - 1)
                if (linePoints.size < 2) {
                    calloutLocation.value = null
                    distanceText.value = ""
                    cumulativeDistance = 0.0
                } else {
                    // Recalculate the cumulative distance after removing the last point
                    cumulativeDistance = 0.0
                    if (linePoints.size>1){
                        for (i in 1 until linePoints.size) {
                            val segment = Polyline(listOf(linePoints[i - 1], linePoints[i]))
                            val segmentLength = GeometryEngine.lengthGeodetic(
                                segment,
                                getLinearUnit(originalDistanceUnit),
                                GeodeticCurveType.Geodesic

                            )
//                        Log.d("tg", "undoLastGraphic: "+linePoints)
//                        Log.d("tg", "undoLastGraphic: "+segment +""+segmentLength)
                            cumulativeDistance += segmentLength
//                        println("Segment $i: ${linePoints[i - 1]} to ${linePoints[i]}, Length: $segmentLength")
                        }
                    }


                    distanceText.value = formatMeasurementValue(cumulativeDistance, originalDistanceUnit)
                    calloutLocation.value = linePoints.lastOrNull()
                }
            }

            if (graphicsOverlay.graphics.isEmpty()) {
                calloutLocation.value = null
            }
        }
    }
    
                                        TextSymbol().apply {
                                            text = distanceText.value
                                            color = com.arcgismaps.Color.fromRgba(0, 0, 0, 255) // Black color
                                            size = 15f
                                        }
                                    }
                                }
                            }
                            graphicsStack.add(relatedGraphics)
                        }
                    }
                }
            )
Editor is loading...
Leave a Comment