風☆小贤‘s 烂笔头

好记性,不如烂笔头……

ArcGISPlotSilverlightAPI的标绘功能

     ArcGISPlotSilverlightAPI.dll 提供了丰富的标绘图标,貌似不是esri的,网上也没有学习资料。

无奈之下我通过反编译学习,差不多掌握了ArcGISPlotSilverlightAPI的运用,下面就介绍下如何

使用。

演示网址:

http://tm.arcgisonline.cn:8038/App1/WaterPlot/SilverlightPlotMapTestPage.html

自定义Plot类:

    // 地图的标绘功能
    public class MapPlot
    {
        #region 字段
        //复杂标绘工具
        private PlotDraw _plotDraw;
        //简单标绘工具
        private Draw _draw;
        //地图对象
        private Map _mapObject;
        //线标注
        private LineSymbol _syLineSymbol;
        //面标注
        private FillSymbol _syFillSymbol;
        //图层
        private GraphicsLayer _gLayer;
        //标注枚举
        private MapPlotMode _plotMode;
        #endregion

        #region 构造函数
        public MapPlot(Map mapObject)
        {
            this._mapObject = mapObject;
            _plotDraw = new PlotDraw(this._mapObject);
            Layer _layer = this._mapObject.Layers.SingleOrDefault(a => string.IsNullOrEmpty(a.ID));
            if (_layer != null) _layer.ID = "_plotDraw";
            #region 保存标绘结果
            this._plotDraw.DrawEnd += (polygon, polyline) =>
               {
                   try
                   {
                       Graphic graphic;
                       //如果是面
                       if (polygon != null)
                       {
                           if (this._plotDraw.DrawMode == PlotDrawMode.CompassAndTarget)
                           {
                               graphic = new Graphic();
                               graphic.Symbol = _syFillSymbol;
                               graphic.Geometry = new Polygon();
                               for (int i = 0; i < (polygon.Rings.Count - 1); i++)
                               {
                                   (graphic.Geometry as Polygon).Rings.Add(polygon.Rings[i]);
                               }
                               this._gLayer.Graphics.Add(graphic);
                               if (polygon.Rings.Count > 4)
                               {
                                   Graphic item = new Graphic();
                                   item.Geometry = new Polygon();
                                   (item.Geometry as Polygon).Rings.Add(polygon.Rings[4]);
                               }
                           }
                           else
                           {
                               graphic = new Graphic();
                               graphic.Symbol = _syFillSymbol;
                               graphic.Geometry = polygon;
                               this._gLayer.Graphics.Add(graphic);
                           }
                       }
                       //如果是线
                       if (polyline != null)
                       {
                           graphic = new Graphic();
                           graphic.Geometry = polyline;
                           graphic.Symbol = _syLineSymbol;
                           this._gLayer.Graphics.Add(graphic);
                       }
                   }
                   catch { }
               };
            #endregion
            _draw = new Draw(this._mapObject);
            #region 保存标绘结果
            _draw.DrawComplete += (o, a) =>
               {
                   try
                   {
                       Graphic graphic = new Graphic();
                       graphic.Geometry = a.Geometry;
                       if (a.Geometry is ESRI.ArcGIS.Client.Geometry.Polygon)
                           graphic.Symbol = _syFillSymbol;
                       else
                           graphic.Symbol = _syLineSymbol;
                       _gLayer.Graphics.Add(graphic);
                   }
                   catch { }
               };
            #endregion
        }

        public MapPlot(Map mapObject, string htmlColor, double size)
            : this(mapObject)
        {
            //初始化标注
            InitSymbol(ColorManager.HtmlToColor(htmlColor), size);
        }
        #endregion

        #region 公共方法
        /// <summary>
        /// 设置标注
        /// </summary>
        public void InitSymbol(Color _color,double size)
        {            
            _syLineSymbol = new SimpleLineSymbol();
            _syLineSymbol.Color = new SolidColorBrush(_color);
            _syLineSymbol.Width = size;
            _syFillSymbol = new SimpleFillSymbol();
            LinearGradientBrush liner = new LinearGradientBrush();
            liner.Opacity = 0.8;
            liner.GradientStops.Add(new GradientStop() { Color = Colors.White, Offset = 0 });
            liner.GradientStops.Add(new GradientStop() { Color = _color, Offset = 1 });
            _syFillSymbol.Fill = liner;
            _syFillSymbol.BorderBrush = new SolidColorBrush(Colors.Black);
            _syFillSymbol.BorderThickness = 1;

            _draw.LineSymbol = _syLineSymbol;
            _draw.FillSymbol = _syFillSymbol;
        }
        /// <summary>
        /// 开始标绘
        /// </summary>
        public void StartPlot(GraphicsLayer gLayer, MapPlotMode mapPlotMode)
        {
            try
            {
                this._plotMode = mapPlotMode;
                //设置图层
                this._gLayer = gLayer;
                //枚举值
                int value = (int)mapPlotMode;
                //大于23使用简单标绘
                if (value > 23 && value <28)
                {
                    _plotDraw.setPlotDrawMode(PlotDrawMode.None);
                    _draw.IsEnabled = true;
                    _draw.LineSymbol = _syLineSymbol;
                    _draw.FillSymbol = _syFillSymbol;
                    _draw.DrawMode = (DrawMode)System.Enum.Parse(typeof(DrawMode), mapPlotMode.ToString(), false);
                }
                else if (value <= 23)  //复杂标绘
                {
                    _draw.IsEnabled = false;
                    _plotDraw.setPlotDrawMode((PlotDrawMode)System.Enum.Parse(typeof(PlotDrawMode), mapPlotMode.ToString(), false));
                }
                else  //文本标注
                {
                    _draw.IsEnabled = false;
                    _plotDraw.setPlotDrawMode(PlotDrawMode.None);
                    _mapObject.MouseClick += TextBoxPlot;
                }
            }
            catch { }
        }

        /// <summary>
        /// 文本标注
        /// </summary>
        private void TextBoxPlot(object sender, Map.MouseEventArgs e)
        {
            try
            {
                Graphic _g = new Graphic();
                if(this._plotMode == MapPlotMode.LTextBox)
                    _g.Symbol = CustomSymbols.GetLeftTxtMarker();
                else if(this._plotMode == MapPlotMode.RTextBox)
                    _g.Symbol = CustomSymbols.GetRightTxtMarker();
                _g.Geometry = e.MapPoint;
                _gLayer.Graphics.Add(_g);
            }
            catch { }
        }

        /// <summary>
        /// 结束标绘
        /// </summary>
        public void StopPlot()
        {
            _plotDraw.setPlotDrawMode(PlotDrawMode.None);
            _mapObject.MouseClick -= TextBoxPlot;
            _draw.IsEnabled = false;
        }

        public void DeletePlot(GraphicsLayer gLayer)
        {

        }
        #endregion
    }
懒得整理,直接贴代码了……

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/li_fighting/article/details/9815975
文章标签: C# Silverlight 地图
想对作者说点什么? 我来说一句

ArcGIS for JavaScript

-

学院

1970年01月01日 08:00

Arcgis标绘例子

2015年04月26日 15.97MB 下载

二维地图标绘

2017年12月15日 82B 下载

没有更多推荐了,返回首页

不良信息举报

ArcGISPlotSilverlightAPI的标绘功能

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭