Skip to content
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 SnapGeometryEdits #201

Merged
merged 4 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
# ArcGIS Maps SDK for Kotlin version
arcgisMapsKotlinVersion = "200.5.0-4223"
arcgisMapsKotlinVersion = "200.5.0-4244"
# SDK versions
compileSdk = "34"
minSdk = "26"
Expand Down
9 changes: 5 additions & 4 deletions snap-geometry-edits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ A field worker can create new features by editing and snapping the vertices of a

To create a geometry, press the create button to choose the geometry type you want to create (i.e. points, multipoints, polyline, or polygon) and interactively tap and drag on the map view to create the geometry.

To configure snapping, press the snap settings button to enable or disable snapping and choose which layers to snap to.
To configure snapping, press the snap settings button to enable or disable snapping and choose which snap sources to snap to.

To interactively snap a vertex, ensure that snapping is enabled and move the mouse pointer or drag a vertex to nearby an existing feature. When the pointer is close to a feature, the edit position will be adjusted to coincide with (or snap to), edges and vertices of that feature. Click or release the touch pointer to place the vertex at the snapped location.
To interactively snap a vertex to a feature or graphic, ensure that snapping is enabled for the relevant snap source and move the mouse pointer or drag a vertex to nearby an existing feature or graphic. When the pointer is close to that existing geoelement, the edit position will be adjusted to coincide with (or snap to), edges and vertices of its geometry. Click or release the touch pointer to place the vertex at the snapped location.

To edit a geometry, tap the geometry to be edited in the map to select it and then edit the geometry by tapping and dragging its vertices and snapping them to nearby features.
To edit a geometry, tap the geometry to be edited in the map to select it and then edit the geometry by tapping and dragging its vertices and snapping them to nearby features or graphics.

To edit a vertex using the magnifier, tap and hold on the vertex and then drag it along with the magnifier.

Expand All @@ -41,6 +41,7 @@ To save your edits, press the save button.
* Geometry
* GeometryEditor
* GeometryEditorStyle
* GraphicsOverlay
* MapView
* MapView.interactionOptions.isMagnifierEnabled
* SnapSettings
Expand All @@ -63,4 +64,4 @@ Snapping can be used during interactive edits that move existing vertices using

## Tags

edit, feature, geometryeditor, geoviewcompose, layers, magnify, map, snapping
edit, feature, geometryeditor, geoviewcompose, graphics, layers, magnify, map, snapping
3 changes: 3 additions & 0 deletions snap-geometry-edits/README.metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"feature",
"geometryeditor",
"geoviewcompose",
"graphics",
"layers",
"magnify",
"map",
Expand All @@ -19,6 +20,7 @@
"Geometry",
"GeometryEditor",
"GeometryEditorStyle",
"GraphicsOverlay",
"MapView",
"MapView.interactionOptions.isMagnifierEnabled",
"SnapSettings",
Expand All @@ -32,6 +34,7 @@
"Geometry",
"GeometryEditor",
"GeometryEditorStyle",
"GraphicsOverlay",
"MapView",
"MapView.interactionOptions.isMagnifierEnabled",
"SnapSettings",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ class MapViewModel(
*/
init {
sampleCoroutineScope.launch {
// set the feature layer's feature tiling mode
// set the id for the graphics overlay
graphicsOverlay.id = "Editor Graphics Overlay"
// set the feature layer's tiling mode
map.loadSettings.featureTilingMode =
FeatureTilingMode.EnabledWithFullResolutionWhenSupported
// load the map
Expand Down Expand Up @@ -194,12 +196,13 @@ class MapViewModel(
* more elements in the geometry.
*/
fun deleteSelection() {
if (geometryEditor.geometry.value?.isEmpty == true) {
geometryEditor.stop()
isCreateButtonEnabled.value = true
}

if (geometryEditor.selectedElement.value != null) {
geometryEditor.deleteSelectedElement()
if (geometryEditor.geometry.value?.isEmpty == true) {
geometryEditor.stop()
isCreateButtonEnabled.value = true
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ fun MainScreen(sampleName: String) {
val graphicsOverlayCollection = listOf(mapViewModel.graphicsOverlay)

Scaffold(
topBar = { SampleTopAppBar(title = sampleName) },
content = {
Column(
modifier = Modifier
.fillMaxSize()
.padding(it)
) {
SampleTopAppBar(title = sampleName)
MapView(
modifier = Modifier
.fillMaxSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.arcgismaps.geometry.GeometryType
import com.arcgismaps.mapping.layers.FeatureLayer
import com.arcgismaps.mapping.view.GraphicsOverlay
import com.arcgismaps.mapping.view.geometryeditor.SnapSourceSettings
import com.esri.arcgismaps.sample.sampleslib.theme.SampleTypography

Expand Down Expand Up @@ -126,117 +127,103 @@ fun SnapSettings(
}
}
}
Row(
modifier = Modifier
.fillMaxWidth()
.padding(20.dp, 10.dp, 20.dp, 10.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
style = SampleTypography.titleMedium,
text = "Point Layers",
color = MaterialTheme.colorScheme.primary
)
TextButton(
onClick = {
snapSourceList.value.forEachIndexed { index, snapSource ->
if ((snapSource.source as FeatureLayer).featureTable?.geometryType == GeometryType.Point) {
onSnapSourceChanged(true, index)
}
}
}
) {
Text(text = "Enable All Sources")
SnapSourceUI(snapSourceList, isSnapSourceEnabled, onSnapSourceChanged, GeometryType.Point)
SnapSourceUI(snapSourceList, isSnapSourceEnabled, onSnapSourceChanged, GeometryType.Polyline)
SnapSourceUI(snapSourceList, isSnapSourceEnabled, onSnapSourceChanged, null)
}
}
}
}

@Composable
fun SnapSourceUI(
snapSourceList: State<List<SnapSourceSettings>>,
isSnapSourceEnabled: List<Boolean>,
onSnapSourceChanged: (Boolean, Int) -> Unit,
geometryType : GeometryType?
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(20.dp, 10.dp, 20.dp, 10.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
style = SampleTypography.titleMedium,
text = when (geometryType) {
is GeometryType.Point -> "Point Layer"
is GeometryType.Polyline -> "Polyline Layer"
else -> "Graphics Overlays"
},
color = MaterialTheme.colorScheme.primary
)
TextButton(
onClick = {
snapSourceList.value.forEachIndexed { index, snapSource ->
if (geometryType != null &&
(snapSource.source as? FeatureLayer)?.featureTable?.geometryType == geometryType) {
onSnapSourceChanged(true, index)
} else if (geometryType == null && snapSource.source is GraphicsOverlay) {
onSnapSourceChanged(true, index)
}
}
Surface(
modifier = Modifier.padding(20.dp, 0.dp, 20.dp, 10.dp),
tonalElevation = 1.dp,
shape = RoundedCornerShape(20.dp),
border = BorderStroke(1.dp, MaterialTheme.colorScheme.outlineVariant)
) {
Column(
modifier = Modifier.padding(14.dp)
) {
Column {
snapSourceList.value.forEachIndexed { index, snapSource ->
if ((snapSource.source as FeatureLayer).featureTable?.geometryType == GeometryType.Point) {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
modifier = Modifier.padding(20.dp, 0.dp, 0.dp, 0.dp),
text = (snapSource.source as FeatureLayer).name
)
Switch(
checked = isSnapSourceEnabled[index],
onCheckedChange = { newValue ->
onSnapSourceChanged(newValue, index)
}
)
}
}
}
}
}
}
) {
Text(
text = if (geometryType != null) {
"Enable All Layers"
} else {
"Enable All Overlays"
}
Row(
modifier = Modifier
.fillMaxWidth()
.padding(20.dp, 0.dp, 20.dp, 10.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
style = SampleTypography.titleMedium,
text = "Polyline Layers",
color = MaterialTheme.colorScheme.primary
)
TextButton(
onClick = {
snapSourceList.value.forEachIndexed { index, snapSource ->
if ((snapSource.source as FeatureLayer).featureTable?.geometryType == GeometryType.Polyline) {
onSnapSourceChanged(true, index)
)
}
}
Surface(
modifier = Modifier.padding(20.dp, 0.dp, 20.dp, 10.dp),
tonalElevation = 1.dp,
shape = RoundedCornerShape(20.dp),
border = BorderStroke(1.dp, MaterialTheme.colorScheme.outlineVariant)
) {
Column(
modifier = Modifier.padding(14.dp)
) {
Column {
snapSourceList.value.forEachIndexed { index, snapSource ->
if (geometryType != null &&
(snapSource.source as? FeatureLayer)?.featureTable?.geometryType == geometryType) {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
modifier = Modifier.padding(20.dp, 0.dp, 0.dp, 0.dp),
text = (snapSource.source as FeatureLayer).name
)
Switch(
checked = isSnapSourceEnabled[index],
onCheckedChange = { newValue ->
onSnapSourceChanged(newValue, index)
}
}
)
}
) {
Text(text = "Enable All Sources")
}
}
Surface(
modifier = Modifier.padding(20.dp, 0.dp, 20.dp, 10.dp),
tonalElevation = 1.dp,
shape = RoundedCornerShape(20.dp),
border = BorderStroke(1.dp, MaterialTheme.colorScheme.outlineVariant)
) {
Column(
modifier = Modifier.padding(14.dp)
) {
Column {
snapSourceList.value.forEachIndexed { index, snapSource ->
if ((snapSource.source as FeatureLayer).featureTable?.geometryType == GeometryType.Polyline) {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
modifier = Modifier.padding(20.dp, 0.dp, 0.dp, 0.dp),
text = (snapSource.source as FeatureLayer).name
)
Switch(
checked = isSnapSourceEnabled[index],
onCheckedChange = { newValue ->
onSnapSourceChanged(newValue, index)
}
)
}
} else if (geometryType == null && snapSource.source is GraphicsOverlay) {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
modifier = Modifier.padding(20.dp, 0.dp, 0.dp, 0.dp),
text = (snapSource.source as GraphicsOverlay).id
)
Switch(
checked = isSnapSourceEnabled[index],
onCheckedChange = { newValue ->
onSnapSourceChanged(newValue, index)
}
}
)
}
}
}
Expand Down
Loading