public override IElement GetElement(IPageLayout ipageLayout_0) { 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 INorthArrow) { INorthArrow mapSurround = (base.m_pElement as IMapSurroundFrame).MapSurround as INorthArrow; if (mapSurround.Map != (ipageLayout_0 as IActiveView).FocusMap) { 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); }
//复制指北针 private void CopyNorthArrow(INorthArrow srcArrow, INorthArrow destArrow) { IClone pSrc = srcArrow as IClone; IClone pDest = pSrc.Clone(); destArrow = pDest as INorthArrow; }
/// <summary> /// 添加指北针 /// </summary> /// <param name="layoutControl">布局视图</param> /// <param name="pEnv">矩形框</param> /// <param name="pStyleGalleryItem">指北针样式</param> public static void AddNorthArrow(AxPageLayoutControl layoutControl, IEnvelope pEnv, IStyleGalleryItem pStyleGalleryItem) { if (pStyleGalleryItem == null) { return; } IGraphicsContainer pGraphicsContainer = layoutControl.PageLayout as IGraphicsContainer; if (pGraphicsContainer == null) { return; } IMap pMap = layoutControl.ActiveView.FocusMap; IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame; IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass(); pMapSurroundFrame.MapFrame = pMapFrame; //删除已经存在的指北针 MappingHelper.DeleteElementByName(layoutControl, "North Arrow"); INorthArrow pNorthArrow = pStyleGalleryItem.Item as INorthArrow; if (pNorthArrow != null) { pNorthArrow.Size = pEnv.Width * 50; pMapSurroundFrame.MapSurround = pNorthArrow;//根据用户的选取,获取相应的MapSurround } IElement pElement = (IElement)pMapSurroundFrame; pElement.Geometry = pEnv; //添加元素 MappingHelper.AddElementWithName(pGraphicsContainer, pElement, "North Arrow"); }
public void SetObjects(object @object) { this.m_pOldNorthArrow = @object as INorthArrow; if (this.m_pOldNorthArrow != null) { this.m_pNorthArrow = (this.m_pOldNorthArrow as IClone).Clone() as INorthArrow; } }
public NorthArrowPropertyFr(IElement pEle) { InitializeComponent(); m_pElement = pEle; IMapSurroundFrame pSurround = pEle as IMapSurroundFrame; m_northArrow = pSurround.MapSurround as INorthArrow; }
public void SetObjects(object object_0) { this.imapSurroundFrame_0 = object_0 as IMapSurroundFrame; if (this.imapSurroundFrame_0 != null) { this.inorthArrow_0 = (this.imapSurroundFrame_0.MapSurround as IClone).Clone() as INorthArrow; } }
public void SetObjects(object object_0) { this.mapTemplateElement_0 = object_0 as MapTemplateElement; this.imapSurroundFrame_0 = this.mapTemplateElement_0.Element as IMapSurroundFrame; if (this.imapSurroundFrame_0 != null) { this.inorthArrow_0 = (this.imapSurroundFrame_0.MapSurround as IClone).Clone() as INorthArrow; } }
//大小设置 private void NorthArrowSize_ValueChanged(object sender, EventArgs e) { if (m_pStyleGalleryItem != null && !string.IsNullOrEmpty(NorthArrowSize.Text)) { INorthArrow pNorthArrow = m_pStyleGalleryItem.Item as INorthArrow; pNorthArrow.Size = double.Parse(this.NorthArrowSize.Text); PreviewImage(); } }
public void AddNorthArrow() { //添加指北针 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.MarkerNorthArrow"; //Create a MapSurroundFrame from the MapFrame IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null); if (mapSurroundFrame == null) { return; } if (mapSurroundFrame.MapSurround == null) { return; } IEnvelope m_envelop = new EnvelopeClass(); m_envelop.PutCoords(15, 15, 20, 20); INorthArrow northArrow = null; frmNorthArrowSymbol frmNorthArrow = new frmNorthArrowSymbol(); IStyleGalleryItem pstyGallertItem = frmNorthArrow.GetItem(ESRI.ArcGIS.Controls.esriSymbologyStyleClass.esriStyleClassNorthArrows);; if (pstyGallertItem != null) { northArrow = (INorthArrow)pstyGallertItem.Item; northArrow.Map = this.m_pagelayoutControl.ActiveView.FocusMap; northArrow.CalibrationAngle = frmNorthArrow.Angle(); } else { return; } IMapSurround m_mapSurround; m_mapSurround = (IMapSurround)northArrow; mapSurroundFrame.MapSurround = m_mapSurround; IElement m_element = (IElement)mapSurroundFrame; m_element.Geometry = m_envelop; m_pagelayoutControl.AddElement(m_element, Type.Missing, Type.Missing, "NorthArrow", 2); m_pagelayoutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
//调用指北针样式 private void btNAStyle_Click(object sender, EventArgs e) { //记录原位置 IEnvelope pEnv = new EnvelopeClass(); pEnv = m_pElement.Geometry.Envelope; //删除原有对象 m_pGraphicsContainer.DeleteElement(m_pElement); //Create the form with the SymbologyControl FrmNorthArrow symbolForm = new FrmNorthArrow(m_pNorthArrow); //Get the IStyleGalleryItem if (symbolForm.ShowDialog() != DialogResult.OK) { return; } IStyleGalleryItem styleGalleryItem = symbolForm.GetItem(); //Release the form symbolForm.Dispose(); if (styleGalleryItem == null) { return; } IMapFrame pMapFrame = m_pGraphicsContainer.FindFrame(m_hookHelper.ActiveView.FocusMap) as IMapFrame; if (pMapFrame == null) { return; } //Create a map surround frame IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass(); //Set its map frame and map surround pMapSurroundFrame.MapFrame = pMapFrame; pMapSurroundFrame.MapSurround = (IMapSurround)styleGalleryItem.Item; m_pElement = (IElement)pMapSurroundFrame; m_pElement.Geometry = (IGeometry)pEnv; //Add the element to the graphics container m_pGraphicsContainer.AddElement(m_pElement, 0); m_pMapFrame = m_pElement as IMapSurroundFrame; m_pNorthArrow = m_pMapFrame.MapSurround as INorthArrow; UpdateUI(true); //Refresh m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pMapSurroundFrame, null); }
//颜色设置 private void colorNorthArrow_SelectedColorChanged(object sender, EventArgs e) { if (m_pStyleGalleryItem == null) { MessageBox.Show("请选择指北针样式", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } INorthArrow pNorthArrow = m_pStyleGalleryItem.Item as INorthArrow; pNorthArrow.Color = ClsGDBDataCommon.ColorToIColor(colorNorthArrow.SelectedColor); PreviewImage(); }
//选择样式 private void axSymbologyControl_OnItemSelected(object sender, ISymbologyControlEvents_OnItemSelectedEvent e) { //选择样式 m_pStyleGalleryItem = (IStyleGalleryItem)e.styleGalleryItem; if (m_pStyleGalleryItem != null) { INorthArrow pNorthArrow = m_pStyleGalleryItem.Item as INorthArrow; NorthArrowAngle.Text = pNorthArrow.Angle.ToString(); this.NorthArrowSize.Value = pNorthArrow.Size; IColor pNorthArrowColor = pNorthArrow.Color; Color pColor = ColorTranslator.FromOle(pNorthArrowColor.RGB); colorNorthArrow.SelectedColor = pColor; } PreviewImage(); }
public FrmNorthArrwoAttribute(string[] symbolstyle, IElement element, IGraphicsContainer GraphicsContainer, IHookHelper hookHelper) { InitializeComponent(); this.EnableGlass = false; m_pElement = element; //SymbolStyle = symbolstyle; //pElement = Element; m_pGraphicsContainer = GraphicsContainer; m_hookHelper = hookHelper; //pOrielement = Element; m_pNorthArrowOrg = new MarkerNorthArrowClass(); m_pMapFrameOrg = new MapSurroundFrameClass(); m_pMapFrame = new MapSurroundFrameClass(); //得到当前对象 m_pMapFrame = m_pElement as IMapSurroundFrame; m_pNorthArrow = m_pMapFrame.MapSurround as INorthArrow; //拷贝个对象 CopyMapSurroundFrame(m_pMapFrame, m_pMapFrameOrg); CopyNorthArrow(m_pNorthArrow, m_pNorthArrowOrg); }
private void btnNorthArrorSelector_Click(object sender, EventArgs e) { try { frmSymbolSelector selector = new frmSymbolSelector(); if (selector != null) { selector.SetStyleGallery(this.istyleGallery_0); selector.SetSymbol(this.inorthArrow_0); if (selector.ShowDialog() == DialogResult.OK) { this.inorthArrow_0 = selector.GetSymbol() as INorthArrow; this.bool_0 = false; this.method_1(); this.bool_0 = true; this.method_0(); } } } catch { } }
private void btnNorthArrorSelector_Click(object sender, EventArgs e) { try { frmSymbolSelector selector = new frmSymbolSelector(); if (selector != null) { selector.SetStyleGallery(this.m_pSG); selector.SetSymbol(this.m_pNorthArrow); if (selector.ShowDialog() == DialogResult.OK) { this.m_pNorthArrow = selector.GetSymbol() as INorthArrow; this.m_CanDo = false; this.Init(); this.m_CanDo = true; this.ValueChanged(); } } } catch { } }
private void Btn_AddNorthArrow_Click(object sender, EventArgs e) { FormSymbologySelector formSymbologySelector = new FormSymbologySelector(RequestResponder, esriSymbologyStyleClass.esriStyleClassNorthArrows); formSymbologySelector.ShowDialog(); IGraphicsContainer pGraphicsContainer = Ctrl_PageLayout.ActiveView.GraphicsContainer; IMapFrame pMapFrame = (IMapFrame)pGraphicsContainer.FindFrame(Ctrl_PageLayout.ActiveView.FocusMap); if (pMapFrame == null) { return; } UID uid = new UIDClass { Value = "esriCarto.MarkerNorthArrow" }; IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(uid, null); if (pMapSurroundFrame == null || pMapSurroundFrame.MapSurround == null) { return; } INorthArrow pNorthArrow = m_pStyleGalleryItem.Item as INorthArrow; pNorthArrow.Size = m_pEnvelopDrawed.Width * 100; pMapSurroundFrame.MapSurround = pNorthArrow; IElement pElement = (IElement)pMapSurroundFrame; pElement.Geometry = m_pEnvelopDrawed; if (m_pNorthArrowElement != null) { Ctrl_PageLayout.ActiveView.GraphicsContainer.DeleteElement(m_pNorthArrowElement); } Ctrl_PageLayout.ActiveView.GraphicsContainer.AddElement(pElement, 0); m_pNorthArrowElement = pElement; Ctrl_PageLayout.ActiveView.PartialRefresh(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; } }
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); } } } }
public FrmNorthArrow(INorthArrow northArrow) { InitializeComponent(); this.EnableGlass = false; m_pNorthArrow = northArrow; }