Search code examples
iosswiftesriesri-maps

Feature layer markers not getting displayed in Esri ios SDK


I'm using ESRI iOS SDK 10.2.5,my app was built using swift 2.3 and i have converted it to 3.2 now,everythng works fine.

but there's a little problem in displaying the markers in feature layer which used to work correctly in swift 2.3

the method signature have slightly changed after migration .

here's the method signature for 2.3 (works fine):

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()
}

method signature for 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()
}

Model class for manipulating features :

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")

}
}

i have debugged the code and came to know that the featureSet.feature has no elements in swift 3.2 but has elements in 2.3,that is why it is not entering the loop and setting the graphics to the marker

why this happens,since this method is from esri's delegate..is this bug from their end ?

please help me in fixing this issue,if anyone has any idea on this


Solution

  • there's nothing wrong in migration from 2.3 to 3.2,only thing which might break according to me is the code in your model class

    try changing your model class in the second init from

    self.isActive = aDecoder.decodeObject(forKey: "isActive") as? Bool
    

    to

    self.isActive = aDecoder.decodeBool(forKey: "isActive")
    

    you are trying to read a boolean value like object, which might be the issue