移动 and/or 移除 ArcGIS 图形图层中的标记

Move and/or Remove Markers in ArcGIS Graphics Layer

我正在使用 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分配了一个属性"marker:markerKey",即marker位置信息存储的唯一数据库记录号(key),作为marker ID。

将初始标记添加到叠加层后,应用程序 "Listens" 到数据库以获取以下事件:

当标记被移动或删除时,数据库侦听器会收到通知并传递被移动(或删除)的标记的记录号(键)。如果移动了标记,则记录将包含新的纬度和经度信息。

我已经尝试读取图形覆盖并确定它是一个包含在 NSMutable 数组中的集合。我可以读取所有属性如下:

let graphicsCollection = self.overlay.graphics.mutableArrayValue(forKey: "attributes")
print(graphicsCollection)

结果是:

(
        {
        marker = "-KlRW2_rba1zBrDPpxSl";
    },
{
        marker = "-Lu915xF3zQp4dIYnsP_";
    }
)

我可以对 "geometry" 执行相同的操作并获取 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"
)

我无法确定如何获取属性数组的 "index"(例如上面的标记“-KlRW2_rba1zBrDPpxSl”应该有一个索引 [0]),所以我可以使用它"index" 以访问适当的 AGSPoint 并更新纬度和经度或删除标记。

在此先感谢您的帮助。

如果您想移动标记(即 AGSGraphic),您需要获取 AGSGraphic 本身并修改 geometry 属性。我认为跳转到 mutableArrayValue() 调用中的 "geometry" 有点搬起石头砸自己的脚。

我会这样处理:

let searchMarker = "-KlRW2_rba1zBrDPpxSl"
let newLocation = AGSPointMakeWGS84(40.7128, -74.0060) // NYC
if let graphic = (overlay.graphics as? [AGSGraphic])?.first(where: { 
    ([=10=].attributes["marker"] as? String) == searchMarker
}) {
    // Move the graphic
    graphic.geometry = newLocation
    // Or remove the graphic
    overlay.graphics.remove(graphic)
}