// 添加图例
        public static void MakeLegend(AxPageLayoutControl pageLayoutControl, IEnvelope envelope)
        {
            IActiveView pActiveView = pageLayoutControl.ActiveView;

            UID pUID = new UID()
            {
                Value = "esriCarto.Legend"
            };
            IGraphicsContainer pGraphicsContainer = pageLayoutControl.PageLayout as IGraphicsContainer;
            IMapFrame          pMapFrame          = pGraphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame;
            // 根据唯一标识符,创建与之对应的MapSurroundFrame
            IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pUID, null);
            // 获取PageLayout中的图例元素
            IElement pDeleteElement = pageLayoutControl.FindElementByName("Legend");

            if (pDeleteElement != null)
            {
                pGraphicsContainer.DeleteElement(pDeleteElement); // 如果已存在图例,删除已经存在的图例
            }
            // 设置MapSurroundFrame背景
            ISymbolBackground pSymbolBackground = new SymbolBackgroundClass()
            {
                FillSymbol = new SimpleFillSymbolClass()
                {
                    Color   = AeUtilsSymbology.GetRgbColor(240, 240, 240),
                    Outline = new SimpleLineSymbolClass()
                    {
                        Color = AeUtilsSymbology.GetRgbColor(0, 0, 0)
                    }
                }
            };

            pMapSurroundFrame.Background = pSymbolBackground;
            // 添加图例
            IElement pElement = pMapSurroundFrame as IElement;

            pElement.Geometry = envelope as IGeometry;
            IMapSurround pMapSurround = pMapSurroundFrame.MapSurround;
            ILegend      pLegend      = pMapSurround as ILegend;

            pLegend.ClearItems();
            pLegend.Title = "图例";
            for (int i = 0; i < pActiveView.FocusMap.LayerCount; i++)
            {
                ILegendItem pLegendItem = new HorizontalLegendItemClass()
                {
                    Layer            = pActiveView.FocusMap.get_Layer(i),
                    ShowDescriptions = false,
                    Columns          = 1,
                    ShowHeading      = true,
                    ShowLabels       = true
                };
                pLegend.AddItem(pLegendItem);
            }
            pGraphicsContainer.AddElement(pElement, 0);
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
示例#2
0
        private void MakeLegend(IActiveView pActiveView, IPageLayout pPageLayout, IEnvelope pEnv)
        {
            UID pID = new UID();

            pID.Value = "esriCarto.Legend";
            IGraphicsContainer pGraphicsContainer = pPageLayout as IGraphicsContainer;
            IMapFrame          pMapFrame          = pGraphicsContainer.FindFrame(pActiveView.FocusMap) as IMapFrame;
            IMapSurroundFrame  pMapSurroundFrame  = pMapFrame.CreateSurroundFrame(pID, null);         //根据唯一标示符,创建与之对应MapSurroundFrame
            IElement           pDeletElement      = axPageLayoutControl1.FindElementByName("Legend"); //获取PageLayout中的图例元素

            if (pDeletElement != null)
            {
                pGraphicsContainer.DeleteElement(pDeletElement);  //如果已经存在图例,删除已经存在的图例
            }
            //设置MapSurroundFrame背景
            ISymbolBackground pSymbolBackground = new SymbolBackgroundClass();
            IFillSymbol       pFillSymbol       = new SimpleFillSymbolClass();
            ILineSymbol       pLineSymbol       = new SimpleLineSymbolClass();

            pLineSymbol.Color            = m_OperatePageLayout.GetRgbColor(0, 0, 0);
            pFillSymbol.Color            = m_OperatePageLayout.GetRgbColor(240, 240, 240);
            pFillSymbol.Outline          = pLineSymbol;
            pSymbolBackground.FillSymbol = pFillSymbol;
            pMapSurroundFrame.Background = pSymbolBackground;
            //添加图例
            IElement pElement = pMapSurroundFrame as IElement;

            pElement.Geometry = pEnv as IGeometry;
            IMapSurround pMapSurround = pMapSurroundFrame.MapSurround;
            ILegend      pLegend      = pMapSurround as ILegend;

            pLegend.ClearItems();
            pLegend.Title = "图例";
            for (int i = 0; i < pActiveView.FocusMap.LayerCount; i++)
            {
                ILegendItem pLegendItem = new HorizontalLegendItemClass();
                pLegendItem.Layer            = pActiveView.FocusMap.get_Layer(i);//获取添加图例关联图层
                pLegendItem.ShowDescriptions = false;
                pLegendItem.Columns          = 1;
                pLegendItem.ShowHeading      = true;
                pLegendItem.ShowLabels       = true;
                pLegend.AddItem(pLegendItem);//添加图例内容
            }
            pGraphicsContainer.AddElement(pElement, 0);
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
示例#3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            m_legend.Title = textBoxTitle.Text;

            m_legend.ClearItems();
            int mapCount    = m_legend_Complete.ItemCount;
            int legentCount = listBoxLegendItem.Items.Count;

            for (int i = 0; i < legentCount; i++)
            {
                for (int j = 0; j < mapCount; j++)
                {
                    if (listBoxLegendItem.Items[i].ToString() == listBoxMapItem.Items[j].ToString())
                    {
                        m_legend.AddItem(m_legend_Complete.get_Item(j));
                    }
                }
            }
            if (checkBoxIsTitleShow.Checked == false)
            {
                m_legend.Title = "";
            }
            m_legend.Refresh();
        }
示例#4
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            m_legend.Name  = this.textBoxElement.Text.Trim();
            m_legend.Title = this.textBox1.Text; //图例的标题
            ILayer      player;
            ILegendItem pLegendItem = null;

            #region //设置图例显示的项
            if (this.listBox2.Items.Count != 0)
            {
                m_legend.ClearItems();
                foreach (object item in this.listBox2.Items)   //设置需要的图例项  根据用户需要添加
                {
                    for (int j = 0; j < m_pageLayoutControl.ActiveView.FocusMap.LayerCount; j++)
                    {
                        player = m_pageLayoutControl.ActiveView.FocusMap.get_Layer(j);
                        if (player.Name == item.ToString())
                        {
                            IFeatureLayer pFLayer       = player as IFeatureLayer;
                            IFeatureClass pFeatureClass = pFLayer.FeatureClass;
                            if (pFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                            {
                                continue;
                            }
                            else
                            {
                                pLegendItem                  = new HorizontalLegendItemClass(); //图例项标签的样式
                                pLegendItem.Layer            = player;
                                pLegendItem.Columns          = 1;
                                pLegendItem.ShowDescriptions = false;
                                pLegendItem.ShowHeading      = false;
                                pLegendItem.ShowLabels       = true;
                                switch (comboBox1.SelectedItem.ToString().Trim())
                                {
                                case "所有文本符号":
                                    pLegendItem.LayerNameSymbol = pTextSymbol;   //设置字体样式
                                    pLegendItem.HeadingSymbol   = pTextSymbol;
                                    pLegendItem.LegendClassFormat.LabelSymbol = pTextSymbol;
                                    break;

                                case "所有图层名称":
                                    pLegendItem.LayerNameSymbol = pTextSymbol;
                                    break;

                                case "所有标题项":
                                    pLegendItem.HeadingSymbol = pTextSymbol;
                                    break;

                                case "所有标注项":
                                    pLegendItem.LegendClassFormat.LabelSymbol = pTextSymbol;
                                    break;

                                case "所有描述性文字":
                                    break;
                                }
                            }
                            m_legend.AddItem(pLegendItem);
                        }
                    }
                }
            }
            #endregion
            plegendFormat.DefaultPatchHeight = Convert.ToDouble(this.textBoxHeight.Text); //块的高度
            plegendFormat.DefaultPatchWidth  = Convert.ToDouble(this.textBoxWidth.Text);  //块的宽度


            #region //设置图例的底色边框
            IMapSurround pmapsurronud = m_legend as IMapSurround;
            mapSurroundFrame.MapSurround = pmapsurronud;
            m_FrameProperties            = (IFrameProperties)mapSurroundFrame;
            // m_SymbolBackground.FillSymbol.Color = ConvertColorToIColor(this.btnBackGroundColor.BackColor);
            m_FrameProperties.Background = (IBackground )m_SymbolBackground;
            // m_SymbolBorder.LineSymbol.Color = ConvertColorToIColor(this.btnBolderColor.BackColor);
            m_FrameProperties.Border = (IBorder)m_SymbolBorder;
            // m_SymbolShadow.FillSymbol.Color = ConvertColorToIColor(this.btnShadowColor.BackColor);
            m_FrameProperties.Shadow = (IShadow)m_SymbolShadow;

            #endregion



            IEnvelope pEnvelop = new EnvelopeClass();      //图例的位置
            pEnvelop.PutCoords(Convert.ToDouble(this.textBoxX.Text), Convert.ToDouble(this.textBoxY.Text),
                               Convert.ToDouble(this.textBoxX.Text) + Convert.ToDouble(this.textBoxWidth1.Text),
                               Convert.ToDouble(this.textBoxY.Text) + Convert.ToDouble(this.textBoxHeight1.Text));


            IElement m_element = mapSurroundFrame   as IElement;
            m_element.Geometry = pEnvelop;
            m_pageLayoutControl.AddElement(m_element, Type.Missing, Type.Missing, m_legend.Name, 0);
            m_pageLayoutControl.ActiveView.Refresh();
            this.Close();
        }
示例#5
0
        //更新图例
        private void UpdateLegend()
        {
            //边框、背景、阴影的间距
            if (txtBorderGap.Text != null && pSymbolBorder != null)
            {
                pSymbolBorder.Gap = double.Parse(this.txtBorderGap.Text);
            }
            if (txtBackgroundGap.Text != null && pSymbolBackground != null)
            {
                pSymbolBackground.Gap = double.Parse(this.txtBackgroundGap.Text);
            }
            if (txtShadowX.Text != null && pSymbolShadow != null)
            {
                pSymbolShadow.VerticalSpacing = double.Parse(this.txtShadowX.Text);
            }
            if (txtShadowY.Text != null && pSymbolShadow != null)
            {
                pSymbolShadow.HorizontalSpacing = double.Parse(this.txtShadowY.Text);
            }
            //边框、背景、阴影的角度
            if (txtBorderAngle.Text != null && pSymbolBorder != null)
            {
                pSymbolBorder.CornerRounding = short.Parse(txtBorderAngle.Text);
            }
            if (txtBackgroundAngle.Text != null && pSymbolBackground != null)
            {
                pSymbolBackground.CornerRounding = short.Parse(txtBackgroundAngle.Text);
            }
            if (txtShadowAngle.Text != null && pSymbolShadow != null)
            {
                pSymbolShadow.CornerRounding = short.Parse(txtShadowAngle.Text);
            }
            //边框、背景、阴影
            IFrameProperties pFrameProperties = pMapSurroundFrame as IFrameProperties;

            if (pSymbolBorder != null)
            {
                pFrameProperties.Border = pSymbolBorder;
            }
            if (pSymbolBackground != null)
            {
                pFrameProperties.Background = pSymbolBackground;
            }
            if (pSymbolShadow != null)
            {
                pFrameProperties.Shadow = pSymbolShadow;
            }

            ILegendFormat pLegendFormat = new LegendFormatClass();

            //标题设置  显示
            if (this.cBoxShowTitle.Checked == true)
            {
                pLegendFormat.ShowTitle = true;
            }
            else
            {
                pLegendFormat.ShowTitle = false;
            }
            //标题样式

            if (pTitleSymbol != null)
            {
                pLegendFormat.TitleSymbol = pTitleSymbol;
            }

            //图面样式以及高度和样式设计
            if (pLinePatch != null)
            {
                pLegendFormat.DefaultLinePatch = pLinePatch;
            }
            if (pAreaPatch != null)
            {
                pLegendFormat.DefaultAreaPatch = pAreaPatch;
            }
            if (txtPatchWith.Text != null)
            {
                pLegendFormat.DefaultPatchWidth = double.Parse(txtPatchWith.Text);
            }
            if (txtPatchHeight.Text != null)
            {
                pLegendFormat.DefaultPatchHeight = double.Parse(txtPatchHeight.Text);
            }

            //第四界面从上到下图例各部分之间的距离
            pLegendFormat.TitleGap           = double.Parse(txtTitleAndLegend.Text);
            pLegendFormat.VerticalItemGap    = double.Parse(txtLegendItems.Text);
            pLegendFormat.HorizontalItemGap  = double.Parse(txtColumns.Text);
            pLegendFormat.HeadingGap         = double.Parse(txtHeadings.Text);
            pLegendFormat.TextGap            = double.Parse(txtLabelsAndDescription.Text);
            pLegendFormat.VerticalPatchGap   = double.Parse(txtPatchesV.Text);
            pLegendFormat.HorizontalPatchGap = double.Parse(txtPatchAndLabels.Text);

            //样式添加到图例
            Legend.Title  = this.txtLegendTitle.Text;
            Legend.Format = pLegendFormat;
            //地图链接

            Legend.AutoVisibility = cBoxAddVisibleLayer.Checked; //只显示显示的图层
            Legend.AutoAdd        = cBoxAddNewLayer.Checked;     //自动添加显示的图层
            Legend.AutoReorder    = cBoxNewOrder.Checked;        //按照图层顺序排列图例

            //Legend.ClearItems();
            //Legend.Refresh();

            //图例列数
            double pLegendColumn = double.Parse(this.LegendColumn.Text);
            //图例中要包含的图层个数为  pSelectedidx.Count
            double pLegendItemCount = pSelectedidx.Count;
            //计算图例分裂的位置
            int    ColumnPos = (int)(pLegendItemCount / pLegendColumn);
            double remainder = (pLegendItemCount % pLegendColumn) / pLegendColumn;

            if (remainder >= 0.5)
            {
                ColumnPos = ColumnPos + 1;
            }

            for (int i = 0; i < pSelectedidx.Count; i++)
            {
                ILegendItem pLegendItem = new HorizontalLegendItemClass();
                pLegendItem.Layer = pMap.get_Layer(pSelectedidx[i]);
                int lengendinex = 0;//记录同名图层在legend中的位置
                for (int j = 0; j < Legend.ItemCount; j++)
                {
                    if (Legend.Item[j].Layer == pLegendItem.Layer)
                    {
                        lengendinex = j;
                        break;
                    }
                }
                pLegendItem.ShowDescriptions  = Legend.Item[lengendinex].ShowDescriptions;
                pLegendItem.ShowHeading       = Legend.Item[lengendinex].ShowHeading;
                pLegendItem.ShowLabels        = Legend.Item[lengendinex].ShowLabels;
                pLegendItem.ShowLayerName     = Legend.Item[lengendinex].ShowLayerName;
                pLegendItem.HeadingSymbol     = Legend.Item[lengendinex].HeadingSymbol;
                pLegendItem.LayerNameSymbol   = Legend.Item[lengendinex].LayerNameSymbol;
                pLegendItem.LegendClassFormat = Legend.Item[lengendinex].LegendClassFormat;

                //列数设置
                //列数设置
                if (ColumnPos <= 1)
                {
                    pLegendItem.NewColumn = true;
                }
                else if (ColumnPos > 1 && i > 0)
                {
                    int columnI = i % ColumnPos;
                    if (columnI == 0)
                    {
                        pLegendItem.NewColumn = true;
                    }
                }
                legendlist.Add(pLegendItem);
            }
            Legend.ClearItems();
            Legend.Refresh();
            for (int i = 0; i < legendlist.Count; i++)
            {
                Legend.AddItem(legendlist[i]);
            }
            ILegendLayout pLegendLayout = pLegendFormat as ILegendLayout;

            pLegendLayout.ScaleGraphicsOnResize = false;
            m_hookHelper.ActiveView.Refresh();
        }
示例#6
0
        // 添加图例
        private void AddLegend()
        {
            IActiveView        pActiveView = axPageLayoutControl_main.ActiveView;
            IGraphicsContainer pGC         = axPageLayoutControl_main.PageLayout as IGraphicsContainer;

            UID pUID = new UIDClass()
            {
                Value = "esriCarto.Legend"
            };
            IMapFrame pMapFrame = pGC.FindFrame(pActiveView.FocusMap) as IMapFrame;
            // 根据唯一标识符,创建与之对应的MapSurroundFrame
            IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(pUID, null);
            // 检查PageLayout中是否已有图例(有则删除)
            IElement pDelElement = axPageLayoutControl_main.FindElementByName("Legend");

            if (pDelElement != null)
            {
                pGC.DeleteElement(pDelElement);
            }
            // 设置MapSurroundFrame背景
            ISymbolBackground pSymbolBackground = new SymbolBackgroundClass()
            {
                FillSymbol = new SimpleFillSymbolClass()
                {
                    Color   = GetRgbColor(240, 240, 240),
                    Outline = new SimpleLineSymbolClass()
                    {
                        Color = GetRgbColor(0, 0, 0),
                        Width = 1
                    }
                }
            };

            pMapSurroundFrame.Background = pSymbolBackground;
            // 添加图例
            IElement  pElement = pMapSurroundFrame as IElement;
            IEnvelope pEnv     = axPageLayoutControl_main.Extent;

            pEnv.XMin        += 2;
            pEnv.YMin        += 3;
            pElement.Geometry = pEnv;
            IMapSurround pMapSurround = pMapSurroundFrame.MapSurround;
            ILegend      pLegend      = pMapSurround as ILegend;

            pLegend.ClearItems();
            pLegend.Title = "图例";
            for (int i = 0; i < pActiveView.FocusMap.LayerCount; i++)
            {
                ILegendItem pLegendItem = new HorizontalLegendItemClass()
                {
                    Layer            = pActiveView.FocusMap.get_Layer(i),
                    ShowDescriptions = false,
                    Columns          = 1,
                    ShowHeading      = true,
                    ShowLabels       = true
                };
                pLegend.AddItem(pLegendItem);
            }
            pGC.AddElement(pElement, 0);
            pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }