GNServer(几何网络分析)扩展ArcGIS Rest—Flex Widget

GNTraceWidget.xml


GNTraceWidget会使用到的一些参数,在GNTraceWidget.xml文件中设置,有些参数根据规范可以在xml文件一次配置好,不需要提供用户交互修改的接口。包括GNServer扩展的地址、输出的edge属性字段、输出的junction属性字段、trace的类型。


<?xml version="1.0" ?>
<configuration>
	<gnserver>http://heyb/ArcGIS/rest/services/ESRISH/SewerNetwork/MapServer/exts/GNServer</gnserver>
    <edgeoutfields>
    	<edgeoutfield>OBJECTID</edgeoutfield>
    	<edgeoutfield>SEWER_ID</edgeoutfield>
    	<edgeoutfield>LINE_TYPE</edgeoutfield>
    	<edgeoutfield>LINETYPE_CODE</edgeoutfield>
    </edgeoutfields>
    <junctionoutfields>
    	<junctionoutfield>OBJECTID</junctionoutfield>
    	<junctionoutfield>SEWERPT_ID</junctionoutfield>
    	<junctionoutfield>NODE_TYPE</junctionoutfield>
    </junctionoutfields>
    <tracetypes>
    	<tracetype>Trace Downstream</tracetype>
    	<tracetype>Trace Upstream</tracetype>
    	<tracetype>Find Common Ancestors</tracetype>
		<tracetype>Find Connected</tracetype>
		<tracetype>Find Loops</tracetype>
		<tracetype>Find Disconnected</tracetype>
		<tracetype>Find Path Upstream</tracetype>
		<tracetype>Find Path</tracetype>
		<tracetype>Find Upstream Accumulation</tracetype>
    </tracetypes/>
</configuration>


GNTraceWidget


GNTraceWidget用户的界面,设置分析的相关参数,执行Trace功能,并显示分析结果。

UI

GNServer(几何网络分析)扩展ArcGIS Rest—Flex Widget_第1张图片

GNServer(几何网络分析)扩展ArcGIS Rest—Flex Widget_第2张图片


根据xml配置初始Widget

if (configXML)
{
	//parse out fields, trace types from xml config file
	gnTraceTask.url = configXML.gnserver[0];
	edgeOutFields = configXML..edgeoutfield;
	gnTrace.edgeOutFields = "";
	for (var i:int = 0; i < edgeOutFields.length() - 1; i++)
	{
		gnTrace.edgeOutFields += edgeOutFields[i] + ",";
	}
	gnTrace.edgeOutFields += edgeOutFields[edgeOutFields.length() - 1];
	
	gnTrace.junctionOutFields = "";
	junctionOutFields = configXML..junctionoutfield;
	for (i = 0; i < junctionOutFields.length() - 1; i++)
	{
		gnTrace.junctionOutFields += junctionOutFields[i] + ",";
	}
	gnTrace.junctionOutFields += junctionOutFields[junctionOutFields.length() - 1];
	
	var traceTypes:XMLList = configXML..tracetype;
	var traceTypesArray:ArrayList = new ArrayList();
	for (i = 0; i < traceTypes.length(); i++)
	{
		traceTypesArray.addItem(traceTypes[i]);						
	}
	traceTypeComboBox.dataProvider = traceTypesArray;
	traceTypeComboBox.selectedIndex = 0;
	
	gnTraceTask.queryGNLayerInfos(new AsyncResponder(onGNLayerInfos, onFault));
}

添加分析的Flags、Barries

//ativate point draw tool to input flags
private function activateDrawTool(value:String, mode:String):void
{				
	var status:String;
	switch (value)
	{
		case JUNCTION_FLAGS:
		{
			drawSymbol = juncFlagsSymbol;
			status = "Place flags";
			break;
		}
		case EDGE_FLAGS:
		{
			drawSymbol = edgeFlagsSymbol;
			status = "Place flags";
			break;
		}
		case JUNCTION_BARRIERS:
		{
			drawSymbol = juncBarriersSymbol;
			status = "Place barriers";
			break;
		}
		case EDGE_BARRIERS:
		{
			drawSymbol = edgeBarriersSymbol;
			status = "Place barriers";
			break;
		}
	}
	currentTraceOperation = value;
	setMapAction(DrawTool.MAPPOINT, status, drawSymbol, drawEnd);				
}

设置参数执行分析

//trace button handler
protected function gnTraceButton_clickHandler(event:MouseEvent):void
{
	//set some parameters for tracing
	gnTrace.traceType = traceTypeComboBox.selectedItem.toString();
	if (gnTrace.traceType == "Find Common Ancestors" && inputJunctionFlags.features.length + inputEdgeFlags.features.length < 2)
	{
		Alert.show("There must be more than 2(including) flags for this type of tracing!", "Warning");
		resultStatusLabel.text = "";
		return;
	}
	resultStatusLabel.text = "Tracing....";
	gnTrace.junctionFlags = inputJunctionFlags;
	gnTrace.edgeFlags = inputEdgeFlags;
	gnTrace.junctionBarriers = inputJunctionBarriers;
	gnTrace.edgeBarriers = inputEdgeBarriers;
	
	gnTrace.disableLayers = "";
	var layerId:String;
	for(var index:int = 0; index < disableLayersCBL.selectedItems.length; index++)
	{
		layerId = disableLayersCBL.selectedItems[index].id;
		if (index == disableLayersCBL.selectedItems.length - 1)
			gnTrace.disableLayers += "fcid " + layerId;
		else
			gnTrace.disableLayers += "fcid " + layerId + ",";
	}		
	
	gnTraceTask.execute(gnTrace, new AsyncResponder(onResult, onFault));
}

处理分析的结果

//hanlder while traced results succeeded to return
protected function onResult(featureSet:FeatureSet, token:Object = null):void
{
	var juncFeatureSet:FeatureSet = gnTraceTask.junctionsFeatureSet;
	var edgesFeatureSet:FeatureSet = gnTraceTask.edgesFeatureSet;
	//clear results returned last time
	tracedJunctionsGraphicLayer.clear();
	tracedEdgesGraphicLayer.clear();
	//bind the new results
	gnTraceEdgeResultAC = CreateTracedEdgeResults(edgesFeatureSet, null);
	gnTraceJunctionResultAC = CreateTracedJunctionResults(juncFeatureSet, null);
	resultStatusLabel.text = "Tracing succeeded, edges : " + edgesFeatureSet.features.length.toString() 
		+ " junctions : " +  juncFeatureSet.features.length.toString();

}			

//create edge GNTraceResult arraycollection for resultlist binding, and add traced edges to graphicslayer
private function CreateTracedEdgeResults(featureSet:FeatureSet, queryFields:XMLList):ArrayCollection
{
	var result:ArrayCollection = new ArrayCollection();
	
	for each (var graphic:Graphic in featureSet.features)
	{
		var gnTraceResult:GNTraceResult = new GNTraceResult();
		gnTraceResult.title = graphic.attributes.OBJECTID;
		var edgeAttr:String = "";
		for (var ii:int = 0; ii < edgeOutFields.length(); ii++)
		{
			edgeAttr += edgeOutFields[ii] + ": " + graphic.attributes[edgeOutFields[ii]] + "\n";
		}
		gnTraceResult.content = edgeAttr;
		gnTraceResult.point = getGeomCenter(graphic);
		gnTraceResult.symbol = edgeSymbol;
		gnTraceResult.geometry = graphic.geometry;
		tracedEdgesGraphicLayer.add(graphic);					
		result.addItem(gnTraceResult);
	}				
	return result;				
}

//create juncitons GNTraceResult arraycollection for resultlist binding, and add juncitons edges to graphicslayer
private function CreateTracedJunctionResults(featureSet:FeatureSet, queryFields:XMLList):ArrayCollection
{
	var result:ArrayCollection = new ArrayCollection();				
	for each (var graphic:Graphic in featureSet.features)
	{
		var gnTraceResult:GNTraceResult = new GNTraceResult();
		gnTraceResult.title = graphic.attributes.OBJECTID;
		var juncAttr:String = "";
		for (var ii:int = 0; ii < junctionOutFields.length(); ii++)
		{
			juncAttr += junctionOutFields[ii] + ": " + graphic.attributes[junctionOutFields[ii]] + "\n";
		}
		gnTraceResult.content = juncAttr;
		gnTraceResult.point = getGeomCenter(graphic);
		gnTraceResult.symbol = juncSymbol;
		gnTraceResult.geometry = graphic.geometry;
		tracedJunctionsGraphicLayer.add(graphic);					
		result.addItem(gnTraceResult);
	}				
	return result;				
}

来两张结果图

GNServer(几何网络分析)扩展ArcGIS Rest—Flex Widget_第3张图片

GNServer(几何网络分析)扩展ArcGIS Rest—Flex Widget_第4张图片

你可能感兴趣的:(网络,function,REST,Flex,扩展,binding)