Jerome_lau

GIS is changing the World!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

祥讲ARCGIS SERVER中绘制多边形工具

Posted on 2009-02-22 11:00  jerome  阅读(1015)  评论(0)    收藏  举报

本文详细的注释多边形绘制工具的实现代码,便于初学者比较好的理解,由于本人水平有限,注释中难免有错,还望有高人指点一二。

public void ServerAction(ToolEventArgs args)
    {
        ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapctrl;
        mapctrl = (ESRI.ArcGIS.ADF.Web.UI.WebControls.Map)args.Control;
        //类型转换 把ToolEventArgs类(常规的工具事件类)中的Control属性信息中的变量,转换为ESRI.ArcGIS.ADF.Web.UI.WebControls.Map类,并实例化为对象
        PolygonEventArgs peag = (PolygonEventArgs)args;//Event arguments for a polygon ClientToolAction 显示转换为PolygonEventArgs类
        System.Drawing.Point[] screen_points = peag.Vectors;//用PolygonEventArgs的Vectors属性保存Point数组中的点,记录最开始画线的点坐标

        ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality ags_mf = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality)mapctrl.GetFunctionality(0);//通过GetFunctionality()方法初始化ADF中的数据源
        //ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal ags_mr = (ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal)ags_mf.Resource;
        //ESRI.ArcGIS.Server.IServerContext sc = ags_mr.ServerContextInfo.ServerContext;
        ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapDescription;
        mapDescription = ags_mf.MapDescription;//获取地图资源的描述信息并实例化对象
          
        RgbColor rgb = new RgbColor();//创建新的颜色类的对象实例
        rgb.Red = 0;
        rgb.Green = 255;
        rgb.Blue = 0;
        rgb.AlphaValue = 255;//给该对象的属性赋值

        PointN[] pnts1 = new PointN[screen_points.Length];//把获取的屏幕坐标点的值赋给一个点对象数组pnts1

        for (int i = 0; i < screen_points.Length; i++)
        {
            PointN pnt = new PointN();//新建一个点对象
            ESRI.ArcGIS.ADF.Web.Geometry.Point mappnt = ESRI.ArcGIS.ADF.Web.Geometry.Point.ToMapPoint(screen_points[i], mapctrl.Extent, (int)mapctrl.Width.Value, (int)mapctrl.Height.Value);//创建一个基于 ESRI.ArcGIS.ADF.Web.Geometry.Point类的点对象(用该类的ToMapPoint方法Converts a System.Drawing.Point in screen coordinates to a Point in Map coordinates即坐标的转换)
            pnt.X = mappnt.X;
            pnt.Y = mappnt.Y;//把转换好的坐标赋给新的ADF点对象
            pnts1[i] = pnt;
        }

        Ring[] rings1 = new Ring[1];//环对象是一种封闭的路径对戏那个,它的起始点和终止点坐标值是一样的,这种对象具有内部和外部属性。是产生多边形的元素,是有SEGMENT对象组成的
        Ring ring1 = new Ring();
        ring1.PointArray = pnts1;//把pnts1数组赋给RING1对象数组(用PointArray属性)
        PolygonN polygon = new PolygonN();//对变形对象是RING对象的集合
        rings1[0] = ring1;
        polygon.RingArray = rings1;//把环的数组集合赋给polygon对象的RingArray属性 ,这样可以组成多边形
        polygon.Extent = new EnvelopeN();
        polygon.HasID = false;
        polygon.HasM = false;
        polygon.HasZ = false;
        polygon.SpatialReference = mapDescription.SpatialReference;//提供对变形的各种属性

        SimpleFillSymbol sfs = new SimpleFillSymbol();
        sfs.Style = ESRI.ArcGIS.ADF.ArcGISServer.esriSimpleFillStyle.esriSFSSolid;
        sfs.Color = rgb;   //用于展示多边形相关风格,颜色符号信息

        PolygonElement pe = new PolygonElement();//创建PolygonElement对象,一种图形元素用于展示多边形
        pe.Symbol = sfs;
        pe.Polygon = polygon;

        if (mapDescription.CustomGraphics != null)
        {
            GraphicElement[] oldges = mapDescription.CustomGraphics;//A type that displays a graphic object
            int cnt = oldges.Length;
            GraphicElement[] newges = new GraphicElement[cnt + 1];
            oldges.CopyTo(newges, 0);//把原始的olges数组复制到newges数组中
            newges[cnt] = pe;//把server中的PolygonElement对象实例赋给系统中图形展示对象数组
            mapDescription.CustomGraphics = newges;//加载自定义的图形对象
        }
        else
        {
            GraphicElement[] ges = new GraphicElement[1];
            ges[0] = pe;
            mapDescription.CustomGraphics = ges;
        }

        mapctrl.Refresh();//刷新控件

    }