// 添加图例
        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 #2
0
        /// <summary>
        /// 获取图例背景
        /// </summary>
        /// <returns></returns>
        private static ISymbolBackground GetSymbolBackground()
        {
            //设置MapSurroundFrame背景
            ISymbolBackground pSymbolBackground = new SymbolBackgroundClass();
            IFillSymbol       pFillSymbol       = new SimpleFillSymbolClass();
            ILineSymbol       pLineSymbol       = new SimpleLineSymbolClass();

            pLineSymbol.Color            = AeColor.GetRgbColor(0, 0, 0);
            pFillSymbol.Color            = AeColor.GetRgbColor(240, 240, 240);
            pFillSymbol.Outline          = pLineSymbol;
            pSymbolBackground.FillSymbol = pFillSymbol;
            return(pSymbolBackground);
        }
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
        /// <summary>
        /// 为PageLayout对象添加图例对象
        /// </summary>
        /// <param name="pPageLayout">PageLayout对象</param>
        /// <param name="pEnvelope">图例添加的位置</param>
        public static void AddLegendToPageLayout(AxPageLayoutControl axpagelayoutcontrol, IEnvelope pEnvelope)
        {
            IPageLayout pageLayout;
            pageLayout = axpagelayoutcontrol.PageLayout;
            try
            {
                IActiveView pActiveView = pageLayout as IActiveView;
                IMap pMap = pActiveView.FocusMap;
                IGraphicsContainer pGraphicsContainer = pActiveView as IGraphicsContainer;
                IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
                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 = pMapFrame.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 HorizontalBarLegendItemClass();
                            pLegendItem.Layer = pLayer;
                            pLegendItem.Columns = 1;
                            pLegendItem.ShowDescriptions = false;
                            pLegendItem.ShowHeading = false;
                            pLegendItem.ShowLabels = true;
                            pLegendItem.LayerNameSymbol = pTextSymbol;
                            pLegend.AddItem(pLegendItem);
                        }
                    }
                }
            }
            catch(Exception  ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string input = this.tbxInput.Text;
            string cat = this.tbxSet.Text;
            string folder = this.tbxOutput.Text;
            string target = this.tbxTarget.Text;
            string depth = this.cbxDepth.Text;

            IStyleGalleryStorage sgs = new StyleGalleryClass();
            while (sgs.FileCount > 0)
            {
                sgs.RemoveFile(sgs.get_File(0));
            }
            IStyleGallery sg = sgs as IStyleGallery;
            sgs.AddFile(input);
            sgs.TargetFile = target;

            IPageLayout3 layout = new PageLayoutClass();
            IGraphicsContainer con = layout as IGraphicsContainer;
            IPage page = layout.Page;
            page.Units = esriUnits.esriPoints;

            IRgbColor bgc = new RgbColorClass();
            bgc.Red = 255;
            bgc.Green = 255;
            bgc.Blue = 254;
            IFrameProperties fp = page as IFrameProperties;
            ISymbolBackground bg = new SymbolBackgroundClass();
            bg.Gap = 0;
            ISimpleFillSymbol sfs = new SimpleFillSymbolClass();
            sfs.Color = bgc as IColor;
            ISimpleLineSymbol sls = new SimpleLineSymbolClass();
            sls.Style = esriSimpleLineStyle.esriSLSNull;
            sfs.Outline = sls;
            bg.FillSymbol = sfs as IFillSymbol;
            fp.Background = bg;

            IEnumStyleGalleryItem items = sg.get_Items("Marker Symbols", input, cat);
            IStyleGalleryItem item = items.Next();
            while (item != null)
            {
                //con.DeleteAllElements();
                IMarkerElement mele = new MarkerElementClass();
                IMarkerSymbol sym_m = item.Item as IMarkerSymbol;
                IMultiLayerMarkerSymbol sym_ml = sym_m as IMultiLayerMarkerSymbol;
                double pic_size;
                if (sym_ml.Size % 2 == 0)
                {
                    pic_size = sym_ml.Size+4;
                }
                else
                {
                    pic_size = sym_ml.Size+5;
                }
                page.PutCustomSize(pic_size, pic_size);
                IPoint ptn = new PointClass();
                ptn.PutCoords(pic_size / 2, pic_size / 2);
                IElement ele_i = mele as IElement;
                ele_i.Geometry = ptn;

                sym_m.Size = sym_ml.Size;
                mele.Symbol = sym_m;
                con.AddElement(ele_i, 0);
                IActiveView av = layout as IActiveView;
                string pic_file = folder+"\\"+item.Name + ".png";
                ExportPNG(av, pic_file,bgc,depth);
                con.DeleteElement(ele_i);

                ISymbol sym = CreatePictureMarkerSymbol(esriIPictureType.esriIPicturePNG, pic_file, pic_size) as ISymbol;
                IStyleGalleryItem newitem = new StyleGalleryItemClass();
                newitem.Name = item.Name;
                newitem.Item = sym;
                newitem.Category = cat;
                sg.AddItem(newitem);

                item = items.Next();
            }
            MessageBox.Show("成功导出图标");
        }
        // 添加图例
        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 #7
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;
            }
        }