Greetings,
I am attempting to add features from a Flex application using the REST API addFeature call. I pieced together a function from various sources But it doesn't seem to do much:
private function addGraphicToEasementLayer(graphic:Graphic):void | |||
{ | |||
var easementJSON:Object = graphic.toJSON(); | |||
trace("the Easement is " + easementJSON); | |||
var httpService:HTTPService = new HTTPService(); | |||
httpService.url = 'http://domain/ArcGIS/rest/services/SharedMaps/GreenwayEasementsTest/FeatureServer/1/addFeatures?f=js... | |||
httpService.send(); | |||
} |
This function runs and does not produce an error. However, it also does not add my easement feature.Has anyone tried adding JSON Features to a featureService using both the Flex and REST APIs? Any tips, tricks, points or general information will be greatly appreciated.
Thanks, Tyler
Solved! Go to Solution.
You have to POST the URLRequest and assign the variables using URLVariables. What I really needed to do is something like this:
private function addGraphicToEasementLayer(graphic:Graphic):void
{
var easementJSON:Object = graphic.toJSON();
var easmentString:String = "["+JSONUtil.encode(easementJSON)+"]";
trace("the Easement is " + easmentString);
var request:URLRequest = new URLRequest('http://yourdomain/ArcGIS/rest/services/SharedMaps/GreenwayEasementsTest/FeatureServer/0/addFeatures'...
var urlVars:URLVariables = new URLVariables();
urlVars.f = "json";
urlVars.features = easmentString;
urlVars.gdbVersion = "";
urlVars.rollbackOnFailure = true;
request.data = urlVars;
request.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.load(request);
}
Works like a charm!
Hope this helps someone else.
Thanks, Tyler
You have to POST the URLRequest and assign the variables using URLVariables. What I really needed to do is something like this:
private function addGraphicToEasementLayer(graphic:Graphic):void
{
var easementJSON:Object = graphic.toJSON();
var easmentString:String = "["+JSONUtil.encode(easementJSON)+"]";
trace("the Easement is " + easmentString);
var request:URLRequest = new URLRequest('http://yourdomain/ArcGIS/rest/services/SharedMaps/GreenwayEasementsTest/FeatureServer/0/addFeatures'...
var urlVars:URLVariables = new URLVariables();
urlVars.f = "json";
urlVars.features = easmentString;
urlVars.gdbVersion = "";
urlVars.rollbackOnFailure = true;
request.data = urlVars;
request.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.load(request);
}
Works like a charm!
Hope this helps someone else.
Thanks, Tyler