ios - ESRI IOS 应用程序开发 - 在绘图类型之间切换时让“sketchEditor.start(with:”保留以前绘制的图形
问题描述
我是 Swift 新手,正在使用 ArcGIS Runtime for IOS 构建一个 GIS 应用程序以了解更多信息。该应用程序的一部分是让某人能够在地图上绘制临时图形。现在,当我在点/折线/多边形之间切换时,先前绘制的图形都会被删除,我想知道是否有办法将它们保留在那里,直到单击“清除”按钮。
我相信答案在于 self.sketchEditor.start(with: nil, creationMode: [draw style])
“nil”正在清除之前的内容,但我无法弄清楚我需要用什么替换它才能让它保留任何当前绘制的图形。
以下是我的代码,任何帮助将不胜感激。
//
// ViewController.swift
// [name]
//
// Created by
//
//
import UIKit
import ArcGIS
import MessageUI
class ViewController: UIViewController {
@IBOutlet weak var mapView: AGSMapView!
@IBOutlet weak var geometrySegmentedControl: UISegmentedControl!
@IBOutlet weak var undoBBI: UIButton!
@IBOutlet weak var clearBBI: UIButton!
private var map: AGSMap!
private var sketchEditor: AGSSketchEditor!
private func setupMap() {
let itemID = [portal map]
let portal = AGSPortal(url: URL(string: "https://www.arcgis.com")!, loginRequired: false)
let portalItem: AGSPortalItem = AGSPortalItem(portal: portal, itemID: itemID)
mapView.map = AGSMap(item: portalItem)
}
private func showAlert(withStatus: String) {
let alertController = UIAlertController(title: "Alert", message:
withStatus, preferredStyle: UIAlertController.Style.alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertAction.Style.default,handler: nil))
present(alertController, animated: true, completion: nil)
}
func setupLocationDisplay() {
mapView.locationDisplay.autoPanMode = AGSLocationDisplayAutoPanMode.compassNavigation
mapView.locationDisplay.start { [weak self] (error:Error?) -> Void in
if let error = error {
self?.showAlert(withStatus: error.localizedDescription)
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
setupMap()
setupLocationDisplay()
let itemID = [portal]
let portal = AGSPortal(url: URL(string: "https://www.arcgis.com")!, loginRequired: false)
let portalItem: AGSPortalItem = AGSPortalItem(portal: portal, itemID: itemID)
self.map = AGSMap(item: portalItem)
self.sketchEditor = AGSSketchEditor()
self.mapView.sketchEditor = self.sketchEditor
self.sketchEditor.start(with: nil, creationMode: .unset)
self.mapView.map = self.map
self.mapView.interactionOptions.isMagnifierEnabled = false
NotificationCenter.default.addObserver(self, selector: #selector(ViewController.respondToGeomChanged), name: .AGSSketchEditorGeometryDidChange, object: nil)
}
@objc
func respondToGeomChanged() {
//Enable/disable UI elements appropriately
self.undoBBI.isSelected = self.sketchEditor.undoManager.canUndo
self.clearBBI.isSelected = self.sketchEditor.geometry != nil && !self.sketchEditor.geometry!.isEmpty
}
// MARK: - Actions
@IBAction func geometryValueChanged(_ geometrySegmentedControl: UISegmentedControl) {
switch geometrySegmentedControl.selectedSegmentIndex {
case 0://multipoint
self.sketchEditor.start(with: nil, creationMode: .unset)
case 1://freehand polyline
self.sketchEditor.start(with: nil, creationMode: .freehandPolyline)
case 2://freehand polygon
self.sketchEditor.start(with: nil, creationMode: .freehandPolygon)
case 3://multipoint
self.sketchEditor.start(with: nil, creationMode: .multipoint)
default:
break
}
self.mapView.sketchEditor = self.sketchEditor
}
@IBAction func undo() {
if self.sketchEditor.undoManager.canUndo { //extra check, just to be sure
self.sketchEditor.undoManager.undo()
}
}
@IBAction func clear() {
self.sketchEditor.clearGeometry()
}
}
解决方案
推荐阅读
- python - Pyinstaller 和 cx-freeze 部署的 PyQT5 .exe 项目上的 DLL 错误
- java - 调用 java WebServlet 时收到 Ajax 错误 404
- javascript - 我有一个计数器来跟踪数字或回合,但我不知道在达到该数字后如何结束游戏
- python - 来自桌面应用程序的 OAuth2 身份验证代码
- python - from google import google ImportError: cannot import name 'google' from 'google' (unknown location)
- unity3d - 连续旋转 90 度无法获得初始角度
- java - HashBiMap 被阻止
- bots - 用于创建团队频道的图形 API 更频繁地提供 429
- angular - 使用 npm 链接深入研究 Angular 包
- xcode - 我从 X-Code 中删除了 App.framework 和 flutter.framework。有什么帮助让他们回来吗?