public void add_grid() { activeView = pageLayoutControl.PageLayout as IActiveView; map = activeView.FocusMap; IMapGrid mapGrid; IMeasuredGrid measuredGrid; measuredGrid = new MeasuredGrid() as IMeasuredGrid; mapGrid = measuredGrid as IMapGrid; measuredGrid.FixedOrigin = true; measuredGrid.Units = map.MapUnits; measuredGrid.XIntervalSize = 10; measuredGrid.YIntervalSize = 10; measuredGrid.XOrigin = -180; measuredGrid.YOrigin = -90; IProjectedGrid projectedGrid; projectedGrid = measuredGrid as IProjectedGrid; projectedGrid.SpatialReference = map.SpatialReference; mapGrid.Name = "Measured Grid"; IMapFrame mapFrame; IGraphicsContainer graphicsContainer; graphicsContainer = activeView as IGraphicsContainer; mapFrame = graphicsContainer.FindFrame(map) as IMapFrame; IMapGrids mapGrids = mapFrame as IMapGrids; mapGrids.AddMapGrid(mapGrid); activeView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null); }
public void AddMapGrid() { m_styleSelector = new MapGridSelectorClass(); //Create a style selector and grab holf of the IMapGridSelector interface m_Ok = m_styleSelector.DoModal(m_pagelayoutControl.hWnd); //Display the style selector to the user IGraphicsContainer graphicsContainer = m_pagelayoutControl.GraphicsContainer; //Get the MapFrame IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(m_pagelayoutControl.ActiveView.FocusMap); if (mapFrame == null) { return; } if (m_Ok == true) { IMapGrid m_mapGrid; m_mapGrid = (IMapGrid )m_styleSelector.GetStyle(0);//获得所选的MapGrid的类型; IMapGrids m_mapGrids = mapFrame as IMapGrids; m_mapGrids.ClearMapGrids();//删除原有的地图格网 if (m_mapGrid != null) { m_mapGrids.AddMapGrid(m_mapGrid); //添加地图格网到地图上 } m_pagelayoutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //刷新 } }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add CmdDelGrid.OnClick implementation IGraphicsContainer gc = m_PageLayControl.ActiveView.GraphicsContainer; IMap map = m_PageLayControl.ActiveView.FocusMap; IMapFrame mf = gc.FindFrame(map) as IMapFrame; IMapGrids mgs = mf as IMapGrids; mgs.ClearMapGrids(); m_PageLayControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
public void CreateGrid(IActiveView activeView, IPageLayout pageLayout) { IMapGrid mapGrid = new GraticuleClass(); mapGrid.Name = "Map Grid"; IColor color = new RgbColorClass(); color.RGB = 0XBBBBBB; ICartographicLineSymbol cartographicLineSymbol = new CartographicLineSymbolClass(); cartographicLineSymbol.Cap = esriLineCapStyle.esriLCSButt; cartographicLineSymbol.Color = color; cartographicLineSymbol.Width = 2; mapGrid.LineSymbol = (ILineSymbol)cartographicLineSymbol; mapGrid.Border = null; mapGrid.TickLength = 15; cartographicLineSymbol = new CartographicLineSymbolClass(); cartographicLineSymbol.Cap = esriLineCapStyle.esriLCSButt; cartographicLineSymbol.Color = color; cartographicLineSymbol.Width = 1; mapGrid.TickLineSymbol = (ILineSymbol)cartographicLineSymbol; mapGrid.TickMarkSymbol = null; mapGrid.SubTickCount = 5; mapGrid.SubTickLength = 10; cartographicLineSymbol = new CartographicLineSymbolClass(); cartographicLineSymbol.Cap = esriLineCapStyle.esriLCSButt; cartographicLineSymbol.Color = color; cartographicLineSymbol.Width = 0.2; mapGrid.SubTickLineSymbol = (ILineSymbol)cartographicLineSymbol; IGridLabel gridLabel = mapGrid.LabelFormat; gridLabel.LabelOffset = 15; mapGrid.SetTickVisibility(true, true, true, true); mapGrid.SetSubTickVisibility(true, true, true, true); mapGrid.SetLabelVisibility(true, true, true, true); mapGrid.Visible = true; IMeasuredGrid measuredGrid = mapGrid as IMeasuredGrid; measuredGrid.FixedOrigin = true; measuredGrid.XIntervalSize = 10; measuredGrid.XOrigin = 5; //Shift grid 5 measuredGrid.YIntervalSize = 10; //Parallel interval. measuredGrid.YOrigin = 5; //Shift grid 5 IMap map = activeView.FocusMap; IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer; IFrameElement frameElement = graphicsContainer.FindFrame(map); IMapFrame mapFrame = frameElement as IMapFrame; IMapGrids mapGrids = null; mapGrids = mapFrame as IMapGrids; mapGrids.AddMapGrid(mapGrid); activeView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null); }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { IGraphicsContainer gc = m_PageLayControl.ActiveView.GraphicsContainer; IMap map = m_PageLayControl.ActiveView.FocusMap; IMapFrame mf = gc.FindFrame(map) as IMapFrame; IMapGridFactory ipMapGridFactory = new MeasuredGridFactoryClass(); IMapGrid mg = ipMapGridFactory.Create(mf); IMapGrids mgs = mf as IMapGrids; mgs.AddMapGrid(mg); m_PageLayControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
/// <summary> /// 获取地图格网 /// </summary> /// <param name="layoutControl">布局视图</param> /// <returns></returns> public static IMapGrids GetMapGrids(AxPageLayoutControl layoutControl) { IGraphicsContainer graphicsContainer = layoutControl.PageLayout as IGraphicsContainer; if (graphicsContainer == null) { return(null); } IMap pMap = layoutControl.ActiveView.FocusMap; IFrameElement frameElement = graphicsContainer.FindFrame(pMap); IMapFrame mapFrame = frameElement as IMapFrame; IMapGrids pMapGrids = mapFrame as IMapGrids; return(pMapGrids); }
private void FrmGrids_Load(object sender, EventArgs e) { try { IActiveView pActiveView = m_hookHelper.PageLayout as IActiveView; IMap pMap = pActiveView.FocusMap; IGraphicsContainer pGraphicsContainer = pActiveView as IGraphicsContainer; IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame; MapGrids = pMapFrame as IMapGrids; UpdateGridsListBox(); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 删除已存在格网 /// </summary> /// <param name="pActiveView"></param> public static void DeleteExistMapGrid(IActiveView pActiveView) { IGraphicsContainer graphicsContainer = pActiveView as IGraphicsContainer; if (graphicsContainer == null) { return; } IMap pMap = pActiveView.FocusMap; IFrameElement frameElement = graphicsContainer.FindFrame(pMap); IMapFrame mapFrame = frameElement as IMapFrame; IMapGrids mapGrids = mapFrame as IMapGrids; if (mapGrids == null) { return; } if (mapGrids.MapGridCount > 0) { IMapGrid pMapGrid = mapGrids.MapGrid[0]; mapGrids.DeleteMapGrid(pMapGrid); } pActiveView.PartialRefresh(esriViewDrawPhase.esriViewBackground, null, null); }
public frmMapGridsProperty(IPageLayout ipageLayout_1, IMapGrids imapGrids_1) { this.InitializeComponent(); this.imapGrids_0 = imapGrids_1; this.ipageLayout_0 = ipageLayout_1; }
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; } }