Skip to content

Commit

Permalink
feedback 2
Browse files Browse the repository at this point in the history
  • Loading branch information
prupani-7 committed Dec 18, 2023
1 parent 7d29c43 commit 253b6eb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.AndroidViewModel
import com.arcgismaps.Color
import com.arcgismaps.geometry.CoordinateFormatter
import com.arcgismaps.geometry.LatitudeLongitudeFormat
import com.arcgismaps.geometry.Point
import com.arcgismaps.geometry.SpatialReference
import com.arcgismaps.geometry.UtmConversionMode
import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
import com.arcgismaps.mapping.view.Graphic
import com.esri.arcgismaps.sample.sampleslib.components.MessageDialogViewModel

class MapViewModel(application: Application) : AndroidViewModel(application) {
Expand All @@ -43,12 +48,24 @@ class MapViewModel(application: Application) : AndroidViewModel(application) {
// create a ViewModel to handle dialog interactions
val messageDialogVM: MessageDialogViewModel = MessageDialogViewModel()

// set up a graphic to indicate where the coordinates relate to, with an initial location
val initialPoint = Point(0.0, 0.0, SpatialReference.wgs84())

val coordinateLocationGraphic = Graphic(
geometry = initialPoint,
symbol = SimpleMarkerSymbol(
style = SimpleMarkerSymbolStyle.Cross,
color = Color.fromRgba(255, 255, 0, 255),
size = 20f
)
)

/**
* Uses CoordinateFormatter to update the UI with coordinate notation strings based on the
* given [newLocation] point to convert to coordinate notations
*/
fun toCoordinateNotationFromPoint(newLocation: Point) {

coordinateLocationGraphic.geometry = newLocation
// use CoordinateFormatter to convert to Latitude Longitude, formatted as Decimal Degrees
decimalDegrees = CoordinateFormatter.toLatitudeLongitudeOrNull(
point = newLocation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.lifecycle.viewmodel.compose.viewModel
import com.arcgismaps.Color
import com.arcgismaps.geometry.Point
import com.arcgismaps.geometry.SpatialReference
import com.arcgismaps.mapping.ArcGISMap
import com.arcgismaps.mapping.Basemap
import com.arcgismaps.mapping.layers.ArcGISTiledLayer
import com.arcgismaps.mapping.symbology.SimpleMarkerSymbol
import com.arcgismaps.mapping.symbology.SimpleMarkerSymbolStyle
import com.arcgismaps.mapping.view.Graphic
import com.arcgismaps.mapping.view.GraphicsOverlay
import com.arcgismaps.toolkit.geocompose.MapView
import com.arcgismaps.toolkit.geocompose.rememberGraphicsOverlayCollection
Expand All @@ -52,25 +46,16 @@ fun MainScreen(sampleName: String) {
// create a map that has the WGS 84 coordinate system and set this into the map
val basemapLayer = ArcGISTiledLayer(LocalContext.current.applicationContext.getString(R.string.basemap_url))
val arcGISMap = ArcGISMap(Basemap(basemapLayer))
// the collection of graphics overlays used by the MapView
val graphicsOverlayCollection = rememberGraphicsOverlayCollection()
// graphics overlay for the MapView to draw the graphics
val graphicsOverlay = remember { GraphicsOverlay() }
// set up a graphic to indicate where the coordinates relate to, with an initial location
val initialPoint = Point(0.0, 0.0, SpatialReference.wgs84())
// the collection of graphics overlays used by the MapView
val graphicsOverlayCollection = rememberGraphicsOverlayCollection().apply {
add(graphicsOverlay)
}

val coordinateLocation = Graphic(
geometry = initialPoint,
symbol = SimpleMarkerSymbol(
style = SimpleMarkerSymbolStyle.Cross,
color = Color.fromRgba(255, 255, 0, 255),
size = 20f
)
)
graphicsOverlay.graphics.add(coordinateLocation)
graphicsOverlay.graphics.add(mapViewModel.coordinateLocationGraphic)
// update the coordinate notations using the initial point
coordinateLocation.geometry = initialPoint
mapViewModel.toCoordinateNotationFromPoint(initialPoint)
mapViewModel.toCoordinateNotationFromPoint(mapViewModel.initialPoint)

Scaffold(
topBar = { SampleTopAppBar(title = sampleName) },
Expand All @@ -85,20 +70,16 @@ fun MainScreen(sampleName: String) {
MapView(
modifier = Modifier.fillMaxSize(),
arcGISMap = arcGISMap,
graphicsOverlays = graphicsOverlayCollection.apply {
this.add(graphicsOverlay)
},
graphicsOverlays = graphicsOverlayCollection,
onSingleTapConfirmed = { singleTapConfirmedEvent ->
/**
* Updates the tapped graphic and coordinate notations using the [tappedPoint]
*/
// retrieve the map point on MapView tapped
val tappedPoint = singleTapConfirmedEvent.mapPoint
if (tappedPoint != null) {
// update the tapped location graphic
coordinateLocation.geometry = tappedPoint
mapViewModel.coordinateLocationGraphic.geometry = tappedPoint
graphicsOverlay.graphics.apply {
clear()
add(coordinateLocation)
add(mapViewModel.coordinateLocationGraphic)
}
// update the coordinate notations using the tapped point
mapViewModel.toCoordinateNotationFromPoint(tappedPoint)
Expand Down

0 comments on commit 253b6eb

Please sign in to comment.