态度标绘模块

config.xml文件的配置如下:

        <widget label="态势标绘" icon="assetsimpact_area_over.png"
            config="widgets/esri/NewPlot/NewPlotWidget.xml" url="widgets/esri/NewPlot/NewPlotWidget.swf" />

源代码目录如下:

1495a.com 1

分界面效果:

1495a.com 2

大意的思绪如下:利用arcgis api  for
flex的draw绘制接口以及三个第1方的绘图api
PlotAPI4flex,来绘制种种箭头以及多方形、圆形等图形,文本和图纸的绘图用的是arcgis
api。

NewPlotWidget.xml:配置总计周长和面积的单位音讯等等

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <geometryservice>http://localhost:6080/arcgis/rest/services/Utilities/Geometry/GeometryServer</geometryservice>
    <spatialref>4326</spatialref>
    <distanceunit>千米</distanceunit>      
    <areaunit>平方公里</areaunit>  
    <showMeasurements>显示测量结果</showMeasurements>    
    <perimeter>周长:</perimeter> 
    <arealabel>面积:</arealabel>

</configuration>

1495a.com,NewPlotWidget.mxml:

轻易易行的叙说一下思路好了

1.响应绘制的风云,要激活draw工具:

            //集成后的标会响应函数            
            private function activateDrawTool(event:MouseEvent):void
            {
                    this.drawToolbar.deactivate();
                    graphicsLayer.visible=true;                        
                    selectedDrawingIcon =BorderImage(event.currentTarget);
                    clearSelectionFilter();
                    selectedDrawingIcon.filters = [ glowFilter ];

                    finishDrawing = false;
                    showMeasurements = false;
                    drawType = selectedDrawingIcon.name;    

                    borVisibleChange(selectedDrawingIcon.id);

                    switch (drawType)
                    {

                        case DrawTool.POLYLINE:
                        {
                            addingPlot=false;                        
                            drawingPolygon = false;
                            drawingLine = true;
                            showMeasurements = true;

                            outlineColorId.visible=false;
                            outlineColor.visible=false;

                            drawStatus = drawLineLabel;

                            this.drawtool.deactivate();    
                            setMapAction(drawType, drawStatus, lineSymbol, drawEnd);
                            break;
                        }
                        case DrawTool.FREEHAND_POLYLINE:
                        {
                            addingPlot=drawingPolygon =false;                            
                            drawingLine=showMeasurements = true;

                            outlineColorId.visible=false;
                            outlineColor.visible=false;                    

                            drawStatus = drawFreehandLineLabel;

                            this.drawtool.deactivate();    
                            setMapAction(drawType, drawStatus, lineSymbol, drawEnd);
                            break;
                        }                            
                        case DrawTool.POLYGON:
                        {
                            addingPlot=    drawingLine = false;
                            drawingPolygon = showMeasurements = true;        

                            outlineColorId.visible=true;
                            outlineColor.visible=true;

                            drawStatus = drawPolygonLabel;

                            this.drawtool.deactivate();    
                            setMapAction(drawType, drawStatus, fillSymbol, drawEnd);                            
                            break;
                        }
                        case DrawTool.EXTENT:
                        {
                            addingPlot=    drawingLine = false;
                            drawingPolygon = showMeasurements = true;        

                            outlineColorId.visible=true;
                            outlineColor.visible=true;

                            drawStatus = drawExtentLabel;

                            this.drawtool.deactivate();    
                            setMapAction(drawType, drawStatus, fillSymbol, drawEnd);                            
                            break;
                        }
                        case DrawTool.CIRCLE:
                        {
                            addingPlot=    drawingLine = false;
                            drawingPolygon = showMeasurements = true;        

                            outlineColorId.visible=true;
                            outlineColor.visible=true;

                            drawStatus = drawCircleLabel;

                            this.drawtool.deactivate();    
                            setMapAction(drawType, drawStatus, fillSymbol, drawEnd);                            
                            break;
                        }
                        case DrawTool.FREEHAND_POLYGON:
                        {
                            addingPlot= drawingLine = false;
                            drawingPolygon =showMeasurements = true;

                            outlineColorId.visible=true;
                            outlineColor.visible=true;

                            drawStatus = drawFreehandPolygonLabel;

                            this.drawtool.deactivate();    
                            setMapAction(drawType, drawStatus, fillSymbol, drawEnd);
                            break;
                        }    
                        case DrawTool.MAPPOINT:
                        {    
                            this.addingPlot=drawingPolygon =drawingLine = showMeasurements = false;                        
                            this.addingText=true;
                            drawStatus = drawMapPointLabel;            

                            outlineColorId.visible=true;
                            outlineColor.visible=true;

                            this.drawtool.deactivate();                            
                            setMapAction(drawType,drawStatus,null,drawEnd);                        
                            break;
                        }
                        default:
                        {
                            //响应态势标会
                            drawingPolygon =drawingLine = showMeasurements = false;                        
                            this.addingPlot=true;    

                            outlineColorId.visible=true;
                            outlineColor.visible=true;

                            this.setMapAction(null,null,null,null);
                            var outline:SimpleLineSymbol=new SimpleLineSymbol("solid", this.outlineColor.selectedColor, this.customAlpha.value, 1);                
                            drawtool.fillSymbol=new SimpleFillSymbol("solid", this.fillColor.selectedColor, customAlpha.value, outline);        

                            this.drawtool.activate(drawType);    


                        }


                    }

            }

2.绘制完事后的收尾事件,获取geometry等音信,分别剖断是属于哪一类档期的顺序(点、线、面等等),然后转变graphic,增添在地图上出示出来

            private function drawEnd(event:DrawEvent):void
            {

                finishDrawing = true;
                this.drawtool.deactivate();
                this.setMapAction(null,null,null,null);

                selectedDrawingIcon = null;
                clearSelectionFilter();
                event.target.deactivate();
                var outSR:SpatialReference = new SpatialReference(102113);
                var geom:Geometry = event.graphic.geometry;

                lastDrawGraphic = new Graphic(geom);            

                if(addingPlot==true)
                {

                    var outline:SimpleLineSymbol=new SimpleLineSymbol("solid", this.outlineColor.selectedColor, this.customAlpha.value, 1);                
                    lastDrawGraphic.symbol=new SimpleFillSymbol("solid", this.fillColor.selectedColor, customAlpha.value, outline);        
                    this.drawtool.deactivate();

                }                
                else
                {                
                    switch (geom.type)
                    {
                        /*   case Geometry.MAPPOINT:
                        {
                            //文本标会就是对点的symbol进行了修改
                            if (txtLabel.text == "")
                                return;
                            var text:String=txtLabel.text;
                            var color:uint=cpText.selectedColor;
                            var font:String=textFont.selectedItem.font;
                            var size:Number=numTextSize.value;
                            var textFormat:TextFormat=new TextFormat(font, size, color, bold.selected, italic.selected, underline.selected);                            
                            var textSymbol:TextSymbol=new TextSymbol(text);
                            textSymbol.textFormat=textFormat;                             
                            lastDrawGraphic.symbol=textSymbol;     
                            break;

                        }   */
                        case Geometry.POLYLINE:
                        {
                            lastDrawGraphic.symbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, fillColor.selectedColor, customAlpha.value, 6);
                            if (chkMeasurements.selected)
                            {
                                var param:ProjectParameters=new ProjectParameters();
                                param.geometries=[geom];
                                param.outSpatialReference=outSR;
                                geometryService.project(param);
                                var polyline:Polyline = geom as Polyline;
                                measurePt = polyline.extent.center;
                            }
                            break;
                        }
                        case Geometry.POLYGON:
                        {

                                lastDrawGraphic.symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, fillColor.selectedColor, customAlpha.value, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, outlineColor.selectedColor, 1, 2));
                                if (chkMeasurements.selected)
                                {
                                    var param:ProjectParameters=new ProjectParameters();
                                    param.geometries=[geom];
                                    param.outSpatialReference=outSR;
                                    geometryService.project(param);
                                    var polygon:Polygon = geom as Polygon;
                                    measurePt = polygon.extent.center;
                                }
                                break;


                        }
                        case Geometry.EXTENT:
                        {
                            lastDrawGraphic.symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, fillColor.selectedColor, customAlpha.value, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, outlineColor.selectedColor, 1, 2));
                            if (chkMeasurements.selected)
                            {
                                var param:ProjectParameters=new ProjectParameters();
                                param.geometries=[geom];
                                param.outSpatialReference=outSR;
                                geometryService.project(param);
                                var extent:Extent = geom as Extent;
                                measurePt = extent.center;
                            }
                            break;
                        }
                    }
                }

                //添加删除要素监听事件
                lastDrawGraphic.addEventListener(MouseEvent.CLICK, onGraphicClick);

                graphicsLayer.add(lastDrawGraphic);                 
                onePlanGraphics.addItem(lastDrawGraphic);
                savePlanBtn.enabled=true;            

            }    

三.投影结果函数,总结周长和面积等新闻

            //使用GeometryService计算距离和面积等响应
            private function projectCompleteHandler(event:GeometryServiceEvent):void
            {
                var geom:Geometry = (event.result as Array)[0];
                var lengthsParameters:LengthsParameters = new LengthsParameters();
                var areasAndLengthsParameters:AreasAndLengthsParameters = new AreasAndLengthsParameters();
                switch (geom.type)
                {
                    case Geometry.POLYLINE:
                    {
                        var pLine:Polyline = Polyline(geom);
                        lengthsParameters.geodesic = true;
                        lengthsParameters.polylines = [ pLine ];
                        geometryService.lengths(lengthsParameters);
                        break;
                    }
                    case Geometry.POLYGON:
                    {
                        var pGon:Polygon = Polygon(geom);
                        areasAndLengthsParameters.polygons = [ pGon ];
                        geometryService.areasAndLengths(areasAndLengthsParameters);
                        break;
                    }
                    case Geometry.EXTENT:
                    {
                        var extent:Extent = Extent(geom);

                        // convert it to a polygon for measurment
                        const arrPoints:Array = [
                            new MapPoint(extent.xmin, extent.ymin),
                            new MapPoint(extent.xmin, extent.ymax),
                            new MapPoint(extent.xmax, extent.ymax),
                            new MapPoint(extent.xmax, extent.ymin),
                            new MapPoint(extent.xmin, extent.ymin)
                        ];

                        var polygon:Polygon = new Polygon();
                        polygon.addRing(arrPoints);
                        polygon.spatialReference = extent.spatialReference;

                        areasAndLengthsParameters.polygons = [ polygon ];
                        geometryService.areasAndLengths(areasAndLengthsParameters);
                        break;
                    }
                }
            }

            private function arealengthsCompleteHandler(event:GeometryServiceEvent):void
            {
                var area:Number = event.result.areas[0]; //event.arealengths.areas[0];
                var length:Number = event.result.lengths[0]; // or (event.result as Array)[0]; //event.arealengths.lengths[0];

                var label:String = "面积:" + numFormatter.format(area/1000000) + "平方千米";
                label += "\n" + "周长:" + numFormatter.format(length/1000) + "千米";
                addDrawLabel(label, lastDrawGraphic);
            }

            private function lengthsCompleteHandler(event:GeometryServiceEvent):void
            {
                var length:Number = (event.result as Array)[0];

                var label:String = "距离:" + numFormatter.format(length/1000) + "千米";
                addDrawLabel(label, lastDrawGraphic);
            }

备注:

GIS技术沟通QQ群:4325120玖叁

WebGIS一遍开采培养和演习入门群: 23833940八

相关文章

Leave a Comment.