ios - 在 ArcGIS 图形图层中移动和/或移除标记
问题描述
我正在使用 ArcGIS 100.6 iOS SDK 并使用图形叠加层上的标记填充地图,其位置存储在我的应用程序的所有用户通用的数据库中。每个标记都存储在唯一的记录中,每个记录都包含标记的纬度和经度。当应用程序启动时,它会读取数据库中所有标记的位置并将每个标记添加到图形叠加中,如下所示:
let areaMarker = AGSPictureMarkerSymbol(image: UIImage(named: "CustomMarker")!)
let areaMarkerLocation = AGSPointMakeWGS84(y ?? 0.0, x ?? 0.0)
let markerIcon = AGSGraphic(geometry: areaMarkerLocation, symbol: areaMarker, attributes: >["marker": markerKey])
self.overlay.graphics.add(markerIcon)
如上所示,每个标记都分配有一个属性“marker:markerKey”,该属性是存储标记位置信息的唯一数据库记录号(键),并用作标记ID。
将初始标记添加到叠加层后,应用程序“侦听”数据库中的以下事件:
- 添加了一个新标记
- 现有标记移动到新位置
- 现有标记被删除
当标记被移动或删除时,会通知数据库侦听器并传递已移动(或删除)的标记的记录号(键)。如果标记被移动,则记录将包含新的纬度和经度信息。
我已经尝试阅读图形覆盖并确定它是包含在 NSMutable 数组中的集合。我可以读取所有属性如下:
let graphicsCollection = self.overlay.graphics.mutableArrayValue(forKey: "attributes")
print(graphicsCollection)
结果是:
(
{
marker = "-KlRW2_rba1zBrDPpxSl";
},
{
marker = "-Lu915xF3zQp4dIYnsP_";
}
)
我可以对“几何”做同样的事情并获得 AGSPoints 数组:
let graphicsCollection = self.overlay.graphics.mutableArrayValue(forKey: "geometry")
print(graphicsCollection)
结果是:
(
"AGSPoint: (-117.826127, 44.781139), sr: 4326",
"AGSPoint: (-112.056906, 33.629829), sr: 4326"
)
我无法确定如何获取属性数组的“索引”(例如,上面的标记“-KlRW2_rba1zBrDPpxSl”的索引应该为 [0]),因此我可以使用该“索引”访问相应的 AGSPoint 并更新纬度和经度或删除标记。
在此先感谢您的帮助。
解决方案
如果您想移动标记(即一个AGSGraphic
),您需要获取它AGSGraphic
本身并修改geometry
属性。我认为通过在你的mutableArrayValue()
电话中跳到“几何”,你有点在踢自己。
我会这样解决它:
let searchMarker = "-KlRW2_rba1zBrDPpxSl"
let newLocation = AGSPointMakeWGS84(40.7128, -74.0060) // NYC
if let graphic = (overlay.graphics as? [AGSGraphic])?.first(where: {
($0.attributes["marker"] as? String) == searchMarker
}) {
// Move the graphic
graphic.geometry = newLocation
// Or remove the graphic
overlay.graphics.remove(graphic)
}
推荐阅读
- cuda - 将数据从 CPU 传输到 GPU,反之亦然,具体在哪里?
- sqlite - 从多个sqlite数据库中提取数据到单个.csv?
- nexmo - 如何创建 NexmoClient 对象?
- javascript - 使用 javascript map() 将值转换为对象
- cassandra - 卡桑德拉抛出 NoHostAvailableException
- typescript - 通过 Firebase 函数从实时数据库更新数据
- firebase - 如果firebase用户中存在相同的电子邮件,如何在电子邮件表单字段上显示错误
- python - 解析两个参数错误:模块 'cv2.cv2' 没有属性 'read'
- php - Chrome 和 Firefox 阻止下载动态创建的 zip 文件,称这是不寻常的下载并且可能有害
- ios - iOS13 应用设置属性不再可编辑