I am trying to save the length of drawn graphic in the feature attribute. I have got the length of line feature. However, When I try to add it in editsStartingHandler I never have the calculated length available. I know this is because of the Async nature of flex, but I wanted to know where could I add the appropriate event listener function.
In populateEditor(), we have
oplList.layer.removeEventListener(FeatureLayerEvent.SELECTION_COMPLETE, featureLayer_selectionComplete);
oplList.layer..addEventListener(FeatureLayerEvent.EDITS_STARTING, editsStartingHandler);
//oplList.layer..addEventListener(GeometryServiceEvent.LENGTHS_COMPLETE, editsStartingHandler); This returns geometry event which I cannot use in editsStartingHandler().
oplList.layer.addEventListener(FeatureLayerEvent.SELECTION_COMPLETE, featureLayer_selectionComplete, false, 1);
private function editsStartingHandler(event:FeatureLayerEvent):void
{
//////////////////////////////////////////NEW ADDITION FOR ADDING LENGTH ON MAP /////////////////////////////////////////////////
var geom:Geometry = new Geometry();
var spatialref:Number=102003;
var outSR:SpatialReference = new SpatialReference(spatialref);
geom=event.adds[0].geometry;
geometryService.project([ geom ], outSR);
//var tok1:AsyncToken =geometryService.project([ geom ], outSR, new AsyncResponder(projectCompleteHandler, proj_fault, tok1));
//tok.addResponder(new AsyncResponder(projectCompleteHandler, proj_fault, tok));
var polyline:Polyline = geom as Polyline;
//ViewerContainer.addEventListener("lengthCalc", sendServer);
Alert.show("DONE!!!!");
Alert.show(lengthFea.toString());
trace("Before event.add");
if (event.adds)
{
event.adds[0].attributes['transformation_transaction_id'] = ttid;
event.adds[0].attributes['user_id'] = userIDNum;
event.adds[0].attributes['user_name'] = userName;
event.adds[0].attributes['active'] = _activeNo;
event.adds[0].attributes['phase'] = "ACTIVE";
event.adds[0].attributes['len'] = lengthFea;
}
}
private function editsStartingHandler(event:FeatureLayerEvent):void
{
//////////////////////////////////////////NEW ADDITION FOR ADDING LENGTH ON MAP /////////////////////////////////////////////////
var geom:Geometry = new Geometry();
var spatialref:Number=102003;
var outSR:SpatialReference = new SpatialReference(spatialref);
geom=event.adds[0].geometry;
geometryService.project([ geom ], outSR);
//var tok1:AsyncToken =geometryService.project([ geom ], outSR, new AsyncResponder(projectCompleteHandler, proj_fault, tok1));
//tok.addResponder(new AsyncResponder(projectCompleteHandler, proj_fault, tok));
var polyline:Polyline = geom as Polyline;
//ViewerContainer.addEventListener("lengthCalc", sendServer);
Alert.show("DONE!!!!");
Alert.show(lengthFea.toString());
trace("Before event.add");
if (event.adds)
{
event.adds[0].attributes['_id'] = id;
event.adds[0].attributes['user_id'] = userIDNum;
event.adds[0].attributes['user_name'] = userName;
event.adds[0].attributes['active'] = _activeNo;
event.adds[0].attributes['phase'] = "ACTIVE";
}
}
private function projectCompleteHandler(event:GeometryServiceEvent):void
{
var geom:Geometry = (event.result as Array)[0];
var lengthsParameters:LengthsParameters = new LengthsParameters();
var pLine:Polyline = Polyline(geom);
lengthsParameters.geodesic = true;
lengthsParameters.polylines = [ pLine ];
//var tok2:AsyncToken =geometryService.lengths(lengthsParameters, new AsyncResponder(lengthsCompleteHandler, proj_fault, tok2));
geometryService.lengths(lengthsParameters);
}
//private function lengthsCompleteHandler(result:Object, token:AsyncToken):void
private function lengthsCompleteHandler(event:GeometryServiceEvent):void
{
var leng = (event.result as Array)[0]*3.28;
var data:Object=
{
length:leng
}
ViewerContainer.dispatchEvent( new AppEvent("lengthCalc",data) );
}
//private function sendServer(event:AppEvent):void
{
//var lengthFea:String=event.data.length.toString();
//Alert.show(lengthFea.toString());
}
I am trying to find the Drawend event or the place where I can add the event listener before events.add[] and add a events.add[] in that listener function . I have used event listeners and asyc token responder...however I cannot catch the drawend event in this widget. Some help would be greatly appreciated. Thanks.