Untitled
unknown
plain_text
8 months ago
4.4 kB
7
Indexable
when (selectedGeometryType) {
"Area" -> {
val pointGraphic = Graphic(mapPoint, pointSymbol)
graphicsOverlay.graphics.add(pointGraphic)
relatedGraphics.add(pointGraphic)
polygonPoints.add(mapPointNotNull)
if (polygonPoints.size > 1) {
val polyline = Polyline(polygonPoints)
val lineGraphic = Graphic(polyline, lineSymbol)
graphicsOverlay.graphics.add(lineGraphic)
relatedGraphics.add(lineGraphic)
// Remove previous text symbols
graphicsOverlay.graphics.removeAll { it.symbol is TextSymbol }
if (polygonPoints.size > 2) {
val polygon = Polygon(polygonPoints)
val polygonGraphic = Graphic(polygon, polygonSymbol)
graphicsOverlay.graphics.add(polygonGraphic)
relatedGraphics.add(polygonGraphic)
val areaValue = GeometryEngine.areaGeodetic(
polygon,
getAreaUnit(selectedUnit),
GeodeticCurveType.Geodesic
)
val centroid = GeometryEngine.labelPointOrNull(polygon)
calloutLocation.value = centroid
//
area = areaValue
// originalAreaUnit = selectedUnit
areaText.value = formatMeasurementValue(
areaValue,
selectedUnit
) // Update area text
// calloutLocation.value = GeometryEngine.labelPointOrNull(polygon)
} else {
val distanceValue = GeometryEngine.lengthGeodetic(
polyline,
getLinearUnit(selectedUnit),
GeodeticCurveType.Geodesic
)
distance = distanceValue
distanceText.value = formatMeasurementValue(
distanceValue,
selectedUnit
) // Update area text
// distanceTextState.postValue(distanceValue.toString())
}
}
}
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,
graphicsOverlay,
areaText
)
val polygon = Polygon(polygonPoints)
calloutLocation.value = GeometryEngine.labelPointOrNull(polygon)
}
}Editor is loading...
Leave a Comment