我正在使用 ESRI iOS SDK 10.2.5,我的应用程序是使用 swift 2.3 构建的,我现在已将其转换为 3.2,一切正常。
但是在要素层中显示标记时存在一个小问题,这些标记曾经在 swift 2.3 中正常工作
迁移后方法签名略有变化。
这是 2.3 的方法签名(工作正常):
func featureLayer(featureLayer: AGSFeatureLayer!, operation op: NSOperation!, didQueryFeaturesWithFeatureSet featureSet: AGSFeatureSet!) {
if (featureLayer == self.featureLayer) {
// featureset has more than 1 element
for poi in featureSet.features {
var attr = [String: AnyObject]()
attr["NAME"] = poi.allAttributes()[LanguageController.localizedString("poi_detail_name")] as? String;
attr["DETAIL"] = poi.allAttributes()["PHONE_NUMBER"] as? String;
attr["CATEGORY_EN"] = poi.allAttributes()["FACILITY_CAT_EN"] as? String;
attr["IS_OFFICE"] = false;
attr["IS_HDKP"] = false
let graphic = AGSGraphic(
geometry: poi.geometry,
symbol: getSymbolForGraphic(poi as! AGSGraphic),
attributes: attr)
self.mapLayer.addGraphic(graphic);
}
SVProgressHUD.dismiss()
}
swift 3.2 的方法签名:
func featureLayer(_ featureLayer: AGSFeatureLayer!, operation op: Operation!, didQueryFeaturesWith featureSet: AGSFeatureSet!) {
if (featureLayer == self.featureLayer) {
// problem here,featureset.feature has 0 elements
for poi in featureSet.features {
var attr = [String: Any]()
attr["NAME"] = (poi as AnyObject).allAttributes()[LanguageController.localizedString("poi_detail_name")] as? String;
attr["DETAIL"] = (poi as AnyObject).allAttributes()["PHONE_NUMBER"] as? String;
attr["CATEGORY_EN"] = (poi as AnyObject).allAttributes()["FACILITY_CAT_EN"] as? String;
attr["IS_OFFICE"] = false as Any
attr["IS_HDKP"] = false as Any
let graphic = AGSGraphic(
geometry: (poi as AnyObject).geometry,
symbol: getSymbolForGraphic(poi as! AGSGraphic),
attributes: attr)
self.mapLayer.addGraphic(graphic);
}
SVProgressHUD.dismiss()
}
用于操作特征的模型类:
class POICategory: NSObject, NSCoding
{
var isActive : Bool;
var name : String;
var nameFilter : String;
var key : String;
init(isActive: Bool,name : String, nameFilter: String, key: String){
self.isActive = isActive;
self.name = name;
self.nameFilter = nameFilter;
self.key = key;
}
required init?(coder aDecoder: NSCoder) {
self.isActive = aDecoder.decodeObject(forKey: "isActive") as? Bool
self.name = aDecoder.decodeObject(forKey: "name") as! String
self.nameFilter = aDecoder.decodeObject(forKey: "nameFilter") as! String
self.key = aDecoder.decodeObject(forKey: "key") as! String
}
func encode(with aCoder: NSCoder) {
aCoder.encode(self.isActive, forKey: "isActive")
aCoder.encode(self.name, forKey: "name")
aCoder.encode(self.nameFilter, forKey: "nameFilter")
aCoder.encode(self.key, forKey: "key")
}
}
我已经调试了代码并知道 featureSet.feature 在 swift 3.2 中没有元素,但在 2.3 中有元素,这就是它没有进入循环并将图形设置为标记的原因
为什么会发生这种情况,因为这个方法来自 esri 的委托..这个错误是他们的结果吗?
请帮我解决这个问题,如果有人对此有任何想法