-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update show coordinates sample #152
Changes from 11 commits
ec24bca
286b08e
b9edffa
fcfa35c
e81f619
54de8fe
39b141a
232adcc
88f6d01
ce6bb37
85acc1b
7d29c43
253b6eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The app crashes when I type in an incorrect coordinate point. Ideally, it should display the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above comment.. |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,40 +16,93 @@ | |||||||||
|
||||||||||
package com.esri.arcgismaps.sample.showcoordinatesinmultipleformats.screens | ||||||||||
|
||||||||||
import android.app.Application | ||||||||||
import androidx.compose.foundation.layout.Column | ||||||||||
import androidx.compose.foundation.layout.fillMaxSize | ||||||||||
import androidx.compose.foundation.layout.padding | ||||||||||
import androidx.compose.material3.Scaffold | ||||||||||
import androidx.compose.runtime.Composable | ||||||||||
import androidx.compose.runtime.remember | ||||||||||
import androidx.compose.ui.Modifier | ||||||||||
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 | ||||||||||
import com.esri.arcgismaps.sample.sampleslib.components.MessageDialog | ||||||||||
import com.esri.arcgismaps.sample.sampleslib.components.SampleTopAppBar | ||||||||||
import com.esri.arcgismaps.sample.showcoordinatesinmultipleformats.components.ComposeMapView | ||||||||||
import com.esri.arcgismaps.sample.showcoordinatesinmultipleformats.R | ||||||||||
import com.esri.arcgismaps.sample.showcoordinatesinmultipleformats.components.MapViewModel | ||||||||||
|
||||||||||
/** | ||||||||||
* Main screen layout for the sample app | ||||||||||
*/ | ||||||||||
@Composable | ||||||||||
fun MainScreen(sampleName: String) { | ||||||||||
fun MainScreen(sampleName: String, application: Application) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be passed in? Could you use |
||||||||||
// create a ViewModel to handle MapView interactions | ||||||||||
val mapViewModel: MapViewModel = viewModel() | ||||||||||
// create a map that has the WGS 84 coordinate system and set this into the map | ||||||||||
val basemapLayer = ArcGISTiledLayer(application.getString(R.string.basemap_url)) | ||||||||||
val arcGISMap = ArcGISMap(Basemap(basemapLayer)) | ||||||||||
// the collection of graphics overlays used by the MapView | ||||||||||
val graphicsOverlayCollection = rememberGraphicsOverlayCollection() | ||||||||||
// the collection of graphics overlays used by the MapView | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a duplicate comment to line 55 |
||||||||||
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()) | ||||||||||
|
||||||||||
val coordinateLocation = Graphic( | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Could rename it to
Suggested change
|
||||||||||
geometry = initialPoint, | ||||||||||
symbol = SimpleMarkerSymbol( | ||||||||||
style = SimpleMarkerSymbolStyle.Cross, | ||||||||||
color = Color.fromRgba(255, 255, 0, 255), | ||||||||||
size = 20f | ||||||||||
) | ||||||||||
) | ||||||||||
graphicsOverlay.graphics.add(coordinateLocation) | ||||||||||
// update the coordinate notations using the initial point | ||||||||||
coordinateLocation.geometry = initialPoint | ||||||||||
mapViewModel.toCoordinateNotationFromPoint(initialPoint) | ||||||||||
|
||||||||||
Scaffold( | ||||||||||
topBar = { SampleTopAppBar(title = sampleName) }, | ||||||||||
content = { | ||||||||||
content = { it -> | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this intentional? I expect it to be named or not declared explicitly There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed it, thanks! |
||||||||||
Column( | ||||||||||
modifier = Modifier.fillMaxSize().padding(it) | ||||||||||
modifier = Modifier | ||||||||||
.fillMaxSize() | ||||||||||
.padding(it) | ||||||||||
) { | ||||||||||
// layout to display the coordinate text fields. | ||||||||||
CoordinatesLayout(mapViewModel = mapViewModel) | ||||||||||
// composable function that wraps the MapView | ||||||||||
ComposeMapView( | ||||||||||
MapView( | ||||||||||
modifier = Modifier.fillMaxSize(), | ||||||||||
mapViewModel = mapViewModel, | ||||||||||
onSingleTap = { singleTapConfirmedEvent -> | ||||||||||
mapViewModel.onMapTapped(singleTapConfirmedEvent.mapPoint) | ||||||||||
arcGISMap = arcGISMap, | ||||||||||
graphicsOverlays = graphicsOverlayCollection.apply { | ||||||||||
this.add(graphicsOverlay) | ||||||||||
}, | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think simple assignment properties here would be more clear, and we can move the // graphics overlay for the MapView to draw the graphics
val graphicsOverlay = remember { GraphicsOverlay() }
// the collection of graphics overlays used by the MapView
val graphicsOverlayCollection = rememberGraphicsOverlayCollection().apply {
add(graphicsOverlay)
}
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This solution fixed the issue with showMessageDialog not showing and app crashing with error (GO object already owned) |
||||||||||
onSingleTapConfirmed = { singleTapConfirmedEvent -> | ||||||||||
/** | ||||||||||
* Updates the tapped graphic and coordinate notations using the [tappedPoint] | ||||||||||
*/ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
val tappedPoint = singleTapConfirmedEvent.mapPoint | ||||||||||
if (tappedPoint != null) { | ||||||||||
// update the tapped location graphic | ||||||||||
coordinateLocation.geometry = tappedPoint | ||||||||||
graphicsOverlay.graphics.apply { | ||||||||||
clear() | ||||||||||
add(coordinateLocation) | ||||||||||
} | ||||||||||
// update the coordinate notations using the tapped point | ||||||||||
mapViewModel.toCoordinateNotationFromPoint(tappedPoint) | ||||||||||
} | ||||||||||
} | ||||||||||
) | ||||||||||
|
||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The graphic point does not update when I try the reverse workflow.
Could you debug to see if this issue is due to the toolkit MapView or the sample workflow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, fixed...
the geometry of the coordinateLocationGraphic was not getting updated to the new Point.