Skip to content

Commit f1aa69b

Browse files
authored
Merge pull request #430 from Esri/Ting/Update-SnappingGO
[Update] Add graphics overlay as a snap source to `Snap geometry edits`
2 parents 2d7b3cd + d38a299 commit f1aa69b

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed

Shared/Samples/Snap geometry edits/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ A field worker can create new features by editing and snapping the vertices of a
1212

1313
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.
1414

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

17-
To interactively snap a vertex, ensure that snapping is enabled and move the mouse pointer or drag a vertex close to 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. Release the touch pointer to place the vertex at the snapped location.
17+
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 close to 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. Release the touch pointer to place the vertex at the snapped location.
1818

1919
To more clearly see how the vertex is snapped, long press to invoke the magnifier before starting to move the pointer.
2020

@@ -33,6 +33,7 @@ To more clearly see how the vertex is snapped, long press to invoke the magnifie
3333
* Geometry
3434
* GeometryEditor
3535
* GeometryEditorStyle
36+
* GraphicsOverlay
3637
* MapView
3738
* SnapSettings
3839
* SnapSource
@@ -52,4 +53,4 @@ Snapping can be used during interactive edits that move existing vertices using
5253

5354
## Tags
5455

55-
edit, feature, geometry editor, layers, map, snapping
56+
edit, feature, geometry editor, graphics, layers, map, snapping

Shared/Samples/Snap geometry edits/README.metadata.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
"edit",
1010
"feature",
1111
"geometry editor",
12+
"graphics",
1213
"layers",
1314
"map",
1415
"snapping",
1516
"FeatureLayer",
1617
"Geometry",
1718
"GeometryEditor",
1819
"GeometryEditorStyle",
20+
"GraphicsOverlay",
1921
"MapView",
2022
"SnapSettings",
2123
"SnapSource",
@@ -27,6 +29,7 @@
2729
"Geometry",
2830
"GeometryEditor",
2931
"GeometryEditorStyle",
32+
"GraphicsOverlay",
3033
"MapView",
3134
"SnapSettings",
3235
"SnapSource",

Shared/Samples/Snap geometry edits/SnapGeometryEditsView.GeometryEditorModel.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ extension SnapGeometryEditsView {
2323
let geometryEditor = GeometryEditor()
2424

2525
/// The graphics overlay used to save geometries to.
26-
let geometryOverlay = GraphicsOverlay(renderingMode: .dynamic)
26+
let geometryOverlay: GraphicsOverlay = {
27+
let overlay = GraphicsOverlay(renderingMode: .dynamic)
28+
overlay.id = "Graphics Overlay"
29+
return overlay
30+
}()
2731

2832
/// A Boolean value indicating if the saved sketches can be cleared.
2933
@Published private(set) var canClearSavedSketches = false

Shared/Samples/Snap geometry edits/SnapGeometryEditsView.SnapSettingsView.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,24 @@ extension SnapGeometryEditsView {
2727
/// for the geometry editor.
2828
@State private var snappingEnabled = false
2929

30-
/// An array of snap source layer names and their source settings.
31-
@State private var snapSources: [(layerName: String, sourceSettings: SnapSourceSettings)] = []
30+
/// An array of snap source names and their source settings.
31+
@State private var snapSources: [(name: String, sourceSettings: SnapSourceSettings)] = []
3232

3333
/// An array of Boolean values for each snap source enabled states.
3434
@State private var snapSourceEnabledStates: [Bool] = []
3535

3636
var body: some View {
3737
Form {
38-
Section("Snap Source") {
38+
Section("Geometry Editor Snapping") {
3939
Toggle("Snapping", isOn: $snappingEnabled)
4040
.onChange(of: snappingEnabled) { newValue in
4141
model.geometryEditor.snapSettings.isEnabled = newValue
4242
}
4343
}
4444

45-
Section("Layer Snapping") {
45+
Section("Individual Source Snapping") {
4646
ForEach(0 ..< snapSources.count, id: \.self) { index in
47-
Toggle(snapSources[index].layerName, isOn: $snapSourceEnabledStates[index])
47+
Toggle(snapSources[index].name, isOn: $snapSourceEnabledStates[index])
4848
.onChange(of: snapSourceEnabledStates[index]) { newValue in
4949
snapSources[index].sourceSettings.isEnabled = newValue
5050
}
@@ -65,11 +65,16 @@ extension SnapGeometryEditsView {
6565
model.geometryEditor.snapSettings.isEnabled = true
6666
snappingEnabled = model.geometryEditor.snapSettings.isEnabled
6767

68-
// Creates an array from snap source layers with their
69-
// layer name and source settings.
68+
// Creates an array from snap source layers or graphics overlays
69+
// with their name and source settings.
7070
snapSources = model.geometryEditor.snapSettings.sourceSettings.compactMap { sourceSettings in
71-
guard let layer = sourceSettings.source as? FeatureLayer else { return nil }
72-
return (layer.name, sourceSettings)
71+
if let layer = sourceSettings.source as? FeatureLayer {
72+
return (layer.name, sourceSettings)
73+
} else if let graphicsOverlay = sourceSettings.source as? GraphicsOverlay {
74+
return (graphicsOverlay.id, sourceSettings)
75+
} else {
76+
return nil
77+
}
7378
}
7479

7580
// Initializes the enabled states from the snap sources.

Shared/Samples/Snap geometry edits/SnapGeometryEditsView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct SnapGeometryEditsView: View {
7171
// Various snapping settings for a geometry editor.
7272
SnapSettingsView(model: model)
7373
}
74-
.presentationDetents([.fraction(0.5)])
74+
.presentationDetents([.fraction(0.6)])
7575
.frame(idealWidth: 320, idealHeight: 380)
7676
}
7777
.disabled(!layersAreLoaded)

0 commit comments

Comments
 (0)