Esri ios SDK 中未显示要素图层标记
Feature layer markers not getting displayed in Esri ios SDK
我正在使用 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:
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 的委托..这个错误来自他们吗?
如果有人对此有任何想法,请帮助我解决这个问题
从 2.3 迁移到 3.2 没有任何问题,根据我的说法,唯一可能会中断的是您模型中的代码 class
尝试在
的第二个初始化中更改您的模型 class
self.isActive = aDecoder.decodeObject(forKey: "isActive") as? Bool
到
self.isActive = aDecoder.decodeBool(forKey: "isActive")
您正在尝试读取对象之类的布尔值,这可能是问题所在
我正在使用 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:
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 的委托..这个错误来自他们吗?
如果有人对此有任何想法,请帮助我解决这个问题
从 2.3 迁移到 3.2 没有任何问题,根据我的说法,唯一可能会中断的是您模型中的代码 class
尝试在
的第二个初始化中更改您的模型 classself.isActive = aDecoder.decodeObject(forKey: "isActive") as? Bool
到
self.isActive = aDecoder.decodeBool(forKey: "isActive")
您正在尝试读取对象之类的布尔值,这可能是问题所在