FeatureInfo Widget hinzugefügt
This commit is contained in:
@@ -4,6 +4,7 @@ import MapViewModel
|
||||
import android.Manifest
|
||||
import android.R.attr.enabled
|
||||
import android.app.Application
|
||||
import android.graphics.BitmapFactory
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.PickVisualMediaRequest
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
@@ -30,9 +31,12 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.arcgismaps.data.ArcGISFeature
|
||||
// Hier holen wir die ArcGIS Klassen
|
||||
import com.arcgismaps.mapping.ArcGISMap
|
||||
import com.arcgismaps.mapping.BasemapStyle
|
||||
@@ -88,6 +92,8 @@ fun MainScreen(modifier: Modifier = Modifier, application: Application) {
|
||||
floatingActionButton = {
|
||||
LargeFloatingActionButton(
|
||||
onClick = {
|
||||
mapViewModel.resetDraft()
|
||||
mapViewModel.closeFeatureInfo()
|
||||
openReport()
|
||||
},
|
||||
modifier = Modifier.offset(y = 64.dp),
|
||||
@@ -136,6 +142,14 @@ fun ContentScreen(
|
||||
)
|
||||
}
|
||||
|
||||
if (mapViewModel.showFeatureInfo && mapViewModel.selectedFeature != null) {
|
||||
FeatureInfoOverlay(
|
||||
feature = mapViewModel.selectedFeature!!,
|
||||
onClose = { mapViewModel.closeFeatureInfo() }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
// Slider von Links
|
||||
SideSlider(visible = sliderOpen) {
|
||||
Text(
|
||||
@@ -332,7 +346,11 @@ fun ReportOverlay(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.SpaceBetween
|
||||
) {
|
||||
Button(onClick = { mapViewModel.pickCurrentLocation() }) {
|
||||
Button(
|
||||
onClick = {
|
||||
mapViewModel.pickCurrentLocation()
|
||||
}
|
||||
) {
|
||||
Text(if (hasPoint) "Neue Position aus Standort" else "Position aus Standort")
|
||||
}
|
||||
Button(
|
||||
@@ -346,3 +364,64 @@ fun ReportOverlay(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun FeatureInfoOverlay(
|
||||
feature: ArcGISFeature,
|
||||
onClose: () -> Unit
|
||||
) {
|
||||
val typ = feature.attributes["Typ"].toString()
|
||||
val beschreibung = feature.attributes["Beschreibung"].toString()
|
||||
val id = feature.attributes["OBJECTID"].toString()
|
||||
var image by remember { mutableStateOf<ImageBitmap?>(null) }
|
||||
|
||||
LaunchedEffect(feature) {
|
||||
image = loadFirstAttachmentBitmap(feature)
|
||||
}
|
||||
|
||||
|
||||
OverlayShell(
|
||||
title = "Meldung $id",
|
||||
footer = {
|
||||
OutlinedButton(
|
||||
onClick = {
|
||||
onClose()
|
||||
}
|
||||
) { Text("Schließen", color = Color.Black) }
|
||||
}
|
||||
) {
|
||||
image?.let {
|
||||
Image(
|
||||
bitmap = it,
|
||||
contentDescription = "Feature Bild",
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(200.dp),
|
||||
contentScale = ContentScale.Crop
|
||||
)
|
||||
}
|
||||
Text("Typ: $typ", color = Color.Black)
|
||||
Text("Beschreibung:", color = Color.Black)
|
||||
Text(beschreibung, color = Color.Black)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun loadFirstAttachmentBitmap(
|
||||
feature: ArcGISFeature
|
||||
): ImageBitmap? {
|
||||
|
||||
// Feature muss geladen sein
|
||||
feature.load().getOrThrow()
|
||||
|
||||
// Attachments abrufen
|
||||
val attachments = feature.fetchAttachments().getOrThrow()
|
||||
|
||||
val first = attachments.firstOrNull() ?: return null
|
||||
|
||||
// Attachment-Daten laden
|
||||
val data = first.fetchData().getOrThrow()
|
||||
|
||||
val bitmap = BitmapFactory.decodeByteArray(data, 0, data.size)
|
||||
return bitmap.asImageBitmap()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user