supermap iobect .net 7.1.2 图例的拆分


  LayoutSelection objLytSelect = m_MapLayoutControl.MapLayout.Selection;//.Selection;
            //LayoutSelection  objLytSelect = m_MapLayoutControl.MapLayout.HitTest(;
            int num =objLytSelect.Count;
            if (objLytSelect.Count == 1)
            {
                int getID = objLytSelect[0];//获取选择集的id
                LayoutElements layElemetn = m_MapLayoutControl.MapLayout.Elements; //获取布局所有元素
                layElemetn.SeekID(getID);//查找选择的id对应的对象
                Geometry objGeometry = layElemetn.GetGeometry(); //对象的基类。该类是一个抽象类。提供一些基本的几何类型的属性与方法
                if (objGeometry.Type == GeometryType.GeoLegend) //判断选择是否是图例对象
                {
                    GeoLegend objGeoLegend = objGeometry as GeoLegend;
                    GeoCompound objGeoCompound = objGeoLegend.InnerGeometry;//InnerGeometry 获取图例包含的复合几何对象(GeoCompound)。 
                    Geometry [] sq= objGeoCompound.Divide(false);//分解复合几何对象,复合几何对象的结构类似于树状结构, 如果分解时只分解顶层对象, 则返回的几何对象仍然可能存在复合几何对象,否则将不含有复合几何对象。
                    m_MapLayoutControl.MapLayout.Elements.Delete(new int[] { getID }); //删除选择的图例对象 为以后单独添加去重
                    for (int i = 0; i < sq.Length; i++)
                    {
                        m_MapLayoutControl.MapLayout.Elements.AddNew(sq[i]); //把拆分的对象重新添加到布局中
                    }
                    m_MapLayoutControl.MapLayout.Refresh(); //刷新
                    objGeoLegend.Dispose();
                    objGeoCompound.Dispose();
                }
                else
                {
                    MessageBox.Show("请选择图例对象!", "提示");
                    objLytSelect.Dispose();// = null;
                    return;
                }

            }
            else
            {
                MessageBox.Show("请单独选择图例对象!", "提示"); 
                objLytSelect.Dispose();
                return;
            }
图例拆分
  try
            {
                LayoutElements layoutElements = m_MapLayoutControl.MapLayout.Elements;
                if (GetMapID() < 0) return;
                layoutElements.SeekID(GetMapID()); //根据图例中地图的id进行查找获取地图对象
                GeoMap geoMap = (GeoMap)layoutElements.GetGeometry();
                string geoMapName = geoMap.MapName;

                GeoLegend geoLegend = new GeoLegend(geoMapName, m_workspace);  
              
                geoLegend.Height = 175;
                geoLegend.Width = 950;
                geoLegend.Center = new Point2D(575, 655);

                GeoStyle geoLegendStyle = new GeoStyle();
                geoLegendStyle.FillForeColor = Color.FromArgb(255, 235, 175);
                geoLegendStyle.FillOpaqueRate = 30;
                geoLegendStyle.LineWidth = 0.5;
                geoLegendStyle.LineColor = Color.FromArgb(65, 65, 65);
                geoLegend.BackGroundStyle = geoLegendStyle;
                geoLegend.ColumnCount = 3;

                //设置图例项和图例子项的说明文本的风格
                TextStyle geoLegendtextStyle = new TextStyle();
                geoLegendtextStyle.BackColor = Color.Yellow;
                geoLegendtextStyle.ForeColor = Color.Blue;
                geoLegendtextStyle.FontName = "宋体";
                geoLegendtextStyle.FontHeight = 20.0;
                geoLegendtextStyle.FontWidth = 12.0;
                geoLegendtextStyle.IsSizeFixed = false;
                geoLegend.ItemTextStyle = geoLegendtextStyle;
                geoLegend.SubItemTextStyle = geoLegendtextStyle;

                //设置图例标题风格
                TextStyle titleTextStyle = new TextStyle();
                titleTextStyle.BackColor = Color.Yellow;
                titleTextStyle.ForeColor = Color.Blue;
                titleTextStyle.FontName = "宋体";
                titleTextStyle.FontHeight = 40.0;
                titleTextStyle.FontWidth = 25.0;
                titleTextStyle.Italic = true;
                titleTextStyle.Bold = true;
                titleTextStyle.IsSizeFixed = false;
                titleTextStyle.Weight = 500;
                geoLegend.Title = "图例";
                geoLegend.TitleStyle = titleTextStyle;

              
                //将图例添加到布局图层,而非屏幕图层。
                geoLegend.Load(false);
                m_MapLayoutControl.MapLayout.Elements.AddNew(geoLegend);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
添加图例