Skip to content
Closed
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
4 changes: 4 additions & 0 deletions Examples/Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
88519D3F2C8A7967007D7015 /* LocationButtonExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88519D3E2C8A7967007D7015 /* LocationButtonExampleView.swift */; };
8A9419622E035F1D003C7D10 /* AppSecrets.swift.masque in Sources */ = {isa = PBXBuildFile; fileRef = 8A9419612E035F1D003C7D10 /* AppSecrets.swift.masque */; };
8AC666152DA865EE00F33C36 /* Examples+ListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AC666142DA865DD00F33C36 /* Examples+ListItem.swift */; };
D72A3EDC2FB69B18005C6D1B /* GeometryEditorToolbarExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D72A3EDB2FB69B18005C6D1B /* GeometryEditorToolbarExampleView.swift */; };
E42BFBE92672BF9500159107 /* SearchExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E42BFBE82672BF9500159107 /* SearchExampleView.swift */; };
E4624A25278CE815000D2A38 /* FloorFilterExampleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4624A24278CE815000D2A38 /* FloorFilterExampleView.swift */; };
E47ABE442652FE0900FD2FE3 /* ExamplesApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = E47ABE432652FE0900FD2FE3 /* ExamplesApp.swift */; };
Expand Down Expand Up @@ -79,6 +80,7 @@
88519D3E2C8A7967007D7015 /* LocationButtonExampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationButtonExampleView.swift; sourceTree = "<group>"; };
8A9419612E035F1D003C7D10 /* AppSecrets.swift.masque */ = {isa = PBXFileReference; lastKnownFileType = text; name = AppSecrets.swift.masque; path = ../AppSecrets.swift.masque; sourceTree = "<group>"; };
8AC666142DA865DD00F33C36 /* Examples+ListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Examples+ListItem.swift"; sourceTree = "<group>"; };
D72A3EDB2FB69B18005C6D1B /* GeometryEditorToolbarExampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeometryEditorToolbarExampleView.swift; sourceTree = "<group>"; };
E42BFBE82672BF9500159107 /* SearchExampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchExampleView.swift; sourceTree = "<group>"; };
E4624A24278CE815000D2A38 /* FloorFilterExampleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FloorFilterExampleView.swift; sourceTree = "<group>"; };
E47ABE402652FE0900FD2FE3 /* Toolkit Examples.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Toolkit Examples.app"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -118,6 +120,7 @@
E4AA9315276BF5ED000E6289 /* FloatingPanelExampleView.swift */,
E4624A24278CE815000D2A38 /* FloorFilterExampleView.swift */,
882899FC2AB5099300A0BDC1 /* FlyoverExampleView.swift */,
D72A3EDB2FB69B18005C6D1B /* GeometryEditorToolbarExampleView.swift */,
88519D3E2C8A7967007D7015 /* LocationButtonExampleView.swift */,
E4F9BC98265EFCAF001280FF /* OverviewMapExampleView.swift */,
4D19FCB42881C8F3002601E8 /* PopupExampleView.swift */,
Expand Down Expand Up @@ -327,6 +330,7 @@
882899FD2AB5099300A0BDC1 /* FlyoverExampleView.swift in Sources */,
E42BFBE92672BF9500159107 /* SearchExampleView.swift in Sources */,
E4C389D526B8A12C002BC255 /* BasemapGalleryExampleView.swift in Sources */,
D72A3EDC2FB69B18005C6D1B /* GeometryEditorToolbarExampleView.swift in Sources */,
75D41B2B27C6F21400624D7C /* ScalebarExampleView.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
155 changes: 155 additions & 0 deletions Examples/Examples/GeometryEditorToolbarExampleView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
// Copyright 2026 Esri
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import ArcGIS
import ArcGISToolkit
import SwiftUI

struct GeometryEditorToolbarExampleView: View {
/// The feature whose geometry is currently being edited.
@State private var featureBeingEdited: Feature?
/// A description of an error that has occurred.
@State private var errorDescription: String?
/// The geometry editor used to edit geometries on the map.
@State private var geometryEditor = GeometryEditor()
/// The point on the screen that is being identified.
@State private var identifyPoint: CGPoint?
/// A Boolean value indicating whether the geometry edits are being saved.
@State private var isSavingEdits = false
/// A map containing example point, line, and polygon features to edit.
@State private var map: Map = {
let url = URL(
string: "https://arcgis.com/home/item.html?id=2ffa0c3601144e8bbd2c49cf3a7c0559"
Comment thread
CalebRas marked this conversation as resolved.
)!
let map = Map(url: url)!

let envelope = Envelope(xRange: -13059996 ... -13021110, yRange: 4005439...4068056)
map.initialViewpoint = Viewpoint(boundingGeometry: envelope)

return map
}()

var body: some View {
MapViewReader { mapViewProxy in
MapView(map: map)
.geometryEditor(geometryEditor)
.onSingleTapGesture { screenPoint, _ in
guard identifyPoint == nil, featureBeingEdited == nil else { return }
identifyPoint = screenPoint
}
.task(id: identifyPoint) {
guard let identifyPoint else { return }
defer { self.identifyPoint = nil }

do {
try await editFeature(at: identifyPoint, mapViewProxy: mapViewProxy)
} catch {
errorDescription = "\(error)"
}
Comment thread
CalebRas marked this conversation as resolved.
}
}
.overlay(alignment: .topTrailing) {
GeometryEditorToolbar(geometryEditor: geometryEditor)
.padding()
}
.toolbar {
ToolbarItemGroup(placement: .bottomBar) {
finishEditingButtons
}
}
.alert(
"Error",
isPresented: Binding(
get: { errorDescription != nil },
set: { _ in errorDescription = nil }
),
actions: {},
message: {
Text(errorDescription ?? "An unknown error occurred")
}
)
}

/// Buttons for ending a geometry editing session.
@ViewBuilder private var finishEditingButtons: some View {
let canFinishEditing = featureBeingEdited != nil && !isSavingEdits

Button("Cancel", systemImage: "xmark", role: .cancel) {
geometryEditor.stop()
featureBeingEdited?.setVisible(true)
featureBeingEdited = nil
Comment on lines +90 to +91

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

            if let feature = featureBeingEdited.take() {
                feature.setVisible(true)
            }

take it or leave it ;-)

}
.disabled(!canFinishEditing)

Button("Save", systemImage: "checkmark") {
isSavingEdits = true
}
.disabled(!canFinishEditing)
.task(id: isSavingEdits) {
guard isSavingEdits else { return }
defer { isSavingEdits = false }

do {
try await saveEdits()
} catch {
self.errorDescription = "\(error)"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.errorDescription = "\(error)"
errorDescription = "\(error)"

}
Comment thread
CalebRas marked this conversation as resolved.
}
}

/// Identifies a feature at a given screen point and starts editing its geometry.
/// - Parameters:
/// - screenPoint: The point on the screen to identify.
/// - mapViewProxy: A map view proxy used to perform the identify operation.
private func editFeature(at screenPoint: CGPoint, mapViewProxy: MapViewProxy) async throws {
let identifyLayerResults = try await mapViewProxy.identifyLayers(
screenPoint: screenPoint,
tolerance: 10
)

guard let result = identifyLayerResults.first,
let feature = result.geoElements.first as? ArcGISFeature,
let geometry = feature.geometry else {
return
}

geometryEditor.start(withInitial: geometry)
feature.setVisible(false)
featureBeingEdited = feature
}

/// Saves the geometry editor edits to the feature being edited.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a note to explain that the edits aren't applied to the feature service, and is only saved to the local feature table.

private func saveEdits() async throws {
let geometry = geometryEditor.stop()

guard let featureBeingEdited else { return }

featureBeingEdited.geometry = geometry
featureBeingEdited.setVisible(true)
self.featureBeingEdited = nil
Comment on lines +139 to +140

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the featureBeingEdited becomes visible and the cache cleaned up after the featuretable.update succeeds?


try await featureBeingEdited.table?.update(featureBeingEdited)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guard the table as well, so no need optional chaining.

}
Comment thread
CalebRas marked this conversation as resolved.
}

// MARK: - Extensions

private extension Feature {
/// Sets the visibility of the feature on its feature layer.
/// - Parameter visible: `true` to show the feature, otherwise `false`.
func setVisible(_ visible: Bool) {
guard let featureLayer = table?.layer as? FeatureLayer else { return }
featureLayer.setVisible(visible, for: self)
}
}
1 change: 1 addition & 0 deletions Examples/ExamplesApp/Examples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ struct Examples: View {
.example("Feature Form", content: FeatureFormExampleView()),
.example("Floating Panel", content: FloatingPanelExampleView()),
.example("Floor Filter", content: FloorFilterExampleView()),
.example("Geometry Editor Toolbar", content: GeometryEditorToolbarExampleView()),
.example("Location Button", content: LocationButtonExampleView()),
.example("Overview Map", content: OverviewMapExampleView()),
.example("Popup", content: PopupExampleView()),
Expand Down