/// <summary> /// 比例尺 /// </summary> /// <param name="pActiveView"></param> /// <param name="pPageLayout"></param> /// <param name="pEnv"></param> public void makeScaleBar(IActiveView pActiveView, IPageLayout pPageLayout, IEnvelope pEnv) { IGraphicsContainer container = pPageLayout as IGraphicsContainer; // 获得MapFrame IFrameElement frameElement = container.FindFrame(pActiveView.FocusMap); IMapFrame mapFrame = frameElement as IMapFrame; //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround UID uid = new UIDClass(); uid.Value = "esriCarto.AlternatingScaleBar"; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null); //设置MapSurroundFrame中比例尺的样式 IMapSurround mapSurround = mapSurroundFrame.MapSurround; IScaleBar markerScaleBar = ((IScaleBar)mapSurround); markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow; markerScaleBar.UseMapSettings(); //QI,确定mapSurroundFrame的位置 IElement element = mapSurroundFrame as IElement; element.Geometry = pEnv; //使用IGraphicsContainer接口添加显示 container.AddElement(element, 0); pActiveView.Refresh(); }
/// <summary> /// 生成默认比例尺 /// </summary> /// <param name="pageLayoutControl"></param> /// <param name="startX"></param> /// <param name="startY"></param> /// <returns></returns> public static IMapSurround GetDefaultScaleBar(IPageLayoutControlDefault pageLayoutControl, double startX, double startY) { try { IPageLayout pageLayout = pageLayoutControl.PageLayout; IGraphicsContainer container = pageLayout as IGraphicsContainer; IActiveView activeView = pageLayout as IActiveView; // 获得MapFrame IFrameElement frameElement = container.FindFrame(activeView.FocusMap); IMapFrame mapFrame = frameElement as IMapFrame; //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround UID uid = new UIDClass(); uid.Value = "esriCarto.AlternatingScaleBar"; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null); //设置MapSurroundFrame中比例尺的样式 IMapSurround mapSurround = mapSurroundFrame.MapSurround; IScaleBar markerScaleBar = ((IScaleBar)mapSurround); markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow; markerScaleBar.UseMapSettings(); //QI,确定mapSurroundFrame的位置 IElement element = mapSurroundFrame as IElement; IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(startX, startY, startX + 10, startY + 10); element.Geometry = envelope; mapSurround = mapSurroundFrame.MapSurround; return(mapSurround); } catch (System.Exception ex) { return(null); } }
public static void addScalebar(AxPageLayoutControl axPageLayoutControl, String type) { IPageLayout pageLayout = axPageLayoutControl.PageLayout; IActiveView activeView = pageLayout as IActiveView; IMap pMap = activeView.FocusMap; IGraphicsContainer pGraphicsContainer = pageLayout as IGraphicsContainer; IMapFrame mapFrame = (IMapFrame)pGraphicsContainer.FindFrame(pMap); UID uid = new UIDClass(); uid.Value = type; IMapSurroundFrame pMapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null); IMapSurround pMapSurround = pMapSurroundFrame.MapSurround; IScaleBar pScaleBar = (IScaleBar)pMapSurround; pScaleBar.LabelPosition = esriVertPosEnum.esriBelow; pScaleBar.UseMapSettings(); IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.PutCoords(0.8, 0.8, 13, 2); IElement element = pMapSurroundFrame as IElement; element.Geometry = pEnvelope; pGraphicsContainer.AddElement(element, 0); activeView.Refresh(); }
public void AddScaleBar() { IGraphicsContainer graphicsContainer = m_pagelayoutControl.GraphicsContainer; //Get the MapFrame IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(m_pagelayoutControl.ActiveView.FocusMap); if (mapFrame == null) { return; } //Create a legend UID uID = new UIDClass(); uID.Value = "esriCarto.ScaleLine"; //Create a MapSurroundFrame from the MapFrame IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null); if (mapSurroundFrame == null) { return; } if (mapSurroundFrame.MapSurround == null) { return; } // m_styleSelector = new ScaleBarSelectorClass(); IEnvelope m_envelop = new EnvelopeClass(); m_envelop.PutCoords(5, 5, 10, 10); ESRI.ArcGIS.Controls.esriSymbologyStyleClass styleClass = esriSymbologyStyleClass.esriStyleClassScaleBars; frmLegendItemSymbol frmScaleBar = new frmLegendItemSymbol(); IStyleGalleryItem pstyGallertItem = frmScaleBar.GetItem(styleClass); if (pstyGallertItem == null) { return; } IScaleBar pScalebar = pstyGallertItem.Item as IScaleBar; pScalebar.Units = m_pagelayoutControl.ActiveView.FocusMap.MapUnits; pScalebar.Map = m_pagelayoutControl.ActiveView.FocusMap; pScalebar.UseMapSettings(); IMapSurround m_mapSurround; m_mapSurround = (IMapSurround)pScalebar; mapSurroundFrame.MapSurround = m_mapSurround; IElement m_element = (IElement)mapSurroundFrame; m_element.Geometry = m_envelop; m_pagelayoutControl.AddElement(m_element, Type.Missing, Type.Missing, "ScaleLine", 3); m_pagelayoutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
// 比例尺 public void AddScalebar(AxPageLayoutControl axPageLayout) { //删除已经存在的比例尺 IElement pelement = axPageLayout.FindElementByName("AlternatingScaleBar"); if (pelement != null) { axPageLayout.ActiveView.GraphicsContainer.DeleteElement(pelement); } IGraphicsContainer container = axPageLayout.PageLayout as IGraphicsContainer; IActiveView activeView = axPageLayout.PageLayout as IActiveView; // 获得MapFrame IFrameElement frameElement = container.FindFrame(activeView.FocusMap); IMapFrame mapFrame = frameElement as IMapFrame; //根据MapSurround的uid,创建相应的MapSurroundFrame和MapSurround UID uid = new UIDClass(); uid.Value = "esriCarto.AlternatingScaleBar"; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null); //设置MapSurroundFrame中比例尺的样式 IMapSurround mapSurround = mapSurroundFrame.MapSurround; IScaleBar markerScaleBar = ((IScaleBar)mapSurround); markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow; markerScaleBar.UseMapSettings(); //QI,确定mapSurroundFrame的位置 IElement element = mapSurroundFrame as IElement; IEnvelope envelope = new EnvelopeClass(); double x = 12; double y = 5; envelope.PutCoords(x, y, x + 1, y + 1); element.Geometry = envelope; //使用IGraphicsContainer接口添加显示 container.AddElement(element, 0); activeView.Refresh(); }
public static void AddScalebar(AxPageLayoutControl pageLayoutControl, IEnvelope envelope) { IUID uid = new UIDClass() { Value = "esriCarto.AlternatingScaleBar" }; IFrameElement frameElement = (pageLayoutControl.PageLayout as IGraphicsContainer) .FindFrame(pageLayoutControl.ActiveView.FocusMap); IMapFrame mapFrame = frameElement as IMapFrame; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as UID, null); // Dynamic Cast IElement element = mapSurroundFrame as IElement; // Dynamic Cast element.Geometry = envelope; element.Activate(pageLayoutControl.ActiveView.ScreenDisplay); (pageLayoutControl.PageLayout as IGraphicsContainer).AddElement(element, 0); IMapSurround mapSurround = mapSurroundFrame.MapSurround; IScaleBar markerScaleBar = (IScaleBar)(mapSurround); markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow; markerScaleBar.UseMapSettings(); }
public void AddScalebar(IPageLayout pageLayout, IMap map, double posX, double posY, double division, string strMapUnits, short srtDivisions) { try { if (pageLayout == null || map == null) { return; } IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(posX - (division * 2), posY, posX, posY + (division * 0.5)); // Specify the location and size of the scalebar ESRI.ArcGIS.esriSystem.IUID uid = new ESRI.ArcGIS.esriSystem.UIDClass(); uid.Value = "esriCarto.AlternatingScaleBar"; // Create a Surround. Set the geometry of the MapSurroundFrame to give it a location // Activate it and add it to the PageLayout's graphics container IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer; // Dynamic Cast IActiveView activeView = pageLayout as IActiveView; // Dynamic Cast IFrameElement frameElement = graphicsContainer.FindFrame(map); IMapFrame mapFrame = frameElement as IMapFrame; // Dynamic Cast IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uid as ESRI.ArcGIS.esriSystem.UID, null); // Dynamic Cast IElement element = mapSurroundFrame as IElement; // Dynamic Cast element.Geometry = envelope; element.Activate(activeView.ScreenDisplay); graphicsContainer.AddElement(element, 0); IMapSurround mapSurround = mapSurroundFrame.MapSurround; IScaleBar markerScaleBar = ((IScaleBar)(mapSurround)); markerScaleBar.LabelPosition = esriVertPosEnum.esriBelow; markerScaleBar.UseMapSettings(); markerScaleBar.Divisions = srtDivisions; markerScaleBar.DivisionsBeforeZero = 0; markerScaleBar.Subdivisions = 0; markerScaleBar.LabelFrequency = esriScaleBarFrequency.esriScaleBarMajorDivisions; if (strMapUnits == "Feet") { markerScaleBar.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriFeet; } //Default Settings else if (strMapUnits == "Miles") { markerScaleBar.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriMiles; } else if (strMapUnits == "Meters") { markerScaleBar.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriMeters; } else if (strMapUnits == "Kilometers") { markerScaleBar.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriKilometers; } else { return; } } catch (Exception ex) { frmErrorLog pfrmErrorLog = new frmErrorLog(); pfrmErrorLog.ex = ex; pfrmErrorLog.ShowDialog(); return; } }
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); } } } }
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; } }