Hi, Fiona1 - Where ESRI team works with FeatureSet? Right, when receiving the query results. So the pattern/example of FeatureSet in JSON = server query response in JSON format. It described in ArcGIS Server REST API help.2 - SampleMy JSON{
"displayFieldName" : "description",
"fieldAliases" : {
"objectid" : "Object ID",
"type" : "Type",
"description" : "Description"
},
"geometryType" : "esriGeometryPoint",
"spatialReference" : {
"wkid" : 4326
},
"fields" : [
{
"name" : "objectid",
"type" : "esriFieldTypeOID",
"alias" : "Object ID"
},
{
"name" : "type",
"type" : "esriFieldTypeInteger",
"alias" : "Type"
},
{
"name" : "description",
"type" : "esriFieldTypeString",
"alias" : "Description",
"length" : 1073741822
}
],
"features" : [
{
"attributes" : {
"objectid" : 2010,
"type" : 3,
"description" : "xzc"
},
"geometry" : {
"x" : -117.53253785200002,
"y" : 34.244472716000075
}
},
{
"attributes" : {
"objectid" : 2011,
"type" : 0,
"description" : "adf"
},
"geometry" : {
"x" : -100.62294522999991,
"y" : -15.344261442999937
}
}
]
}
JSON from ESRI help{
"displayFieldName" : "AREANAME",
"fieldAliases" : {
"ST" : "ST",
"POP2000" : "Population - 2000",
"AREANAME" : "City Name"
},
"fields" : [
{
"name" : "ST",
"alias" : "ST",
"type" : "esriFieldTypeString",
"length" : 2
},
{
"name" : "POP2000",
"alias" : "Population - 2000",
"type" : "esriFieldTypeInteger"
},
{
"name" : "AREANAME",
"alias" : "City Name",
"type" : "esriFieldTypeString",
"length" : 255
}
],
"geometryType" : "esriGeometryPoint",
"spatialReference" : {"wkid" : 4326},
"features" : [
{
"attributes" : {
"ST" : "CA",
"POP2000" : 3694820,
"AREANAME" : "Los Angeles"
},
"geometry" : { "x" : -118.37, "y" : 34.086 }
},
{
"attributes" : {
"ST" : "CA",
"POP2000" : 461522,
"AREANAME" : "Long Beach"
},
"geometry" : { "x" : -118.15, "y" : 33.80 }
}
]
}
JSON as query result http://goo.gl/Eys4N------------------App with input panel. Run, paste JSON in panel and push "Add features" button<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:esri="http://www.esri.com/2008/ags">
<s:layout>
<s:VerticalLayout gap="10"
paddingBottom="10"
paddingLeft="10"
paddingRight="10"
paddingTop="10" />
</s:layout>
<fx:Script>
<![CDATA[
import com.esri.ags.FeatureSet;
import com.esri.ags.Graphic;
import com.esri.ags.geometry.Geometry;
import com.esri.ags.symbols.SimpleFillSymbol;
import com.esri.ags.symbols.SimpleLineSymbol;
import com.esri.ags.symbols.SimpleMarkerSymbol;
import com.esri.ags.utils.JSONUtil;
import mx.controls.Alert;
private var sms:SimpleMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_TRIANGLE, 22, 0x00FF00);
private var sls:SimpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, 0xFF0000);
private var sfs:SimpleFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_DIAGONAL_CROSS, 0x0000FF);
protected function onAddButtonClick(event:MouseEvent):void
{
var jsonString:String = txtInput.text;
if (jsonString.length > 0)
{
try
{
var jsonObj:* = JSONUtil.decode(jsonString);
if (rbtnFeatureSetType.selected)
{
var featureSet:FeatureSet = FeatureSet.fromJSON(jsonObj);
if (featureSet && featureSet.features)
{
addGraphicsToMap(featureSet.features);
}
}
else
{
Alert.show("JSON string is valid", "Message");
// TODO: complete code
}
}
catch (error:Error)
{
trace(error.getStackTrace());
Alert.show("The input string cannot be parsed", "Error");
}
}
else
{
Alert.show("You must input valid json string in text area", "Error");
}
}
private function addGraphicsToMap(graphics:Array):void
{
if (graphicsLayer)
{
var isModified:Boolean = false;
for (var i:int; i < graphics.length; i++)
{
var graphic:Graphic = graphics;
if (graphic && graphic.geometry)
{
var geometry:Geometry = graphic.geometry;
switch (geometry.type)
{
case Geometry.MAPPOINT:
graphic.symbol = sms;
break;
case Geometry.POLYLINE:
graphic.symbol = sls;
break;
case Geometry.POLYGON:
graphic.symbol = sfs;
break;
}
trace("Added graphic id=" + graphicsLayer.add(graphic));
isModified = true;
}
}
if (isModified)
{
graphicsLayer.refresh();
}
}
}
]]>
</fx:Script>
<fx:Script>
<![CDATA[
protected function onClearButtonClick(event:MouseEvent):void
{
if (graphicsLayer)
{
graphicsLayer.clear();
}
}
]]>
</fx:Script>
<fx:Declarations>
<s:RadioButtonGroup id="rbtnGroup"/>
</fx:Declarations>
<s:Panel title="Map panel"
width="100%"
height="100%">
<s:layout>
<s:VerticalLayout gap="5"
verticalAlign="middle"
horizontalAlign="center" />
</s:layout>
<s:Button label="Clear graphics"
click="onClearButtonClick(event)" />
<esri:Map id="map">
<esri:ArcGISTiledMapServiceLayer id="baseLayer"
url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer"
alpha="0.7" />
<esri:GraphicsLayer id="graphicsLayer" />
</esri:Map>
</s:Panel>
<s:Panel title="Input panel"
width="100%"
height="100%">
<s:layout>
<s:VerticalLayout gap="5"
verticalAlign="middle"
horizontalAlign="center"
paddingBottom="5"/>
</s:layout>
<s:TextArea id="txtInput"
width="100%"
height="100%" />
<s:HGroup width="100%"
horizontalAlign="center"
gap="20">
<s:RadioButton id="rbtnFeatureSetType"
label="is FeatureSet"
selected="true"
group="{rbtnGroup}"/>
<s:RadioButton id="rbtnCustomType"
label="is not FeatureSet"
group="{rbtnGroup}" />
<s:Button label="Add features"
click="onAddButtonClick(event)" />
</s:HGroup>
</s:Panel>
</s:Application>
P.S. here similar discussion with sample for oldest APIP.S.2 The JSON Validator