Skip to content

Commit d8740f0

Browse files
authored
Merge pull request #669 from Esri/Caleb/Fix-SomeSampleIssues
[Fix] `Manage features` certification issues
2 parents f82f06b + c729abf commit d8740f0

File tree

1 file changed

+37
-31
lines changed

1 file changed

+37
-31
lines changed

Shared/Samples/Manage features/ManageFeaturesView.swift

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ struct ManageFeaturesView: View {
3434
/// The current viewpoint of the map view.
3535
@State private var currentViewpoint: Viewpoint?
3636

37+
/// A Boolean value indicating whether the update attribute dialog is displayed.
38+
@State private var isShowingUpdateAttributeDialog = false
39+
3740
var body: some View {
3841
Group {
3942
switch data {
@@ -62,10 +65,12 @@ struct ManageFeaturesView: View {
6265
MapViewReader { mapView in
6366
MapView(map: data.map)
6467
.onSingleTapGesture { tapLocation, tapMapPoint in
65-
// Store state and clear selection on tap.
66-
self.tapLocation = tapLocation
67-
self.tapMapPoint = tapMapPoint
68-
clearSelection()
68+
if calloutPlacement == nil {
69+
self.tapLocation = tapLocation
70+
self.tapMapPoint = tapMapPoint
71+
} else {
72+
clearSelection()
73+
}
6974
}
7075
.callout(placement: $calloutPlacement) { placement in
7176
if let feature = placement.geoElement as? Feature {
@@ -125,15 +130,10 @@ struct ManageFeaturesView: View {
125130
.foregroundStyle(.secondary)
126131
}
127132
Menu {
128-
Button {
129-
Task {
130-
clearSelection()
131-
await updateAttribute(for: feature)
132-
}
133-
} label: {
134-
Text("Update Attribute")
133+
Button("Update Attribute") {
134+
isShowingUpdateAttributeDialog = true
135135
}
136-
Button {
136+
Button("Update Geometry") {
137137
// Hide callout, leave feature selected.
138138
calloutPlacement = nil
139139
Task {
@@ -144,24 +144,36 @@ struct ManageFeaturesView: View {
144144
// Update callout location after moving feature.
145145
calloutPlacement = .geoElement(feature)
146146
}
147-
} label: {
148-
Text("Update Geometry")
149147
}
150-
Button {
148+
Button("Delete Feature") {
151149
Task {
152150
clearSelection()
153151
await delete(feature: feature)
154152
}
155-
} label: {
156-
Text("Delete Feature")
157153
}
158154
} label: {
159-
Image(systemName: "ellipsis")
160-
.padding(.leading)
155+
Label("Edit Feature", systemImage: "ellipsis")
156+
.padding()
157+
.contentShape(.rect)
158+
.labelStyle(.iconOnly)
161159
}
162160
.fixedSize()
161+
.confirmationDialog("Update Attribute", isPresented: $isShowingUpdateAttributeDialog) {
162+
ForEach(DamageKind.allCases, id: \.self) { damageKind in
163+
Button(damageKind.rawValue) {
164+
isShowingUpdateAttributeDialog = false
165+
clearSelection()
166+
167+
Task {
168+
await updateAttribute(for: feature, damageKind: damageKind)
169+
}
170+
}
171+
}
172+
} message: {
173+
Text("Choose a damage kind for the feature.")
174+
}
163175
}
164-
.padding()
176+
.padding([.leading, .vertical])
165177
}
166178

167179
/// Overlay with instructions for the user.
@@ -247,13 +259,15 @@ extension ManageFeaturesView {
247259
}
248260

249261
/// Updates the attributes of a feature and applies edits to the service.
250-
/// - Parameter feature: The feature to update.
251-
func updateAttribute(for feature: Feature) async {
262+
/// - Parameters:
263+
/// - feature: The feature to update.
264+
/// - damageKind: The kind used to set the feature's damage assessment attribute.
265+
func updateAttribute(for feature: Feature, damageKind: DamageKind) async {
252266
guard case .success(let data) = data else { return }
253267
let table = data.featureTable
254268

255269
do {
256-
feature.damageKind = feature.damageKind?.next ?? .inaccessible
270+
feature.damageKind = damageKind
257271
try await table.update(feature)
258272
_ = try await table.serviceGeodatabase?.applyEdits()
259273
status = "Update attribute succeeded."
@@ -319,14 +333,6 @@ extension ManageFeaturesView {
319333
case minor = "Minor"
320334
case major = "Major"
321335
case destroyed = "Destroyed"
322-
323-
/// The next damage kind to set on a feature.
324-
var next: Self {
325-
let allCases = Self.allCases
326-
let index = allCases.firstIndex(of: self)!
327-
let nextIndex = allCases.index(after: index)
328-
return allCases[nextIndex == allCases.count ? 0 : nextIndex]
329-
}
330336
}
331337
}
332338

0 commit comments

Comments
 (0)