Ejemplo n.º 1
0
        //创建比例尺
        private void CreateScale()
        {
            if (StyleGalleryItem == null)
            {
                return;
            }

            IGraphicsContainer pGraphicsContainer = m_hookHelper.ActiveView.GraphicsContainer;
            IMapFrame          pMapFrame          = pGraphicsContainer.FindFrame(m_hookHelper.ActiveView.FocusMap) as IMapFrame;

            if (pMapFrame == null)
            {
                return;
            }

            if (StyleGalleryItem.Item is IScaleBar)
            {
                IScaleBar pScaleBar = (IScaleBar)StyleGalleryItem.Item;
                pScaleBar.Refresh();
                IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();
                pMapSurroundFrame.MapFrame = pMapFrame;

                pMapSurroundFrame.MapSurround = (IMapSurround)pScaleBar;
                IElement pElement = (IElement)pMapSurroundFrame;

                //添加和指北针一样大小的窗口
                double pScaleBarSize = 15;
                //显示结果大小
                IActiveView pActiveView = m_hookHelper.ActiveView;
                IPageLayout pPageLayout = (IPageLayout)pActiveView;
                IPage       pPage       = pPageLayout.Page;

                double pWidth  = pPage.PrintableBounds.XMin + 2;
                double pHeigth = pPage.PrintableBounds.YMin + 2;

                IEnvelope pEnv = new EnvelopeClass();
                pEnv.PutCoords(pWidth, pHeigth, pWidth + 10, pHeigth + 1);
                pElement.Geometry = (IGeometry)pEnv;

                //Add the element to the graphics container
                pGraphicsContainer.AddElement((IElement)pMapSurroundFrame, 0);
                //Refresh
                m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pMapSurroundFrame, null);
            }
            else if (StyleGalleryItem.Item is IScaleText)
            {
                IScaleText pScaleText = (IScaleText)StyleGalleryItem.Item;
                pScaleText.Refresh();
                IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass();
                pMapSurroundFrame.MapFrame = pMapFrame;

                pMapSurroundFrame.MapSurround = (IMapSurround)pScaleText;
                IElement pElement = (IElement)pMapSurroundFrame;

                //显示结果大小
                IActiveView pActiveView = m_hookHelper.ActiveView;
                IPageLayout pPageLayout = (IPageLayout)pActiveView;
                IPage       pPage       = pPageLayout.Page;


                double pWidth  = pPage.PrintableBounds.XMin + 2;
                double pHeigth = pPage.PrintableBounds.YMin + 2;

                IEnvelope pEnv = new EnvelopeClass();
                pEnv.PutCoords(pWidth, pHeigth, pWidth + 10, pHeigth + 1);
                pElement.Geometry = (IGeometry)pEnv;

                //Add the element to the graphics container
                pGraphicsContainer.AddElement((IElement)pMapSurroundFrame, 0);
                //Refresh
                m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pMapSurroundFrame, null);
            }
        }
Ejemplo n.º 2
0
        private void axPageLayoutControl1_OnDoubleClick(object sender, IPageLayoutControlEvents_OnDoubleClickEvent e)
        {
            if (m_element != null)
            {
                IElementProperties pElementProp = m_element as IElementProperties;

                if (pElementProp.Type == "Text")
                {
                    ITextElement  pTextElement = pElementProp as ITextElement;
                    frmTextSymbol frmText      = new frmTextSymbol(ref pTextElement);
                    frmText.ShowDialog();
                    pElementProp = pTextElement as IElementProperties;
                    m_pageLayoutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphicSelection, null, null);
                    m_pageLayoutControl.ActiveView.Refresh();
                }
                else if (pElementProp.Type == "Map Surround Frame")
                {
                    IMapSurroundFrame pMapSurrounFrame = pElementProp as IMapSurroundFrame;
                    if (pMapSurrounFrame.MapSurround.Name == "Legend")
                    {
                        frmLegendWizard frmLegedWizard = new frmLegendWizard(m_Map, m_pageLayoutControl, pMapSurrounFrame);
                        frmLegedWizard.ShowDialog(); //修改图例属性
                    }
                    else if (pMapSurrounFrame.MapSurround.Name == "Alternating Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Hollow Scale Bar" ||
                             pMapSurrounFrame.MapSurround.Name == "Double lternating Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Scale Line" ||
                             pMapSurrounFrame.MapSurround.Name == "Single Division Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Stepped Scale Line")
                    {
                        ESRI.ArcGIS.Controls.esriSymbologyStyleClass styleClass = esriSymbologyStyleClass.esriStyleClassScaleBars;
                        frmLegendItemSymbol frmScaleBar     = new frmLegendItemSymbol();
                        IStyleGalleryItem   pstyGallertItem = frmScaleBar.GetItem(styleClass);//获取样式
                        IScaleBar           pscaleBar       = pMapSurrounFrame.MapSurround as IScaleBar;
                        esriUnits           punits          = pscaleBar.Units;
                        if (pstyGallertItem != null)
                        {
                            pscaleBar = (IScaleBar)pstyGallertItem.Item;
                        }
                        else
                        {
                            return;
                        }
                        pscaleBar.Map   = m_pageLayoutControl.ActiveView.FocusMap; //重新设置比例尺依附的地图及单位
                        pscaleBar.Units = punits;
                        pscaleBar.UseMapSettings();
                        pscaleBar.Refresh();
                        pMapSurrounFrame.MapSurround = pscaleBar as IMapSurround;                    //旧的比例尺样式转换为新的比例尺样式
                        m_pageLayoutControl.Refresh(esriViewDrawPhase.esriViewGraphics, null, null); //刷新
                    }
                    else if (pMapSurrounFrame.MapSurround.Name == "Scale Text")
                    {
                        frmLegendItemSymbol frmTextScal     = new frmLegendItemSymbol();
                        IStyleGalleryItem   pStyGalleryItem = frmTextScal.GetItem(esriSymbologyStyleClass.esriStyleClassScaleTexts);
                        IScaleText          pScaleText      = pMapSurrounFrame.MapSurround as IScaleText;
                        esriUnits           pUnits          = pScaleText.MapUnits;
                        if (pStyGalleryItem != null)
                        {
                            pScaleText = (IScaleText)pStyGalleryItem.Item;
                        }
                        else
                        {
                            return;
                        }
                        pScaleText.Map               = m_pageLayoutControl.ActiveView.FocusMap;
                        pScaleText.MapUnits          = pScaleText.MapUnits;
                        pMapSurrounFrame.MapSurround = pScaleText as IMapSurround;
                        m_pageLayoutControl.Refresh(esriViewDrawPhase.esriViewGraphics, null, null);
                    }
                    else if (pMapSurrounFrame.MapSurround.Name.Trim() == "North Arrow")
                    {
                        INorthArrow         northArrow      = pMapSurrounFrame.MapSurround as INorthArrow;
                        frmNorthArrowSymbol frmNorthArrow   = new frmNorthArrowSymbol();
                        IStyleGalleryItem   pstyGallertItem = frmNorthArrow.GetItem(esriSymbologyStyleClass.esriStyleClassNorthArrows);;
                        if (pstyGallertItem != null)
                        {
                            northArrow = (INorthArrow)pstyGallertItem.Item;
                            northArrow.CalibrationAngle = frmNorthArrow.Angle();
                        }
                        else
                        {
                            return;
                        }
                        pMapSurrounFrame.MapSurround = (IMapSurround)northArrow;
                        m_pageLayoutControl.Refresh(esriViewDrawPhase.esriViewGraphics, null, null);
                    }
                }
            }
        }