GNTrace
Geometric Network Trace需要的参数由GNTrace传入。
GNTrace定义
package com.esrichina { import com.esri.ags.FeatureSet; public class GNTrace { private var _edgeFlags:FeatureSet; private var _junctionFlags:FeatureSet; private var _edgeBarriers:FeatureSet; private var _junctionBarriers:FeatureSet; private var _traceType:String; private var _disableLayers:String; private var _edgeOutFields:String; private var _junctionOutFields:String; public function GNTrace() { } } }
GNTraceTask
GNTraceTask实现GeometricNetwork Trace的功能,包括queryGNLayerInfos和execute两个方法,前者查询Geometric Network包含的所有图层信息;后者执行Trace功能并返回结果(edge、junction)。
查询Gemetric Network图层信息
public function queryGNLayerInfos(responder:IResponder=null):AsyncToken{ var urlVariable:URLVariables = new URLVariables(); urlVariable.f = "json"; return (sendURLVariables(null, urlVariable, responder, handleLayerInfosDecodedObject)); }
private function handleLayerInfosDecodedObject(decodedObject:Object, asyncToken:AsyncToken):void{ var responder:IResponder; _gnLayerInfos = decodedObject["Geometric Network Layers"]; for each (responder in asyncToken.responders) { responder.result(_gnLayerInfos); }; }
public function execute(gnTrace:GNTrace, responder:IResponder=null):AsyncToken{ var urlVariable:URLVariables = new URLVariables(); urlVariable.f = "json"; urlVariable.JunctionFlags = gnTrace.junctionFlags.convertToJSON();// "{\"features\":[{\"geometry\":{\"x\":557456.645, \"y\":42840.961}}]}"; urlVariable.EdgeFlags = gnTrace.edgeFlags == null ? "" : gnTrace.edgeFlags.convertToJSON(); urlVariable.JunctionBarriers = gnTrace.junctionBarriers == null ? "" : gnTrace.junctionBarriers.convertToJSON(); urlVariable.EdgeBarriers = gnTrace.edgeBarriers == null ? "" : gnTrace.edgeBarriers.convertToJSON(); urlVariable.TraceType = gnTrace.traceType;// "Trace Downstream"; urlVariable.DisableLayers = gnTrace.disableLayers; //""; urlVariable.EdgeOutFields = gnTrace.edgeOutFields; urlVariable.JunctionOutFields = gnTrace.junctionOutFields; return (sendURLVariables("/Trace", urlVariable, responder, handleDecodedObject)); }
private function handleDecodedObject(decodedObject:Object, asyncToken:AsyncToken):void{ var responder:IResponder; edgesFeatureSet = new FeatureSet(); junctionsFeatureSet = new FeatureSet(); edgesFeatureSet.features = []; junctionsFeatureSet.features = []; var edges:Array = decodedObject.Edges; var junctions:Array = decodedObject.Junctions; for(var egIndex:int = 0; egIndex < edges.length; egIndex++) { var paths:Array = edges[egIndex].geometry.paths; var plinePaths:Array = new Array(); for (var pthIndex:int = 0; pthIndex < paths.length; pthIndex++) { var pts:Array = paths[pthIndex]; var plinePts:Array = new Array(); for(var ptIndex:int = 0; ptIndex < pts.length; ptIndex++) { var plinePt:MapPoint = new MapPoint((Number)(pts[ptIndex][0]), (Number)(pts[ptIndex][1])); plinePts.push(plinePt); } plinePaths.push(plinePts); } var pline:Polyline = new Polyline(plinePaths); var linegra:Graphic = new Graphic(pline); linegra.attributes = edges[egIndex].attributes; edgesFeatureSet.features.push(linegra); } for(var jcIndex:int = 0; jcIndex < junctions.length; jcIndex++) { var pt:MapPoint = new MapPoint((Number)(junctions[jcIndex].geometry.x), (Number)(junctions[jcIndex].geometry.y)); var ptgra:Graphic = new Graphic(pt); ptgra.attributes = junctions[jcIndex].attributes; junctionsFeatureSet.features.push(ptgra); } for each (responder in asyncToken.responders) { responder.result(edgesFeatureSet); }; }