FeatureInfo Widget hinzugefügt

This commit is contained in:
2026-01-19 21:40:57 +01:00
parent c9b2b262a8
commit 33e95641d0
3 changed files with 112 additions and 64 deletions

View File

@@ -40,7 +40,8 @@ class MapViewModel(application: Application) : AndroidViewModel(application) {
private set
var reopenReport by mutableStateOf(false)
private set
var showFeatureInfo by mutableStateOf(false)
private set
var selectedFeature: ArcGISFeature? by mutableStateOf(null)
val mapViewProxy = MapViewProxy()
var reportDraft by mutableStateOf(ReportDraft())
@@ -63,7 +64,7 @@ class MapViewModel(application: Application) : AndroidViewModel(application) {
init {
tempOverlay.graphics.add(pointGraphic)
viewModelScope.launch {
serviceFeatureTable = ServiceFeatureTable("https://services9.arcgis.com/UVxdrlZq3S3gqt7w/arcgis/rest/services/si_StrassenSchaeden/FeatureServer/0")
serviceFeatureTable = ServiceFeatureTable("https://services9.arcgis.com/UVxdrlZq3S3gqt7w/arcgis/rest/services/251120_StrassenSchaeden/FeatureServer/0")
serviceFeatureTable.load().onSuccess {
val typeDamageField = serviceFeatureTable.fields.firstOrNull { it.name == "Typ" }
val attributeDomain = typeDamageField?.domain as? CodedValueDomain
@@ -79,55 +80,6 @@ class MapViewModel(application: Application) : AndroidViewModel(application) {
}
}
fun createFeatureAtCurrentLocation(
beschreibung: String,
typ: String,
photos: List<ImageBitmap> = emptyList()
) {
viewModelScope.launch {
println("DEBUG: createFeature gestartet") // Erscheint das in der Logcat?
try {
// 1. Location prüfen
val locationData = locationDisplay?.location?.value
val gpsPoint = locationData?.position
if (gpsPoint == null) {
println("DEBUG: Standort ist NULL - GPS Signal fehlt!")
snackBarMessage = "Kein GPS Signal. Bitte kurz warten oder nach draußen gehen."
return@launch
}
println("DEBUG: GPS gefunden: x=${gpsPoint.x}, y=${gpsPoint.y}")
// 2. Feature erstellen
// Wichtig: explizit WGS84, falls es nicht schon hat
val pointWgs84 = Point(gpsPoint.x, gpsPoint.y, SpatialReference.wgs84())
val feature = serviceFeatureTable.createFeature().apply {
geometry = pointWgs84
attributes["Typ"] = typ
attributes["Beschreibung"] = beschreibung
}
println("DEBUG: Feature lokal erstellt. Sende an Server...")
// 3. Hochladen
serviceFeatureTable.addFeature(feature).onSuccess {
println("DEBUG: addFeature erfolgreich")
applyEditsWithPhotos(feature as ArcGISFeature, photos)
}.onFailure {
println("DEBUG: addFeature FEHLER: ${it.message}")
snackBarMessage = "Fehler: ${it.message}"
}
} catch (e: Exception) {
println("DEBUG: CRASH in createFeature: ${e.message}")
e.printStackTrace()
snackBarMessage = "Fehler: ${e.message}"
}
}
}
fun pickCurrentLocation() {
// keine Coroutine nötig, das ist alles sync
val pos = locationDisplay?.location?.value?.position
@@ -146,7 +98,6 @@ class MapViewModel(application: Application) : AndroidViewModel(application) {
snackBarMessage = "Position aus GPS gesetzt."
}
private suspend fun applyEditsWithPhotos(feature: ArcGISFeature, photos: List<ImageBitmap>) {
serviceFeatureTable.applyEdits().onSuccess { editResults ->
val result = editResults.firstOrNull()
@@ -231,7 +182,7 @@ class MapViewModel(application: Application) : AndroidViewModel(application) {
}
when (selectedOperation) {
FeatureOperationType.DEFAULT -> selectFeatureForAttributeEditAt(singleTapConfirmedEvent.screenCoordinate)
FeatureOperationType.DEFAULT -> selectFeatureAt(singleTapConfirmedEvent.screenCoordinate)
FeatureOperationType.DELETE -> deleteFeatureAt(singleTapConfirmedEvent.screenCoordinate)
FeatureOperationType.UPDATE_ATTRIBUTE -> selectFeatureForAttributeEditAt(singleTapConfirmedEvent.screenCoordinate)
FeatureOperationType.UPDATE_GEOMETRY -> updateFeatureGeometryAt(singleTapConfirmedEvent.screenCoordinate)
@@ -282,7 +233,6 @@ class MapViewModel(application: Application) : AndroidViewModel(application) {
}
private fun updateFeatureGeometryAt(screenCoordinate: ScreenCoordinate) {
featureLayer?.let { featureLayer ->
when (selectedFeature) {
// When no feature is selected.
@@ -398,12 +348,33 @@ class MapViewModel(application: Application) : AndroidViewModel(application) {
}
}
fun selectFeatureAt(screenCoordinate: ScreenCoordinate) {
featureLayer?.let { featureLayer ->
// Clear any existing selection.
featureLayer.clearSelection()
selectedFeature = null
viewModelScope.launch {
// Determine if a user tapped on a feature.
mapViewProxy.identify(featureLayer, screenCoordinate, 10.dp).onSuccess {
identifyResult ->
// Get the identified feature.
val identifiedFeature = identifyResult.geoElements.firstOrNull() as? ArcGISFeature
identifiedFeature?.let {
selectedFeature = it.also {
featureLayer.selectFeature(it)
showFeatureInfo = true
}
}
}
}
}
}
fun closeFeatureInfo() {
showFeatureInfo = false
selectedFeature = null
featureLayer.clearSelection()
}
}
enum class FeatureOperationType(val operationName: String, val instruction: String) {