Exemple #1
0
        /// <summary>
        /// 添加图例或指北针——根据UID元素添加相应的元素
        /// </summary>
        /// <param name="uid"></param>
        private void AddElementInPageLayer(UID uid)
        {
            //提供对控制图形容器的成员的访问。
            IGraphicsContainer graphicsContainer = axPageLayoutControl1.PageLayout as IGraphicsContainer;
            //提供对成员的访问, 控制map元素的对象, IMapFrame是地图浏览栏对象的默认接口
            //通过FindFrame方法, 查找axPageLayoutControl1中屏幕包含指定对象的框架
            IMapFrame mapFrame = graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap) as IMapFrame;
            //提供对成员的访问, 控制地图环绕元素映射的接口, 是附属物框架的对象的默认接口
            //通过CreateSurroundFrame方法创建基于当前地图框下的一个新地图环绕元素(如图例、指北针)
            IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null);
            //IElement是所有图形元素和框架元素类都要实现的接口
            //将mapSurroundFrame强转成IElement类型
            IElement element = mapSurroundFrame as IElement;
            //实例化一个包络线
            IEnvelope envelope = new EnvelopeClass();

            //设定坐标
            envelope.PutCoords(1, 1, 2, 2);
            //设置元素中的几何形状
            element.Geometry = envelope;
            try
            {
                //提供对控制图例的成员的访问。
                ILegend legend = (ILegend)mapSurroundFrame.MapSurround;
                legend.Title = "图例";
            }
            catch
            { }
            graphicsContainer.AddElement(element, 0);
            //设置元素将在axPageLayoutControl屏幕上显示图形
            element.Activate(axPageLayoutControl1.ActiveView.ScreenDisplay);
            //部分刷新
            axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
        public override IElement GetElement(IPageLayout ipageLayout_0)
        {
            if (base.m_pElement == null)
            {
                this.CreateElement(ipageLayout_0);
            }
            if (base.m_pElement == null)
            {
                return(null);
            }
            IPoint    position = this.GetPosition(ipageLayout_0);
            IEnvelope bounds   = new EnvelopeClass();

            base.m_pElement.QueryBounds((ipageLayout_0 as IActiveView).ScreenDisplay, bounds);
            if ((base.m_pElement as IMapSurroundFrame).MapSurround is ILegend)
            {
                ILegend mapSurround = (base.m_pElement as IMapSurroundFrame).MapSurround as ILegend;
                mapSurround.Map = (ipageLayout_0 as IActiveView).FocusMap;
                mapSurround.Refresh();
            }
            if (!bounds.IsEmpty)
            {
                IEnvelope envelope2 = new EnvelopeClass();
                envelope2.PutCoords(position.X, position.Y, position.X + bounds.Width, position.Y + bounds.Height);
                base.m_pElement.Geometry = envelope2;
            }
            return(base.m_pElement);
        }
Exemple #3
0
        //尝试复制Legend
        private void DeepCopyLegend(ILegend SrcLegend, ILegend DstLegend)
        {
            IClone pSrc  = SrcLegend as IClone;
            IClone pDest = pSrc.Clone();

            DstLegend = pDest as ILegend;
        }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapWin"/> class where the Map, Legend, Form and MenuStrip
 /// are all specified.
 /// </summary>
 /// <param name="inMap">Any valid implementation of IBasicMap</param>
 /// <param name="inLegend">Any valid implementation of ILegend</param>
 /// <param name="inMainForm">Any valid windows Form</param>
 /// <param name="inMenuStrip">Any valid windows MenuStrip</param>
 public MapWin(IBasicMap inMap, ILegend inLegend, Form inMainForm, MenuStrip inMenuStrip)
 {
     Map             = inMap;
     Legend          = inLegend;
     MainForm        = inMainForm;
     MenuStrip       = inMenuStrip;
     UserInteraction = new UserInteraction();
 }
Exemple #5
0
        public void SetObjects(object object_0)
        {
            this.imapSurroundFrame_0 = object_0 as IMapSurroundFrame;
            this.ilegend_0           = this.imapSurroundFrame_0.MapSurround as ILegend;
            ILegendFormat format = this.ilegend_0.Format;

            this.itextSymbol_0 = format.TitleSymbol;
        }
Exemple #6
0
 /// <summary>
 /// Constructs a new instance of a MapWin interface where the Map, Legend, Form and MenuStrip
 /// are all specified.
 /// </summary>
 /// <param name="inMap">Any valid implementation of IBasicMap</param>
 /// <param name="inLegend">Any valid implementation of ILegend</param>
 /// <param name="inMainForm">Any valid windows Form</param>
 /// <param name="inMenuStrip">Any valid windows MenuStrip</param>
 public MapWin(IBasicMap inMap, ILegend inLegend, Form inMainForm, MenuStrip inMenuStrip)
 {
     _map             = inMap;
     _legend          = inLegend;
     _mainForm        = inMainForm;
     _menuStrip       = inMenuStrip;
     _userInteraction = new UserInteraction();
 }
 public FrmLegendStyle(ILegendItem legenditem, ILegend legend, int index)
 {
     InitializeComponent();
     this.EnableGlass = false;
     pLegendItem      = legenditem;
     pLegend          = legend;
     lineindex        = index;
 }
Exemple #8
0
 /// <summary>
 /// Constructs a new instance of a MapWin interface where the Map, Legend, Form and MenuStrip
 /// are all specified.
 /// </summary>
 /// <param name="inMap">Any valid implementation of IBasicMap</param>
 /// <param name="inLegend">Any valid implementation of ILegend</param>
 /// <param name="inMainForm">Any valid windows Form</param>
 /// <param name="inMenuStrip">Any valid windows MenuStrip</param>
 public MapWin(IBasicMap inMap, ILegend inLegend, Form inMainForm, MenuStrip inMenuStrip)
 {
     _map = inMap;
     _legend = inLegend;
     _mainForm = inMainForm;
     _menuStrip = inMenuStrip;
     _userInteraction = new UserInteraction();
 }
Exemple #9
0
        public LegendPropertyForm(ILegend legendComplete, IElement pEle)
        {
            InitializeComponent();
            m_legend_Complete = legendComplete;
            m_pElement        = pEle;
            IMapSurroundFrame pSurround = pEle as IMapSurroundFrame;

            m_legend = pSurround.MapSurround as ILegend;
        }
        // 添加图例
        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);
        }
 /// <summary>
 /// Creates a new instance of the GeoPluginArgs
 /// </summary>
 /// <param name="map">Each Manager is associated with a single map</param>
 /// <param name="legend">The legend</param>
 /// <param name="mainMenu">The main menu</param>
 /// <param name="mainToolStrip">The main toolstrip</param>
 /// <param name="progressHandler">The progress handler</param>
 /// <param name="plugins">The list of plugins controlled by the manager</param>
 /// <param name="toolStripContainer">The container where any toolstrips should be added</param>
 public GeoPluginArgs(IMap map, ILegend legend, MenuStrip mainMenu, ToolStrip mainToolStrip, IProgressHandler progressHandler, List<IMapPlugin> plugins, ToolStripContainer toolStripContainer)
 {
     _toolStripContainer = toolStripContainer;
     _map = map;
     _legend = legend;
     _mainMenu = mainMenu;
     _mainToolStrip = mainToolStrip;
     _plugins = plugins;
     _progressHandler = progressHandler;
 }
Exemple #12
0
 private Point GetOffset(ILegend legend)
 {
     //var offset = new Point(0.5f * legend.BorderWidth + BorderMargin.Width, 0.5f * BorderWidth + BorderMargin.Height
     if (legend is Legend)
     {
         var l = (Legend)legend;
         return(new Point(2 * l.BorderMargin.Width + (int)(0.5f * l.BorderWidth) /*+ l.Padding.Width*/,
                          2 * l.BorderMargin.Height + (int)(0.5f * l.BorderWidth) /*+ l.Padding.Height*/));
     }
     return(new Point(legend.Settings.Padding));
 }
        int lineindex = 0;//记录目前被选中的legend的item的索引

        public FrmLegendAttribute(string[] symbolstyle, IElement element, IGraphicsContainer graphicscontainer, IHookHelper hookhelper)
        {
            InitializeComponent();
            this.EnableGlass   = false;
            SymbolStyle        = symbolstyle;
            pElement           = element;
            pGraphicsContainer = graphicscontainer;
            m_hookHelper       = hookhelper;
            pActiView          = m_hookHelper.PageLayout as IActiveView;
            pMap         = pActiView.FocusMap;
            pSelectedidx = new List <int>();

            pMapSurroundFrame = (IMapSurroundFrame)pElement;
            Legend            = pMapSurroundFrame.MapSurround as ILegend;
            pMap = Legend.Map;
        }
Exemple #14
0
        /// <summary>
        /// Overloaded constructor used create an instance of the LegendModel class during serialization.
        /// The public properties of this class are set by this contructor as they are obtained from the
        /// ILegend interface object passed as the parameter.
        /// </summary>
        /// <param name="legend">Specifies the ILegend interface object to be serialized.</param>
        /// <param name="chart">Specifies the IChart interface object of the parent IChart object being serialized.</param>
        public LegendModel(ILegend legend, IChartBase chart)
        {
            Position    = legend.Position;
            Orientation = legend.Orientation;
            Title       = legend.Title;
            Reversed    = legend.Reversed;

#if WINFORMS
            Style      = StyleSerializer.StyleToString(legend.GetStyle("_"), chart as IBrushConverter);
            TitleStyle = StyleSerializer.StyleToString(legend.GetStyle("_Title"), chart as IBrushConverter);
#endif
#if WPF
            Style      = StyleSerializer.StyleToString(legend.GetStyle(), chart as IBrushConverter);
            TitleStyle = StyleSerializer.StyleToString(legend.GetStyle("Title"), chart as IBrushConverter);
#endif
        }
        ///<summary>Add a Legend to the Page Layout from the Map.</summary>
        ///
        ///<param name="pageLayout">An IPageLayout interface.</param>
        ///<param name="map">An IMap interface.</param>
        ///<param name="posX">A System.Double that is X coordinate value in page units for the start of the Legend. Example: 2.0</param>
        ///<param name="posY">A System.Double that is Y coordinate value in page units for the start of the Legend. Example: 2.0</param>
        ///<param name="legW">A System.Double that is length in page units of the Legend in both the X and Y direction. Example: 5.0</param>
        ///
        ///<remarks></remarks>
        public void AddLegend(IPageLayout pageLayout, IMap map, Double posX, Double posY, Double legW)
        {
            if (pageLayout == null || map == null)
            {
                return;
            }
            ESRI.ArcGIS.Carto.IGraphicsContainer graphicsContainer = pageLayout as ESRI.ArcGIS.Carto.IGraphicsContainer;              // Dynamic Cast
            ESRI.ArcGIS.Carto.IMapFrame          mapFrame          = graphicsContainer.FindFrame(map) as ESRI.ArcGIS.Carto.IMapFrame; // Dynamic Cast


            ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
            uid.Value = "esriCarto.Legend";
            ESRI.ArcGIS.Carto.IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame((ESRI.ArcGIS.esriSystem.UID)uid, null); // Explicit Cast

            //Get aspect ratio
            ESRI.ArcGIS.Carto.IQuerySize querySize = mapSurroundFrame.MapSurround as ESRI.ArcGIS.Carto.IQuerySize; // Dynamic Cast
            System.Double w = 0;
            System.Double h = 0;
            querySize.QuerySize(ref w, ref h);
            System.Double aspectRatio = w / h;

            //
            ILegend pLegend = mapSurroundFrame.MapSurround as ILegend;

            pLegend.Title = "图例";
            pLegend.Format.TitlePosition = esriRectanglePosition.esriLeftSide | esriRectanglePosition.esriTopSide;
            pLegend.Format.TitleSymbol   = new TextSymbolClass()
            {
                Font = GetFontDisp(24)
            };
            pLegend.get_Item(0).ShowLayerName   = true;
            pLegend.get_Item(0).LayerNameSymbol = new TextSymbolClass()
            {
                Font = GetFontDisp(22)
            };
            pLegend.get_Item(0).LegendClassFormat.LabelSymbol = new TextSymbolClass()
            {
                Font = GetFontDisp(20)
            };

            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(posX, posY, (posX * legW), (posY * legW / aspectRatio));
            ESRI.ArcGIS.Carto.IElement element = mapSurroundFrame as ESRI.ArcGIS.Carto.IElement; // Dynamic Cast

            element.Geometry = envelope;
            graphicsContainer.AddElement(element, 0);
        }
Exemple #16
0
        protected virtual void OnLegendFactoryChanged(EventArgs e)
        {
            if (_map == null || _legendFactory == null)
            {
                return;
            }

            _legend = _legendFactory.Create(_map, _legendSettings);
            UpdateImage();

            var handler = LegendFactoryChanged;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Exemple #17
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 #18
0
        public LegendListener(IAppContext context, IBroadcasterService broadcaster, ILayerService layerService)
        {
            _context      = context;
            _broadcaster  = broadcaster;
            _layerService = layerService;

            if (_broadcaster == null || _context == null || layerService == null)
            {
                throw new NullReferenceException("Failed to initialize map listener.");
            }

            _legend = _context.Legend as ILegend;
            if (_legend == null)
            {
                throw new NullReferenceException("Legend reference is null.");
            }

            RegisterEvents();
        }
        private void button4_Click(object sender, System.EventArgs e)
        {
            //create the form with the SymbologyControl
            Form2 symbolForm = new Form2();

            //Get the IStyleGalleryItem that has been selected in the SymbologyControl
            IStyleGalleryItem styleGalleryItem = symbolForm.GetItem(esriSymbologyStyleClass.esriStyleClassLinePatches);

            //release the form
            symbolForm.Dispose();
            if (styleGalleryItem == null)
            {
                return;
            }

            //Find the legend
            IElement element = axPageLayoutControl1.FindElementByName("Legend", 1);

            if (element == null)
            {
                return;
            }

            //Get the IMapSurroundFrame
            IMapSurroundFrame mapSurroundFrame = (IMapSurroundFrame)element;

            if (mapSurroundFrame == null)
            {
                return;
            }

            //If a legend exists change the default area patch
            ILegend legend = (ILegend)mapSurroundFrame.MapSurround;

            legend.Format.DefaultLinePatch = (ILinePatch)styleGalleryItem.Item;

            //Update the legend
            legend.Refresh();
            //Refresh the display
            axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
        }
Exemple #20
0
 public void SetObjects(object object_0)
 {
     this.imapSurroundFrame_0 = object_0 as IMapSurroundFrame;
     this.ilegend_0           = this.imapSurroundFrame_0.MapSurround as ILegend;
 }
 /// <summary>
 /// Process all legend items of type T
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="legend">Legend</param>
 /// <param name="action">Action</param>
 public static void ForEachRecursively <T>(this ILegend legend, Action <T> action) where T : class
 {
     ForEachRecursively(legend.RootNodes, action);
 }
Exemple #22
0
 private static void old_acctor_mc()
 {
     m_pLegend = null;
     ApplyOk   = false;
     InitOK    = false;
 }
Exemple #23
0
        private void SetMapFrame()//设置地图基本信息,如比例尺,图例等:
        {
            IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)this.axPageLayoutControl1.ActiveView;

            pGraphicsContainer.Reset();
            IElementProperties pElementProperties = (IElementProperties)pGraphicsContainer.Next();

            while (pElementProperties != null)
            {
                if (pElementProperties is ITextElement)  //设置文本
                {
                    ITextElement ptextElement = new TextElementClass();
                    ptextElement = (ITextElement)pElementProperties;
                    if (ptextElement.Text.Trim() == "双击添加标题" || ptextElement.Symbol.Size > 25)
                    {
                        ptextElement.Text = m_textTitle;
                    }
                    if (ptextElement.Text.Trim().Contains("坐标系"))
                    {
                        ptextElement.Text = "坐标系:" + m_textProject + "\r" + "高程系:" + m_textElevation;
                    }

                    if (ptextElement.Text.Trim().Contains("制作者"))
                    {
                        ptextElement.Text = "制图人:" + m_textName + "\r" + "制作时间:" + m_textDate;
                    }
                }
                if (pElementProperties.Type == "Map Surround Frame")
                {
                    IMapSurroundFrame pMapSurrounFrame = pElementProperties as IMapSurroundFrame;
                    IElement          pElement         = (IElement)pElementProperties;

                    if (pMapSurrounFrame.MapSurround.Name.Trim() == "Legend")
                    {
                        ILegend pLegend = pMapSurrounFrame.MapSurround as ILegend;
                        pLegend.Map = m_Map;
                        //  IMapSurround pMapSurround = pMapSurrounFrame.MapSurround;
                        //pElement = pMapSurrounFrame.MapSurround as IElement;
                        //  pMapSurround.Map = m_Map;
                        //  m_Map.AddMapSurround(pMapSurround);
                    }
                    if (pMapSurrounFrame.MapSurround.Name == "Alternating Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Stepped Scale Line" || pMapSurrounFrame.MapSurround.Name == "Scale Line" ||
                        pMapSurrounFrame.MapSurround.Name == "Hollow Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Single Division Scale Bar" ||
                        pMapSurrounFrame.MapSurround.Name == "Double Alternating Scale Bar")
                    {
                        // m_Map.MapScale = 5000;
                        IScaleBar pScaleBar = pMapSurrounFrame.MapSurround as IScaleBar;
                        pScaleBar.Map = m_Map;


                        pScaleBar.Units = m_Map.MapUnits;
                        pScaleBar.UseMapSettings();

                        pElement = pMapSurrounFrame.MapSurround as IElement;
                    }
                    if (pMapSurrounFrame.MapSurround.Name == "Scale Text")
                    {
                        IScaleText pScaleText = pMapSurrounFrame.MapSurround as IScaleText;
                        pScaleText.Map = m_Map;
                    }
                    if (pMapSurrounFrame.MapSurround.Name == "North Arrow")
                    {
                        INorthArrow pNorthArrow = pMapSurrounFrame.MapSurround as INorthArrow;

                        pNorthArrow.Map = m_Map;
                    }
                }
                if (pElementProperties.Type == "Data Frame")
                {
                    IFrameElement pFrameElement = pElementProperties as IFrameElement;
                    IMapFrame     pMapframe     = pFrameElement as IMapFrame;
                    // pMapframe.ExtentType = esriExtentTypeEnum.esriExtentBounds;
                    IMapGrids pmapGrids = pMapframe as IMapGrids;
                    IMapGrid  pMapGrid  = null;
                    for (int i = 0; i < pmapGrids.MapGridCount; i++)
                    {
                        pMapGrid = pmapGrids.get_MapGrid(i);
                        //用户要求显示与否
                        pMapGrid.Visible = true;
                    }
                }

                pElementProperties = (IElementProperties)pGraphicsContainer.Next();
            }
            if (axPageLayoutControl1.Page.Orientation == 2)
            {
                IPaper paper;
                paper = new PaperClass();        //create a paper object
                IPrinter printer;
                printer = new EmfPrinterClass(); //create a printer object
                paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32());
                paper.Orientation            = 2;
                printer.Paper                = paper;
                axPageLayoutControl1.Printer = printer;

                pageSetupDialog1.PageSettings.Landscape = true;
                pageSetupDialog1.AllowOrientation       = true;
            }
            if (axPageLayoutControl1.Page.Orientation == 1 && axPageLayoutControl1.Printer.Paper.Orientation == 2)
            {
                IPaper paper;
                paper = new PaperClass();        //create a paper object
                IPrinter printer;
                printer = new EmfPrinterClass(); //create a printer object
                paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32());
                paper.Orientation                       = 1;
                printer.Paper                           = paper;
                axPageLayoutControl1.Printer            = printer;
                pageSetupDialog1.PageSettings.Landscape = false;
                pageSetupDialog1.AllowOrientation       = true;
            }
        }
Exemple #24
0
 private void Awake()
 {
     legend = transform.Find("Legend").GetComponent <Legend>();
     axes   = transform.Find("Axes").GetComponent <Axes>();
     Series = new SeriesCollection();
 }
Exemple #25
0
 /// <summary>
 /// Creates a new instance of Layers
 /// </summary>
 public Layers(ILegend inLegend)
 {
     _legend = inLegend; 
 }
        // 添加图例
        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 #27
0
        /// <summary>
        /// given a new map, replaces the PageLayoutControl and the MapControl's focus map
        /// </summary>
        /// <param name="newMap"></param>
        public void ReplaceMap(IMap newMap)
        {
            if (newMap == null)
            {
                throw new Exception("ControlsSynchronizer::ReplaceMap:\r\nNew map for replacement is not initialized!");
            }

            if (m_pageLayoutControl == null || m_mapControl == null)
            {
                throw new Exception("ControlsSynchronizer::ReplaceMap:\r\nEither MapControl or PageLayoutControl are not initialized!");
            }

            bool bIsMapActive = m_IsMapCtrlactive;

            #region 地图重置前记录所有图例的items
            //////////////////////////////////////////////////////////////////////////
            //ReplaceMap后会引起Legend的Map为null,重置map后会引起Item变化
            ArrayList pMaps        = new ArrayList(); //记录Legend对应的地图
            ArrayList pCount       = new ArrayList(); //记录每个Legend内部Items的数量
            ArrayList pLegendItems = new ArrayList(); //记录items

            IGraphicsContainer pGC = m_pageLayoutControl.ActiveView.GraphicsContainer;
            pGC.Reset();
            IElement pElement = pGC.Next();
            ILegend  pLegend  = null;

            while (pElement != null)
            {
                IElementProperties pElementProperties = pElement as IElementProperties;
                if (pElementProperties == null)
                {
                    continue;
                }
                if (pElementProperties.Name == "Legend" || pElementProperties.Name == "图例")
                {
                    IMapSurroundFrame pMapSurroundFrame = pElement as IMapSurroundFrame;
                    pLegend = pMapSurroundFrame.MapSurround as ILegend;
                    if (pLegend != null)
                    {
                        for (int i = 0; i < pLegend.ItemCount; i++)
                        {
                            pLegendItems.Add(pLegend.get_Item(i));
                        }
                        pCount.Add(pLegend.ItemCount);
                        pMaps.Add(pLegend.Map);
                    }
                }
                pElement = pGC.Next();
            }

            #endregion
            //////////////////////////////////////////////////////////////////////////
            //call replace map on the PageLayout in order to replace the focus map
            //we must call ActivatePageLayout, since it is the control we call 'ReplaceMaps'
            this.ActivatePageLayout();
            //assign the new map to the MapControl
            m_mapControl.Map = newMap;

            #region 重置后恢复图例的items
            pGC.Reset();
            int nIndex     = 0;
            int nItemStart = 0;
            pElement = pGC.Next();
            while (pElement != null)
            {
                IElementProperties pElementProperties = pElement as IElementProperties;
                if (pElementProperties == null)
                {
                    continue;
                }
                if (pElementProperties.Name == "Legend" || pElementProperties.Name == "图例")
                {
                    IMapSurroundFrame pMapSurroundFrame = pElement as IMapSurroundFrame;
                    pLegend = pMapSurroundFrame.MapSurround as ILegend;
                    if (pLegend != null)
                    {
                        if (pLegend.Map == null)
                        {
                            pLegend.Map = pMaps[nIndex] as IMap;
                            if (pLegend.ItemCount != (int)pCount[nIndex])
                            {
                                for (int i = pLegend.ItemCount - 1; i >= 0; i--)
                                {
                                    if (!FindItem(pLegendItems, nItemStart, (int)nItemStart + (int)pCount[nIndex], pLegend.get_Item(i)))//如果原来没有则删除
                                    {
                                        pLegend.RemoveItem(i);
                                    }
                                }
                            }
                        }
                        nItemStart += (int)pCount[nIndex];
                        nIndex++;
                    }
                }
                pElement = pGC.Next();
            }
            #endregion

            //reset the active tools
            m_pageLayoutActiveTool = null;
            m_mapActiveTool        = null;

            //make sure that the last active control is activated
            if (bIsMapActive)
            {
                this.ActivateMap();
                m_mapControl.ActiveView.Refresh();
            }
            else
            {
                this.ActivatePageLayout();
                m_pageLayoutControl.ActiveView.Refresh();
            }
        }
Exemple #28
0
        private void LegendWizard_Load(object sender, EventArgs e)
        {
            if (m_pageLayoutControl.ActiveView.FocusMap == null)
            {
                MessageBox.Show("请先添加地图");
                return;

            }
            #region //点击 添加图例按钮 或在 PageLayoutControl中双击图例时
            if (mapSurroundFrame == null)  //当点击 添加图例按钮 或在 PageLayoutControl中双击图例时 先创建图例 或从地图上获得已经添加的图例;
            {

                //Get the GraphicsContainer
                IGraphicsContainer graphicsContainer = m_pageLayoutControl.GraphicsContainer;
                graphicsContainer.Reset();
                IElementProperties pElementPerties = graphicsContainer.Next() as IElementProperties;
                //Get the MapFrame
                IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(m_pageLayoutControl.ActiveView.FocusMap);
                if (mapFrame == null) return;
                while (pElementPerties != null) //从地图中获得已有的图例
                {
                    if (pElementPerties.Type == "Map Surround Frame")
                    {
                        pMapSurrounFrame = pElementPerties as IMapSurroundFrame;
                        if (pMapSurrounFrame.MapSurround.Name == "Legend")
                        {
                            m_legend = pMapSurrounFrame.MapSurround as ILegend;
                            break;
                        }
                    }
                    pElementPerties = (IElementProperties)graphicsContainer.Next();
                }
                if (m_legend == null) //当地图中没有添加图例时 创建新图例
                {
                    //Create a legend
                    UID uID = new UIDClass();
                    uID.Value = "esriCarto.Legend";

                    //Create a MapSurroundFrame from the MapFrame
                    mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null);

                    if (mapSurroundFrame == null) return;
                    if (mapSurroundFrame.MapSurround == null) return;

                    m_legend = mapSurroundFrame.MapSurround as ILegend;
                }
                else
                {
                    mapSurroundFrame = pMapSurrounFrame;

                }

                UID m_uid = new UIDClass();
                m_uid.Value = "{34C20002-4D3C-11D0-92D8-00805F7C28B0}";
                m_mapLayers = m_mapControl.Map as IMapLayers;
                m_emuLayer = m_mapLayers.get_Layers(m_uid, true);//获取图层
                if (m_emuLayer != null)
                {
                    m_emuLayer.Reset();
                    ILayer m_layer = null;
                    while ((m_layer = m_emuLayer.Next()) != null)
                    {
                        this.listBox1.Items.Add(m_layer.Name);//将图层名添加到图例备选项中
                    }
                }
            }
               #endregion
            else //在双击任意范围打印框中图例时,获得图例,及图层信息;
            {
                if (m_Map == null)
                {
                    MessageBox.Show("请先添加地图!");
                }
                for (int k = 0; k < m_Map.LayerCount; k++)
                {
                    listBox1.Items.Add(m_Map.get_Layer(k).Name.ToString());
                }
                m_legend = mapSurroundFrame .MapSurround as ILegend;
            }
            //以下设置需要用到的变量 及初始化 对话框
            plegendFormat = m_legend.Format as ILegendFormat; //设置图例格式需要用到的

            pTextSymbol = new TextSymbolClass();
            pTextSymbol.Size = 10;
            pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; //初始化图例标签的文本格式

            if (m_legend.Title != null)
                textBox1.Text = m_legend.Title.ToString(); //初始化对话框中的文本框 文本
            else
                textBox1.Text = "Legend";

            this.textBoxWidth.Text = "36";
            this.textBoxHeight.Text = "15";
            IMapSurround mapSurround = m_legend as IMapSurround;
            mapSurroundFrame.MapSurround = mapSurround;
            m_FrameProperties = (IFrameProperties)mapSurroundFrame;
            ISymbolBackground pSymbolBack = m_FrameProperties.Background as ISymbolBackground;
            ISymbolBorder pSymbolBorder = m_FrameProperties.Border as ISymbolBorder;
            ISymbolShadow pSymbolShadow = m_FrameProperties.Shadow as ISymbolShadow;
            if (pSymbolBack !=null )
            this.btnBackGroundColor.BackColor =ColorTranslator.FromOle ( pSymbolBack.FillSymbol.Color.RGB ) ;
            if (pSymbolBorder != null)
            this.btnBolderColor.BackColor = ColorTranslator.FromOle(pSymbolBorder.LineSymbol.Color.RGB);
             if (pSymbolShadow != null)
            this.btnShadowColor.BackColor = ColorTranslator.FromOle(pSymbolShadow.FillSymbol.Color.RGB);
        }
Exemple #29
0
        private void LegendWizard_Load(object sender, EventArgs e)
        {
            if (m_pageLayoutControl.ActiveView.FocusMap == null)
            {
                MessageBox.Show("请先添加地图");
                return;
            }
            #region                       //点击 添加图例按钮 或在 PageLayoutControl中双击图例时
            if (mapSurroundFrame == null) //当点击 添加图例按钮 或在 PageLayoutControl中双击图例时 先创建图例 或从地图上获得已经添加的图例;
            {
                //Get the GraphicsContainer
                IGraphicsContainer graphicsContainer = m_pageLayoutControl.GraphicsContainer;
                graphicsContainer.Reset();
                IElementProperties pElementPerties = graphicsContainer.Next() as IElementProperties;
                //Get the MapFrame
                IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(m_pageLayoutControl.ActiveView.FocusMap);
                if (mapFrame == null)
                {
                    return;
                }
                while (pElementPerties != null) //从地图中获得已有的图例
                {
                    if (pElementPerties.Type == "Map Surround Frame")
                    {
                        pMapSurrounFrame = pElementPerties as IMapSurroundFrame;
                        if (pMapSurrounFrame.MapSurround.Name == "Legend")
                        {
                            m_legend = pMapSurrounFrame.MapSurround as ILegend;
                            break;
                        }
                    }
                    pElementPerties = (IElementProperties)graphicsContainer.Next();
                }
                if (m_legend == null) //当地图中没有添加图例时 创建新图例
                {
                    //Create a legend
                    UID uID = new UIDClass();
                    uID.Value = "esriCarto.Legend";

                    //Create a MapSurroundFrame from the MapFrame
                    mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null);

                    if (mapSurroundFrame == null)
                    {
                        return;
                    }
                    if (mapSurroundFrame.MapSurround == null)
                    {
                        return;
                    }

                    m_legend = mapSurroundFrame.MapSurround as ILegend;
                }
                else
                {
                    mapSurroundFrame = pMapSurrounFrame;
                }



                UID m_uid = new UIDClass();
                m_uid.Value = "{34C20002-4D3C-11D0-92D8-00805F7C28B0}";
                m_mapLayers = m_mapControl.Map as IMapLayers;
                m_emuLayer  = m_mapLayers.get_Layers(m_uid, true);//获取图层
                if (m_emuLayer != null)
                {
                    m_emuLayer.Reset();
                    ILayer m_layer = null;
                    while ((m_layer = m_emuLayer.Next()) != null)
                    {
                        this.listBox1.Items.Add(m_layer.Name);//将图层名添加到图例备选项中
                    }
                }
            }
            #endregion
            else //在双击任意范围打印框中图例时,获得图例,及图层信息;
            {
                if (m_Map == null)
                {
                    MessageBox.Show("请先添加地图!");
                }
                for (int k = 0; k < m_Map.LayerCount; k++)
                {
                    listBox1.Items.Add(m_Map.get_Layer(k).Name.ToString());
                }
                m_legend = mapSurroundFrame.MapSurround as ILegend;
            }
            //以下设置需要用到的变量 及初始化 对话框
            plegendFormat = m_legend.Format as ILegendFormat; //设置图例格式需要用到的

            pTextSymbol      = new TextSymbolClass();
            pTextSymbol.Size = 10;
            pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; //初始化图例标签的文本格式

            if (m_legend.Title != null)
            {
                textBox1.Text = m_legend.Title.ToString(); //初始化对话框中的文本框 文本
            }
            else
            {
                textBox1.Text = "Legend";
            }

            this.textBoxWidth.Text  = "36";
            this.textBoxHeight.Text = "15";
            IMapSurround mapSurround = m_legend as IMapSurround;
            mapSurroundFrame.MapSurround = mapSurround;
            m_FrameProperties            = (IFrameProperties)mapSurroundFrame;
            ISymbolBackground pSymbolBack   = m_FrameProperties.Background as ISymbolBackground;
            ISymbolBorder     pSymbolBorder = m_FrameProperties.Border as ISymbolBorder;
            ISymbolShadow     pSymbolShadow = m_FrameProperties.Shadow as ISymbolShadow;
            if (pSymbolBack != null)
            {
                this.btnBackGroundColor.BackColor = ColorTranslator.FromOle(pSymbolBack.FillSymbol.Color.RGB);
            }
            if (pSymbolBorder != null)
            {
                this.btnBolderColor.BackColor = ColorTranslator.FromOle(pSymbolBorder.LineSymbol.Color.RGB);
            }
            if (pSymbolShadow != null)
            {
                this.btnShadowColor.BackColor = ColorTranslator.FromOle(pSymbolShadow.FillSymbol.Color.RGB);
            }
        }
Exemple #30
0
 public LegendHitTester(ILegend legend, Panel panel)
 {
     _legend = legend;
     _panel  = panel;
 }