- GPS Location zu DraftReport
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
import android.app.Application
|
||||
import android.graphics.Bitmap
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.ImageBitmap
|
||||
import androidx.compose.ui.graphics.asAndroidBitmap
|
||||
import androidx.compose.ui.unit.dp
|
||||
@@ -25,7 +22,6 @@ import com.arcgismaps.mapping.Viewpoint
|
||||
import com.arcgismaps.mapping.layers.FeatureLayer
|
||||
import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
|
||||
import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
|
||||
import com.arcgismaps.mapping.symbology.SimpleRenderer
|
||||
import com.arcgismaps.mapping.view.Graphic
|
||||
import com.arcgismaps.mapping.view.GraphicsOverlay
|
||||
import com.arcgismaps.mapping.view.LocationDisplay
|
||||
@@ -65,6 +61,7 @@ class MapViewModel(application: Application) : AndroidViewModel(application) {
|
||||
val tempOverlay = GraphicsOverlay()
|
||||
|
||||
init {
|
||||
tempOverlay.graphics.add(pointGraphic)
|
||||
viewModelScope.launch {
|
||||
serviceFeatureTable = ServiceFeatureTable("https://services9.arcgis.com/UVxdrlZq3S3gqt7w/arcgis/rest/services/si_StrassenSchaeden/FeatureServer/0")
|
||||
serviceFeatureTable.load().onSuccess {
|
||||
@@ -131,6 +128,25 @@ class MapViewModel(application: Application) : AndroidViewModel(application) {
|
||||
}
|
||||
}
|
||||
|
||||
fun pickCurrentLocation() {
|
||||
// keine Coroutine nötig, das ist alles sync
|
||||
val pos = locationDisplay?.location?.value?.position
|
||||
if (pos == null) {
|
||||
snackBarMessage = "Kein GPS Signal. Bitte kurz warten oder Standort aktivieren."
|
||||
return
|
||||
}
|
||||
|
||||
// pos ist ggf. schon Point, aber wir erzwingen WGS84 (sicher für deinen Feature-Service)
|
||||
val pointWgs84 =
|
||||
if (pos.spatialReference == SpatialReference.wgs84()) pos
|
||||
else GeometryEngine.projectOrNull(pos, SpatialReference.wgs84()) as Point
|
||||
|
||||
updateReportDraft { copy(point = pointWgs84) }
|
||||
pointGraphic.geometry = pointWgs84
|
||||
snackBarMessage = "Position aus GPS gesetzt."
|
||||
}
|
||||
|
||||
|
||||
private suspend fun applyEditsWithPhotos(feature: ArcGISFeature, photos: List<ImageBitmap>) {
|
||||
serviceFeatureTable.applyEdits().onSuccess { editResults ->
|
||||
val result = editResults.firstOrNull()
|
||||
@@ -319,9 +335,7 @@ class MapViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
if (p != null) {
|
||||
reportDraft = reportDraft.copy(point = p)
|
||||
tempOverlay.graphics.clear()
|
||||
pointGraphic.geometry = p
|
||||
tempOverlay.graphics.add(pointGraphic)
|
||||
reopenReport = true
|
||||
snackBarMessage = "Position gesetzt."
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user