• AE中的线符号渲染


    窗口设计:

     

    所用到的控件:axSymbolControl、groupBox、MarkerSymbol(Button)、Label、Button、NumericUpDown

    符号窗口代码(记得绑定【确定】【取消】窗口加载等事件):

    /// <summary>
    
            /// 地图符号对象
    
            /// </summary>
    
            private IMapControlDefault m_mapControl;
    
            private ILayer m_Layer;
    
            private ILegendClass m_LegendClass;
    
            private ISymbologyStyleClass m_SymbologyStyleClass;
    
     
    
            /// <summary>
    
            /// 符号属性集合
    
            /// </summary>
    
            private Dictionary<int, double> widths;
    
            private Dictionary<int, Color> colors;
    
     
    
            public LineSymbol(IMapControlDefault m_mapControl, ILayer m_Layer, ILegendClass m_LegendClass)
    
            {
    
                InitializeComponent();
    
                // 初始化地图符号对象
    
                this.m_mapControl = m_mapControl;
    
                this.m_Layer = m_Layer;
    
                this.m_LegendClass = m_LegendClass;
    
     
    
                // 初始化符号属性集合
    
                this.widths = new Dictionary<int, double>();
    
                this.colors = new Dictionary<int, Color>();
    
     
    
                // 初始化符号控件
    
                Init();
    
            }
    
            private void Init()
    
            {
    
                axSymbologyControl1.LoadStyleFile(AppDomain.CurrentDomain.BaseDirectory + " ESRI.ServerStyle");
    
                axSymbologyControl1.StyleClass = esriSymbologyStyleClass.esriStyleClassLineSymbols;
    
                m_SymbologyStyleClass = axSymbologyControl1.GetStyleClass(axSymbologyControl1.StyleClass);
    
     
    
                // 添加当前符号
    
                IStyleGalleryItem pStyleGalleryItem = new ServerStyleGalleryItem();
    
                pStyleGalleryItem.Name = "当前符号";
    
                pStyleGalleryItem.Item = m_LegendClass.Symbol;
    
                m_SymbologyStyleClass.AddItem(pStyleGalleryItem, 0);
    
     
    
                // 符号属性集合
    
                for (int i = 0; i < m_SymbologyStyleClass.get_ItemCount(); i++)
    
                {
    
                    IStyleGalleryItem item = m_SymbologyStyleClass.GetItem(i);
    
                    ILineSymbol pLineSymbol = item.Item as ILineSymbol;
    
                    if (!widths.ContainsKey(item.ID))
    
                    {
    
                        widths.Add(item.ID, pLineSymbol.Width);
    
                    }
    
                    if (!colors.ContainsKey(item.ID))
    
                    {
    
                        colors.Add(item.ID, ConvertToColor(pLineSymbol.Color));
    
                    }
    
                }
    
                m_SymbologyStyleClass.SelectItem(0);
    
            }
    
     
    
            /// <summary>
    
            /// 双击选中符号
    
            /// </summary>
    
            /// <param name="sender"></param>
    
            /// <param name="e"></param>
    
            private void axSymbologyControl1_OnDoubleClick(object sender, ISymbologyControlEvents_OnDoubleClickEvent e)
    
            {
    
                btnOK.PerformClick();
    
            }
    
     
    
            /// <summary>
    
            /// 切换符号
    
            /// </summary>
    
            /// <param name="sender"></param>
    
            /// <param name="e"></param>
    
            private void axSymbologyControl1_OnItemSelected(object sender, ISymbologyControlEvents_OnItemSelectedEvent e)
    
            {
    
                IStyleGalleryItem pStyleGalleryItem = e.styleGalleryItem as IStyleGalleryItem;
    
                numLineWidth.Value = (decimal)widths[pStyleGalleryItem.ID];
    
                LineColor.BackColor = colors[pStyleGalleryItem.ID];
    
     
    
                // 预览
    
                ILineSymbol pLineSymbol = pStyleGalleryItem.Item as ILineSymbol;
    
                pLineSymbol.Width = widths[pStyleGalleryItem.ID];
    
                pLineSymbol.Color = ConvertToRgbColor(colors[pStyleGalleryItem.ID]);
    
                PreviewSymbol(pStyleGalleryItem);
    
            }
    
     
    
            /// <summary>
    
            /// 切换颜色
    
            /// </summary>
    
            /// <param name="sender"></param>
    
            /// <param name="e"></param>
    
            private void btnColor_Click(object sender, EventArgs e)
    
            {
    
                ColorDialog colorDialog = new ColorDialog();
    
                if (colorDialog.ShowDialog() == DialogResult.OK)
    
                {
    
                    LineColor.BackColor = colorDialog.Color;
    
     
    
                    // 预览
    
                    IStyleGalleryItem pStyleGalleryItem = m_SymbologyStyleClass.GetSelectedItem();
    
                    ILineSymbol pLineSymbol = pStyleGalleryItem.Item as ILineSymbol;
    
                    pLineSymbol.Width = (double)numLineWidth.Value;
    
                    pLineSymbol.Color = ConvertToRgbColor(LineColor.BackColor);
    
                    PreviewSymbol(pStyleGalleryItem);
    
                }
    
            }
    
     
    
            /// <summary>
    
            /// 切换宽度
    
            /// </summary>
    
            /// <param name="sender"></param>
    
            /// <param name="e"></param>
    
            private void numWidth_ValueChanged(object sender, EventArgs e)
    
            {
    
                // 预览
    
                IStyleGalleryItem pStyleGalleryItem = m_SymbologyStyleClass.GetSelectedItem();
    
                ILineSymbol pLineSymbol = pStyleGalleryItem.Item as ILineSymbol;
    
                pLineSymbol.Width = (double)numLineWidth.Value;
    
                pLineSymbol.Color = ConvertToRgbColor(LineColor.BackColor);
    
                PreviewSymbol(pStyleGalleryItem);
    
            }
    
     
    
            /// <summary>
    
            /// 确定
    
            /// </summary>
    
            /// <param name="sender"></param>
    
            /// <param name="e"></param>
    
            private void btnOK_Click(object sender, EventArgs e)
    
            {
    
                IGeoFeatureLayer pGeoFeatureLayer = m_Layer as IGeoFeatureLayer;
    
                IFeatureRenderer pFeatureRenderer = pGeoFeatureLayer.Renderer;
    
                ISimpleRenderer pSimpleRenderer = pFeatureRenderer as ISimpleRenderer;
    
                pSimpleRenderer.Symbol = m_SymbologyStyleClass.GetSelectedItem().Item as ISymbol;
    
                m_mapControl.Refresh();
    
                this.Close();
    
            }
    
     
    
            /// <summary>
    
            /// 取消
    
            /// </summary>
    
            /// <param name="sender"></param>
    
            /// <param name="e"></param>
    
            private void btnCancel_Click(object sender, EventArgs e)
    
            {
    
                this.Close();
    
            }
    
     
    
            /// <summary>
    
            /// Color转换为IColor
    
            /// </summary>
    
            /// <param name="color"></param>
    
            /// <returns></returns>
    
            private IColor ConvertToRgbColor(Color color)
    
            {
    
                IColor pColor = new RgbColor();
    
                pColor.RGB = color.R + color.G * 256 + color.B * 65536;
    
                return pColor;
    
            }
    
     
    
            /// <summary>
    
            /// IColor转换为Color
    
            /// </summary>
    
            /// <param name="pColor"></param>
    
            /// <returns></returns>
    
            private Color ConvertToColor(IColor pColor)
    
            {
    
                return ColorTranslator.FromOle(pColor.RGB);
    
            }
    
     
    
            /// <summary>
    
            /// 预览符号
    
            /// </summary>
    
            private void PreviewSymbol(IStyleGalleryItem pStyleGalleryItem)
    
            {
    
                //此处MarkerSymbol为预览符号控件
    
                IPictureDisp pPictureDisp = m_SymbologyStyleClass.PreviewItem(pStyleGalleryItem, MarkerSymbol.Width, MarkerSymbol.Height);
    
                Image priviewImage = Image.FromHbitmap(new IntPtr(pPictureDisp.Handle));
    
                MarkerSymbol.Image = priviewImage;
    
            }

    系统主窗口代码:(记得绑定TOCControl事件,这里为了测试方便,添加了右键等功能代码)

            private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
    
            {
    
                ESRI.ArcGIS.Controls.esriTOCControlItem Item = ESRI.ArcGIS.Controls.esriTOCControlItem.esriTOCControlItemNone;
    
                IBasicMap pBasicMap = null;
    
                ILayer pLayer = null;
    
                object other = null;
    
                object index = null;
    
                axTOCControl1.HitTest(e.x, e.y, ref Item, ref pBasicMap, ref pLayer, ref other, ref index);          //实现赋值
    
                //图层左键
    
                if (e.button == 1)
    
                {
    
                    if (Item == esriTOCControlItem.esriTOCControlItemLegendClass)
    
                    {
    
                        if (pLayer is IFeatureLayer)
    
                        {
    
                            IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
    
                            if (pFeatureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline)
    
                            {
    
                                ILegendGroup pLegendGroup = other as ILegendGroup;
    
                                ILegendClass pLegendClass = pLegendGroup.get_Class((int)index);
    
                                LineSymbol frm = new LineSymbol(axMapControl1.Object as IMapControlDefault, pLayer, pLegendClass);
    
                                frm.ShowDialog();
    
                            }
    
                            
    
                        }
    
                    }
    
                }
    
            }

    运行图:

     

    说明:包括后文中的点符号、面符号(填充符号)都需要此文件:ESRI.ServerStyle。只要装过ArcGIS就会有此文件,可电脑搜索,也可到此链接下载

    https://download.csdn.net/download/say_book/85001155

    也是想出一个系列吧,在自己刚开始学习AE开发的时候苦于查找书籍代码不可用或者各博客描述不够详尽到我一个小白可以读懂,然后踩了各种各样的坑(虽然踩过的坑忘记了很多),其间很多代码的产生都是始于Copy,然后结合自己的查询资料和思考所得,还是希望自己能帮助到各位正在学习或使用的各位同仁吧。

     

    扫码关注公众号

  • 相关阅读:
    ListView Item 里多种点击事件的用法
    dialog 设置maxHeight 最大高度
    php的json_encode不兼容JSON_UNESCAPED_UNICODE的解决方案
    java面试一定会遇到的56个面试题
    使用LinearLayout实现ListView,解决ListView和ScrollView滚动冲突
    检测是否是小米手机
    Android 自定义ViewGroup 实战篇 -> 实现FlowLayout
    clone分支,修改文件本地commit后, push回原分支失败,处理方法
    SQL语句往Oracle数据库中插入日期型数据(to_date的用法)
    C# TimeSpan 计算时间差(时间间隔)
  • 原文地址:https://www.cnblogs.com/pygisxss/p/16046744.html
Copyright © 2020-2023  润新知