博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
天津政府应急系统之GIS一张图(arcgis api for flex)讲解(十)态势标绘模块
阅读量:6294 次
发布时间:2019-06-22

本文共 15793 字,大约阅读时间需要 52 分钟。

config.xml文件的配置如下:

源代码目录如下:

界面效果:

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

NewPlotWidget.xml:配置计算周长和面积的单位信息等等

http://localhost:6080/arcgis/rest/services/Utilities/Geometry/GeometryServer
4326
千米
平方公里
显示测量结果
周长:
面积:

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;                                    }

3.投影结果函数,计算周长和面积等信息

//使用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群:432512093

WebGIS二次开发培训入门群: 238339408

转载地址:http://rtpta.baihongyu.com/

你可能感兴趣的文章
《Node.js入门经典》一2.3 安装模块
查看>>
《Java 开发从入门到精通》—— 2.5 技术解惑
查看>>
Linux 性能诊断 perf使用指南
查看>>
实操分享:看看小白我如何第一次搭建阿里云windows服务器(Tomcat+Mysql)
查看>>
Sphinx 配置文件说明
查看>>
数据结构实践——顺序表应用
查看>>
python2.7 之centos7 安装 pip, Scrapy
查看>>
机智云开源框架初始化顺序
查看>>
Spark修炼之道(进阶篇)——Spark入门到精通:第五节 Spark编程模型(二)
查看>>
一线架构师实践指南:云时代下双活零切换的七大关键点
查看>>
ART世界探险(19) - 优化编译器的编译流程
查看>>
玩转Edas应用部署
查看>>
music-音符与常用记号
查看>>
sql操作命令
查看>>
zip 数据压缩
查看>>
Python爬虫学习系列教程
查看>>
【数据库优化专题】MySQL视图优化(二)
查看>>
【转载】每个程序员都应该学习使用Python或Ruby
查看>>
PHP高级编程之守护进程,实现优雅重启
查看>>
PHP字符编码转换类3
查看>>