ArcGISForFlex地图内嵌饼状图2011年7月制定及修订记录版本完成日期编写/修订纪要编写者备注1.02011-07-26新撰写韩源萌I目录11地图内嵌饼状图效果图23主要制作思路:继承GraphicsLayer对象,重写add方法;重写clear方法;重写settergraphicProvider。在GraphicsLayer添加Graphic对象时,结合统计信息进行饼状图绘制。仿照Flex中的Piechart对象,结合Pieseries对象的结构设计能够为地图内嵌饼状图提供统计信息的对象。类对象:PieChartLayer、PieLayerSeries。2PieLayerSeries类对象设计主要属性内容2.1主要内容包括:进行统计的字段集(_fields)、各个饼角的填充4样式(_fills或者_fillFunction)、分类结果信息(_labelPosition、_labelFunction、_labelSymbol、_labelLineSymbol)。变量含义顾名思义。privatevar_labelFunction:Function;privatevar_labelLineSymbol:Symbol;privatevar_labelSymbol:Symbol;privatevar_showToolTip:Boolean=true;privatevar_fills:Array;privatevar_fillFunction:Function;privatevar_outerRadius:Number;privatevar_outerRadiusFunction:Function;privatevar_precision:int=2;privatevar_fields:Array;privatevar_labelPosition:String=none;具体的getter、setter2.2其具体的getter和setter如下:publicfunctiongetshowToolTip():Boolean{return_showToolTip;}publicfunctionsetshowToolTip(value:Boolean):void{_showToolTip=value;}publicfunctiongetlabelSymbol():Symbol{return_labelSymbol;}publicfunctionsetlabelSymbol(value:Symbol):void{_labelSymbol=value;}publicfunctiongetlabelLineSymbol():Symbol5{return_labelLineSymbol;}publicfunctionsetlabelLineSymbol(value:Symbol):void{_labelLineSymbol=value;}[Inspectable(category=General,enumeration=callout,outside,inside,none,defaultValue=none)]publicfunctiongetlabelPosition():String{return_labelPosition;}publicfunctionsetlabelPosition(value:String):void{_labelPosition=value;}publicfunctiongetprecision():int{return_precision;}publicfunctionsetprecision(value:int):void{_precision=value;}publicfunctiongetfields():Array{return_fields;}publicfunctionsetfields(value:Array):void{_fields=value;}publicfunctiongetouterRadiusFunction():Function{6return_outerRadiusFunction;}publicfunctionsetouterRadiusFunction(value:Function):void{_outerRadiusFunction=value;}publicfunctiongetouterRadius():Number{return_outerRadius;}publicfunctionsetouterRadius(value:Number):void{_outerRadius=value;}publicfunctiongetfillFunction():Function{return_fillFunction;}publicfunctionsetfillFunction(value:Function):void{_fillFunction=value;}publicfunctiongetfills():Array{return_fills;}publicfunctionsetfills(value:Array):void{_fills=value;}publicfunctiongetlabelFunction():Function{return_labelFunction;}7publicfunctionsetlabelFunction(value:Function):void{_labelFunction=value;}3PieChartLayer类对象设计主要属性内容3.1主要内容包括:添加进来的原始Graphic对象集(_graphicOriginalProvider)、统计信息集(_series)、饼状图偏转角度(_xRotation、_yRotation)。privatevar_graphicOriginalProvider:ArrayCollection;privatevar_series:Array;privatevar_xRotation:Number=180;privatevar_yRotation:Number=180;变量含义顾名思义。具体的getter、setter3.2publicfunctiongetxRotation():Number{return_xRotation;}publicfunctionsetxRotation(value:Number):void{_xRotation=value;}publicfunctiongetyRotation():Number{return_yRotation;}publicfunctionsetyRotation(value:Number):void{8_yRotation=value;}publicfunctiongetseries():Array{return_series;}publicfunctionsetseries(value:Array):void{value=value==null?[]:value;_series=value;varn:int=value.length;for(vari:int=0;in;++i){if(value[i]isPieChartLayer){_series.push(value[i]);}}}重写的主要方法3.3GraphicsLayer对象的add、clear、settergraphicProvider方法。3.3.1重写add方法overridepublicfunctionadd(graphic:Graphic):String{if(this._graphicOriginalProvider.contains(graphic)==false){this._graphicOriginalProvider.addItem(graphic);}returnPrepareGraphicFunction(graphic).join(',');}9overridepublicfunctiongetgraphicProvider():Object{returnsuper.graphicProvider();}3.3.2重写settergraphicProvider方法overridepublicfunctionsetgraphicProvider(value:Object):void{if(valueisArray){value=newArrayCollection(valueasArray);}elseif(valueisICollectionView){}elseif(valueisIList){value=newListCollectionView(valueasIList);}elseif(valueisXMLList){value=newXMLListCollection(XMLList(value));}elseif(value!=null){value=newArrayCollection([value]);}else{value=newArrayCollection();}_graphicOriginalProvider=ArrayCollection(value);foreach(vargra:Graphicin_graphicOriginalProvider){PrepareGraphicFunction(gra);}}103.3.3重写clear方法overridepublicfunctionclear():void{super.clear();this._graphicOriginalProvider=newArrayCollection();}处理饼状图绘制3.4PrepareGraphicFunction方法,在重写的add方法和settergraphicProvider方法中调用。protectedfunctionPrepareGraphicFunction(GraItem:Graphic):Array{varresult:Array=newArray();try{if(GraItem!=null&&GraItem.attributes!=null){if(this._series.length!=0){foreach(varseriesItem:PieLayerSeriesinthis._series){varfieldItems:Array=seriesItem.fields;varcount:Number=0;foreach(varfieldItem:StringinfieldItems){count+=Number(GraItem.attributes[fieldItem]);}varpresentPostion:Number=0;for(vari:int=0;ifieldItems.length;i++){varnewGra:Graphic=newGraphic();if(seriesItem.fillFunction!=null){newGra.symbol=seriesItem.fillFunction(newGra);}11elseif(seriesItem.fills.lengthi){newGra.symbol=seriesItem.fills[i];}else{varcolor:uint=uint(Math.random()*0xffffff);varsls:SimpleLineSymbol=newSimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,0x000000,1);seriesItem.fills[i]=newSimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,color,0.8,sls);new