Exemple #1
0
        /// <summary>
        /// 设置图例属性
        /// </summary>
        /// <param name="pLegend">图例</param>
        /// <param name="pMap">地图</param>
        private static void SetLegendProperty(ILegend2 pLegend, IMap pMap)
        {
            pLegend.ClearItems();
            pLegend.Title          = "Legend";
            pLegend.AutoVisibility = true;
            ILegendFormat lFormat = pLegend.Format;

            lFormat.DefaultPatchHeight = 20;
            lFormat.DefaultPatchWidth  = 30;
            lFormat.TitleSymbol        = GetTextSymbol();
            for (int i = 0; i < pMap.LayerCount; i++)
            {
                ILegendItem pLegendItem = new HorizontalLegendItemClass();
                pLegendItem.Layer   = pMap.Layer[i]; //获取添加图例关联图层
                pLegendItem.Columns = 2;
                ILegendClassFormat iClassFormat = pLegendItem.LegendClassFormat;
                iClassFormat.LabelSymbol = GetTextSymbol();
                //iClassFormat.DescriptionSymbol = GetTextSymbol();
                pLegendItem.HeadingSymbol    = GetTextSymbol();
                pLegendItem.ShowDescriptions = false;
                pLegendItem.ShowHeading      = true;
                pLegendItem.ShowLabels       = true;
                pLegendItem.ShowLayerName    = false;
                pLegend.AddItem(pLegendItem); //添加图例内容
            }
        }
        // 添加图例
        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);
        }
Exemple #3
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);
        }
Exemple #4
0
        public static void AddLegend(AxPageLayoutControl pageLayoutControl)
        {
            try
            {
                IEnvelope pEnvelope = new EnvelopeClass();
                pEnvelope.PutCoords(0.2,0.2,5,5);
                IActiveView pActiveView = pageLayoutControl as IActiveView;
                IMap pMap = pActiveView.FocusMap;
                IGraphicsContainer pGraphicsContainer = pActiveView as IGraphicsContainer;
                IMapFrame pMapFram = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
                IElement mapElement = pMapFram as IElement;
                IEnvelope mapEnv = mapElement.Geometry.Envelope;
                pEnvelope.PutCoords(mapEnv.XMin, mapEnv.YMin, mapEnv.XMin + 6.5, mapEnv.YMin + 0.8);
                UID pUID = new UID();
                pUID.Value = "{7A3F91E4-B9E3-11d1-8756-0000F8751720}";
                ISymbolBackground pSymbolBackground = new SymbolBackgroundClass();
                IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
                ILineSymbol pLineSymbol = new SimpleLineSymbolClass();
                pFillSymbol.Color = GetRgbColor(255, 255, 255);
                pLineSymbol.Color = GetRgbColor(255, 255, 255);
                pFillSymbol.Outline = pLineSymbol;
                pSymbolBackground.FillSymbol = pFillSymbol;
                IMapSurroundFrame pMapSurroundFrame = pMapFram.CreateSurroundFrame(pUID, null);
                pMapSurroundFrame.Background = pSymbolBackground;
                IElement pElement = pMapSurroundFrame as IElement;
                pElement.Geometry = pEnvelope;
                IMapSurround pMapSurround = pMapSurroundFrame.MapSurround;
                ILegend pLegend = pMapSurround as ILegend;
                pLegend.ClearItems();
                pLegend.Title = "图例";
                ITextSymbol pTextSymbol = new TextSymbolClass();
                pTextSymbol.Size = 10;
                pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
                ILegendItem pLegendItem = null;
                for (int i = 0; i < pActiveView.FocusMap.LayerCount; i++)
                {
                    ILayer pLayer = pActiveView.FocusMap.get_Layer(i);
                    if (pLayer is IFeatureLayer)
                    {
                        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;
                            pLegendItem.LayerNameSymbol = pTextSymbol;
                            pLegend.AddItem(pLegendItem);
                        }
                    }
                }

            }
            catch(Exception Err)
            { }
        }
Exemple #5
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();
        }
        //更新图例
        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();
        }
Exemple #7
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();
        }
        // 添加图例
        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);
        }
Exemple #9
0
        //创建图例
        private void CreateLegend()
        {
            ILegendFormat     pLegendFormat     = new LegendFormatClass();
            IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();

            pActiveView = m_hookHelper.ActiveView as IActiveView;
            pMap        = pActiveView.FocusMap;

            //边框、背景、阴影的间距
            if (txtLegendFrameGap.Text != null && pSymbolBorder != null)
            {
                pSymbolBorder.Gap = double.Parse(this.txtLegendFrameGap.Text);
            }
            if (txtLegendFrameGap.Text != null && pSymbolBackground != null)
            {
                pSymbolBackground.Gap = double.Parse(this.txtLegendFrameGap.Text);
            }
            if (txtLegendFrameGap.Text != null && pSymbolShadow != null)
            {
                pSymbolShadow.VerticalSpacing   = double.Parse(this.txtLegendFrameGap.Text) + 10;
                pSymbolShadow.HorizontalSpacing = double.Parse(this.txtLegendFrameGap.Text) + 10;
            }
            //边框、背景、阴影的角度
            if (txtLegendFrameAngle.Text != null && pSymbolBorder != null)
            {
                pSymbolBorder.CornerRounding = short.Parse(txtLegendFrameAngle.Text);
            }
            if (txtLegendFrameAngle.Text != null && pSymbolBackground != null)
            {
                pSymbolBackground.CornerRounding = short.Parse(txtLegendFrameAngle.Text);
            }
            if (txtLegendFrameAngle.Text != null && pSymbolShadow != null)
            {
                pSymbolShadow.CornerRounding = short.Parse(txtLegendFrameAngle.Text);
            }
            //边框、背景、阴影
            IFrameProperties pFrameProperties = pMapSurroundFrame as IFrameProperties;

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

            //显示标题
            pLegendFormat.ShowTitle = true;
            //标题位置
            pLegendFormat.TitlePosition = esriRectanglePosition.esriTopSide;
            //标题样式
            pLegendFormat.TitleSymbol = CreateTitleSymbol();


            //第四界面从上到下图例各部分之间的距离
            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);

            pLegendFormat.LayerNameGap = 2;

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


            //创建图例
            ILegend pLegend = new LegendClass_2();

            //图例名称
            //pLegend.Name = this.txtLegendTitle.Text;
            pLegend.AutoVisibility = false; //显示显示的图层
            pLegend.AutoAdd        = false; //自动添加新数据到图例

            pLegend.AutoReorder = true;     //根据图层顺序自动排列
            pLegend.Title       = this.txtLegendTitle.Text;
            pLegend.Format      = pLegendFormat;

            pLegend.Map = pMap;
            pLegend.ClearItems();
            //pLegend.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();

                ILayer pLayer = (ILayer)(pMap.get_Layer(pSelectedidx[i]));
                if (!pLayer.Valid)
                {
                    continue;
                }
                pLegendItem.Layer = pLayer;

                //显示标注和描述
                pLegendItem.ShowDescriptions = true;
                pLegendItem.ShowLabels       = true;

                //标注和描述字体样式
                ITextSymbol pLDTextSymbol = new TextSymbolClass();
                IFontDisp   pLDFont       = new StdFontClass() as IFontDisp;
                IRgbColor   pLDColor      = new RgbColorClass();
                pLDColor.Red        = 0;
                pLDColor.Green      = 0;
                pLDColor.Blue       = 0;
                pLDTextSymbol.Color = pLDColor;

                pLDFont.Size       = (decimal)8;
                pLDFont.Name       = "宋体";
                pLDTextSymbol.Font = pLDFont;
                ILegendClassFormat pLegendClassFormat = new LegendClassFormatClass();
                pLegendClassFormat.LabelSymbol       = pLDTextSymbol;
                pLegendClassFormat.DescriptionSymbol = pLDTextSymbol;

                pLegendItem.LegendClassFormat = pLegendClassFormat;
                //图层名称是否显示
                if (pLegendItem.Layer is IFeatureLayer)
                {
                    if (((IGeoFeatureLayer)pLegendItem.Layer).Renderer is ISimpleRenderer)
                    {
                        pLegendItem.ShowHeading   = false;
                        pLegendItem.ShowLayerName = false;
                    }
                    else
                    {
                        pLegendItem.ShowLayerName = true;
                        pLegendItem.ShowHeading   = true;
                        //图层名称和头文件的样式
                        ITextSymbol pLHTextSymbol = new TextSymbolClass();
                        IFontDisp   pLHFont       = new StdFontClass() as IFontDisp;
                        IRgbColor   pLHColor      = new RgbColorClass();
                        pLDColor.Red   = 0;
                        pLDColor.Green = 0;
                        pLDColor.Blue  = 0;

                        pLHTextSymbol.Color = pLHColor;
                        pLHFont.Name        = "宋体";
                        pLHFont.Size        = 10;
                        pLHFont.Bold        = true;
                        pLHTextSymbol.Font  = pLHFont;
                        pLHTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;

                        pLegendItem.HeadingSymbol   = pLHTextSymbol;
                        pLegendItem.LayerNameSymbol = pLHTextSymbol;
                    }
                }
                else if (pLegendItem.Layer is IRasterLayer)
                {
                    pLegendItem.ShowLayerName = true;
                    pLegendItem.ShowHeading   = true;
                    //图层名称和头文件的样式
                    ITextSymbol pLHTextSymbol = new TextSymbolClass();
                    IFontDisp   pLHFont       = new StdFontClass() as IFontDisp;
                    IRgbColor   pLHColor      = new RgbColorClass();
                    pLDColor.Red   = 0;
                    pLDColor.Green = 0;
                    pLDColor.Blue  = 0;

                    pLHTextSymbol.Color = pLHColor;
                    pLHFont.Name        = "宋体";
                    pLHFont.Size        = 10;
                    pLHFont.Bold        = true;
                    pLHTextSymbol.Font  = pLHFont;
                    pLHTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;

                    pLegendItem.HeadingSymbol   = pLHTextSymbol;
                    pLegendItem.LayerNameSymbol = pLHTextSymbol;
                }

                //列数设置
                if (ColumnPos <= 1)
                {
                    pLegendItem.NewColumn = true;
                }
                else if (ColumnPos > 1 && i > 0)
                {
                    int columnI = i % ColumnPos;
                    if (columnI == 0)
                    {
                        pLegendItem.NewColumn = true;
                    }
                }

                ILegendLayout pLegendLayout = pLegendFormat as ILegendLayout;
                pLegendLayout.ScaleGraphicsOnResize = false;


                //将图层及样式设计加入图例中
                pLegend.AddItem(pLegendItem);
                pLegend.Refresh();
            }



            //将图例加载到PageLayout上
            IGraphicsContainer pGraphicsContainer = pActiveView.GraphicsContainer;
            IMapFrame          pMapFrame          = pGraphicsContainer.FindFrame(pMap) as IMapFrame;

            if (pMapFrame == null)
            {
                return;
            }

            pMapSurroundFrame.MapFrame    = pMapFrame;
            pMapSurroundFrame.MapSurround = (IMapSurround)pLegend;
            IElement pElement = (IElement)pMapSurroundFrame;


            IPageLayout pPageLayout = (IPageLayout)pActiveView;
            IPage       pPage       = pPageLayout.Page;
            double      pWidth      = pPage.PrintableBounds.XMax / 10.0;
            double      pHeigth     = pPage.PrintableBounds.YMin / 10.0;

            IEnvelope pEnvelope = new EnvelopeClass();

            pEnvelope.PutCoords(pWidth, pHeigth, pWidth + 6, pHeigth + 6);
            pElement.Geometry = (IGeometry)pEnvelope;

            pGraphicsContainer.AddElement((IElement)pMapSurroundFrame, 0);

            m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pMapSurroundFrame, null);
        }
Exemple #10
0
        private void frmSymbolProperty_Load(object sender, EventArgs e)
        {
            if (this.m_pStyleGalleryItem != null)
            {
                this.txtName.Text       = this.m_pStyleGalleryItem.Name;
                this.txtCategory.Text   = this.m_pStyleGalleryItem.Category;
                this.symbolItem1.Symbol = this.m_pStyleGalleryItem.Item;
                if (this.symbolItem1.Symbol is IMarkerSymbol)
                {
                    this.m_SymbolType = enumSymbolType.enumSTPoint;
                }
                else if (this.symbolItem1.Symbol is ILineSymbol)
                {
                    this.m_SymbolType = enumSymbolType.enumSTLine;
                }
                else if (this.symbolItem1.Symbol is IFillSymbol)
                {
                    this.m_SymbolType = enumSymbolType.enumSTFill;
                }
                else if (this.symbolItem1.Symbol is ITextSymbol)
                {
                    this.m_SymbolType = enumSymbolType.enumSTText;
                }
                else if (this.symbolItem1.Symbol is IColorRamp)
                {
                    this.m_SymbolType = enumSymbolType.enumSTColorRamp;
                }
                else if (this.symbolItem1.Symbol is IColor)
                {
                    this.m_SymbolType = enumSymbolType.enumSTColor;
                }
                else if (this.symbolItem1.Symbol is ISymbolBorder)
                {
                    this.m_SymbolType = enumSymbolType.enumSTBorder;
                }
                else if (this.symbolItem1.Symbol is ISymbolBackground)
                {
                    this.m_SymbolType = enumSymbolType.enumSTBackground;
                }
                else if (this.symbolItem1.Symbol is ISymbolShadow)
                {
                    this.m_SymbolType = enumSymbolType.enumSTShadow;
                }
                else if (this.symbolItem1.Symbol is IMarkerNorthArrow)
                {
                    this.m_SymbolType = enumSymbolType.enumSTNorthArrow;
                }
                else if (this.symbolItem1.Symbol is IScaleBar)
                {
                    this.m_SymbolType = enumSymbolType.enumSTScaleBar;
                }
                else if (this.symbolItem1.Symbol is IScaleText)
                {
                    this.m_SymbolType = enumSymbolType.enumSTScaleText;
                }
                else if (this.symbolItem1.Symbol is ILegendItem)
                {
                    this.m_SymbolType = enumSymbolType.enumSTLegendItem;
                }
                else
                {
                    this.m_SymbolType = enumSymbolType.enumSTUnknown;
                }
            }
            else
            {
                this.m_pStyleGalleryItem = new ServerStyleGalleryItemClass();
                object obj2 = null;
                switch (this.m_SymbolType)
                {
                case enumSymbolType.enumSTPoint:
                    this.txtName.Text = "点符号";
                    obj2 = new MultiLayerMarkerSymbolClass();
                    ((IMultiLayerMarkerSymbol)obj2).AddLayer(new SimpleMarkerSymbolClass());
                    break;

                case enumSymbolType.enumSTLine:
                    this.txtName.Text = "线符号";
                    obj2 = new MultiLayerLineSymbolClass();
                    ((IMultiLayerLineSymbol)obj2).AddLayer(new SimpleLineSymbolClass());
                    break;

                case enumSymbolType.enumSTFill:
                    this.txtName.Text = "面符号";
                    obj2 = new MultiLayerFillSymbolClass();
                    ((IMultiLayerFillSymbol)obj2).AddLayer(new SimpleFillSymbolClass());
                    break;

                case enumSymbolType.enumSTText:
                case enumSymbolType.enumSTColorRamp:
                case enumSymbolType.enumSTColor:
                case enumSymbolType.enumSTLinePatch:
                case enumSymbolType.enumSTAreaPatch:
                    return;

                case enumSymbolType.enumSTNorthArrow:
                    this.txtName.Text = "指北针";
                    obj2 = new MarkerNorthArrowClass();
                    break;

                case enumSymbolType.enumSTScaleBar:
                    this.txtName.Text = "比例尺";
                    obj2 = new ScaleLineClass();
                    break;

                case enumSymbolType.enumSTScaleText:
                    this.txtName.Text = "比例尺文本";
                    obj2 = new ScaleTextClass();
                    break;

                case enumSymbolType.enumSTBorder:
                    this.txtName.Text = "边界";
                    obj2 = new SymbolBorderClass();
                    break;

                case enumSymbolType.enumSTShadow:
                    this.txtName.Text = "阴影";
                    obj2 = new SymbolShadowClass();
                    break;

                case enumSymbolType.enumSTBackground:
                    this.txtName.Text = "背景";
                    obj2 = new SymbolBackgroundClass();
                    break;

                case enumSymbolType.enumSTLegendItem:
                    this.txtName.Text = "图例项";
                    obj2 = new HorizontalLegendItemClass();
                    break;

                case enumSymbolType.enumSTLabel:
                    this.txtName.Text = "标注";
                    obj2 = new LabelStyleClass();
                    break;

                default:
                    return;
                }
                this.symbolItem1.Symbol           = obj2;
                this.m_pStyleGalleryItem.Name     = this.txtName.Text;
                this.m_pStyleGalleryItem.Category = this.txtCategory.Text;
                this.m_pStyleGalleryItem.Item     = obj2;
            }
        }