/** * Sample for Daniel */ package ee.alphagis { import com.esri.ags.FeatureSet; import com.esri.ags.Graphic; import com.esri.ags.geometry.Geometry; import com.esri.ags.geometry.MapPoint; public class Entity { private var _aaa:String; private var _bbb:String; private var _point:MapPoint; public function get aaa():String { return _aaa; } public function get bbb():String { return _bbb; } public function get point():MapPoint { return _point; } public function Entity(a:String = null, b:String = null, g:MapPoint = null) { _aaa = a; _bbb = b; _point = g; } /** * @return string in JSON format */ public function convertToJson():String { var attr:Object = new Object(); attr.a = _aaa; attr.b = _bbb; var gr:Graphic = new Graphic(_point, null, attr); // we need to create FeatureSet for Json converting var grArray:Array = new Array(); grArray.push(gr); var fs:FeatureSet = new FeatureSet(grArray); fs.geometryType = Geometry.MAPPOINT; return fs.toJSON(); } /** * Convert first feature in feature set to Entity * @param json is string in JSON format, json describes FeatureSet * @retun Entity */ public static function entityFromJson(json:String):Entity { // Note the json describes FeatureSet not Graphic // Look and find in convertToJson() how to create FeatureSet or use API help if (json != null) { var fs:FeatureSet = FeatureSet.fromJSON(json); if (fs != null) { // get array of graphics from feature set var arr:Array = fs.features as Array; if (arr != null && arr.length > 0) { // get graphic from array var gr:Graphic = arr[0] as Graphic; if (gr != null) { var gValue:MapPoint = gr.geometry as MapPoint; var aValue:String; var bValue:String; var attr:Object = gr.attributes; if (attr != null) { // get attributes from your graphic if (attr.hasOwnProperty("a")) { aValue = attr["a"].toString(); } if (attr.hasOwnProperty("b")) { bValue = attr["b"].toString(); } } return new Entity(aValue, bValue, gValue); } } } } return null; } } }
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.