/// <summary> /// 获取数字格式 /// </summary> /// <returns></returns> public static INumericFormat GetNumericFormat() { INumericFormat pNumericFormat = new NumericFormatClass(); pNumericFormat.AlignmentOption = esriNumericAlignmentEnum.esriAlignLeft; pNumericFormat.RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfDecimals; pNumericFormat.RoundingValue = 0; pNumericFormat.ZeroPad = true; return(pNumericFormat); }
public IMapGrid CreateMapGrid(int int_0) { IMapGrid grid = null; switch (int_0) { case 0: grid = new GraticuleClass(); break; case 1: grid = new MeasuredGridClass(); break; case 2: grid = new IndexGridClass(); break; } if (grid == null) { return(null); } grid.SetDefaults(this.m_pMapFrame); grid.LineSymbol = null; IMarkerSymbol symbol = new SimpleMarkerSymbolClass(); (symbol as ISimpleMarkerSymbol).Style = esriSimpleMarkerStyle.esriSMSCross; grid.TickMarkSymbol = symbol; if (grid is IMeasuredGrid) { IFormattedGridLabel label = new FormattedGridLabelClass(); INumericFormat format = new NumericFormatClass { AlignmentOption = esriNumericAlignmentEnum.esriAlignLeft, AlignmentWidth = 0, RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfDecimals, RoundingValue = 3, ShowPlusSign = true, UseSeparator = true, ZeroPad = true }; label.Format = format as INumberFormat; (label as IGridLabel).LabelOffset = 6.0; grid.LabelFormat = label as IGridLabel; IEnvelope mapBounds = this.m_pMapFrame.MapBounds; (grid as IMeasuredGrid).FixedOrigin = true; (grid as IMeasuredGrid).XOrigin = mapBounds.XMin + 500.0; (grid as IMeasuredGrid).YOrigin = mapBounds.YMin + 500.0; grid.SetTickVisibility(false, false, false, false); grid.SetSubTickVisibility(false, false, false, false); } return(grid); }
public void Init() { this.bool_0 = false; if (this.imapGrid_0 != null) { this.btnMainLineStyle.Style = this.imapGrid_0.TickLineSymbol; this.btnSubLineStyle.Style = this.imapGrid_0.SubTickLineSymbol; bool leftVis = false; bool rightVis = false; bool topVis = false; bool bottomVis = false; this.imapGrid_0.QueryTickVisibility(ref leftVis, ref topVis, ref rightVis, ref bottomVis); this.chkTickVisibility.Checked = leftVis; this.btnMainLineStyle.Enabled = leftVis; this.imapGrid_0.QuerySubTickVisibility(ref leftVis, ref topVis, ref rightVis, ref bottomVis); this.chkSubTickVisibility.Checked = leftVis; this.btnSubLineStyle.Enabled = leftVis; this.spinSubTickCount.Enabled = leftVis; this.spinSubTickCount.Value = this.imapGrid_0.SubTickCount; IGridLabel labelFormat = this.imapGrid_0.LabelFormat; this.itextSymbol_0.Font = labelFormat.Font; this.itextSymbol_0.Color = labelFormat.Color; this.itextSymbol_0.Text = labelFormat.DisplayName; this.styleButton1.Style = this.itextSymbol_0; if (labelFormat is IMixedFontGridLabel) { (labelFormat as IMixedFontGridLabel).NumGroupedDigits = 2; this.imapGrid_0.LabelFormat = labelFormat; } if (labelFormat is IFormattedGridLabel) { INumericFormat format = new NumericFormatClass { RoundingValue = 0 }; (labelFormat as IFormattedGridLabel).Format = format as INumberFormat; this.imapGrid_0.LabelFormat = labelFormat; } } this.bool_0 = true; }
private void button_dress_Click(object sender, EventArgs e) { //获取axPageLayoutControl1的图形容器 IGraphicsContainer graphicsContainer = axPageLayoutControl1.GraphicsContainer; //获取axPageLayoutControl1空间里面显示的地图图层 IMapFrame mapFrame = (IMapFrame)graphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap); if (mapFrame == null) { return; } //--------------创建图例------------ UID uID = new UIDClass(); //创建UID作为该图例的唯一标识符,方便创建之后进行删除、移动等操作 uID.Value = "esriCarto.Legend"; IMapSurroundFrame mapSurroundFrame = mapFrame.CreateSurroundFrame(uID, null); if (mapSurroundFrame == null) { return; } if (mapSurroundFrame.MapSurround == null) { return; } mapSurroundFrame.MapSurround.Name = "图例"; IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(16, 2, 18, 7);//设置图例摆放位置(原点在axPageLayoutControl左下角) IElement element = (IElement)mapSurroundFrame; element.Geometry = envelope; //将图例转化为几何要素添加到axPageLayoutControl1,并刷新页面显示 axPageLayoutControl1.AddElement(element, Type.Missing, Type.Missing, "Legend", 0); axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //-----------设置指北针-------- IMapSurround pMapSurround; INorthArrow pNorthArrow; pNorthArrow = new MarkerNorthArrowClass();//创建指北针的实例 pMapSurround = pNorthArrow; pMapSurround.Name = "NorthArrow"; //定义UID UID uid = new UIDClass(); uid.Value = "esriCarto.MarkerNorthArrow"; //定义MapSurroundFrame对象 IMapSurroundFrame pMapSurroundFrame = mapFrame.CreateSurroundFrame(uid, null); pMapSurroundFrame.MapSurround = pMapSurround; IElement pDeletElement = axPageLayoutControl1.FindElementByName("NorthArrow");//获取PageLayout中的图例元素 if (pDeletElement != null) { graphicsContainer.DeleteElement(pDeletElement); //如果已经存在指北针,删除已经存在的指北针 } //定义Envelope设置Element摆放的位置 IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.PutCoords(16, 24, 21, 32); IElement pElement = pMapSurroundFrame as IElement; pElement.Geometry = pEnvelope; graphicsContainer.AddElement(pElement, 0); //刷新axPageLayoutControl1的内容 axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //-----------设置比例尺------------ IActiveView pActiveView = axPageLayoutControl1.PageLayout as IActiveView; IMap pMap = pActiveView.FocusMap as IMap; IGraphicsContainer pGraphicsContainer = pActiveView as IGraphicsContainer; IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame; //IMapSurround pMapSurround; //设置比例尺样式 IScaleBar pScaleBar = new ScaleLineClass(); pScaleBar.Units = esriUnits.esriKilometers; pScaleBar.Divisions = 4; pScaleBar.Subdivisions = 3; pScaleBar.DivisionsBeforeZero = 0; pScaleBar.UnitLabel = "km"; pScaleBar.LabelPosition = esriVertPosEnum.esriBelow; pScaleBar.LabelGap = 3.6; pScaleBar.LabelFrequency = esriScaleBarFrequency.esriScaleBarDivisionsAndFirstMidpoint; pScaleBar.LabelPosition = esriVertPosEnum.esriBelow; ITextSymbol pTextsymbol = new TextSymbolClass(); pTextsymbol.Size = 1; stdole.StdFont pFont = new stdole.StdFont(); pFont.Size = 3; pFont.Name = "Arial"; pTextsymbol.Font = pFont as stdole.IFontDisp; pTextsymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; pScaleBar.UnitLabelSymbol = pTextsymbol; pScaleBar.LabelSymbol = pTextsymbol; INumericFormat pNumericFormat = new NumericFormatClass(); pNumericFormat.AlignmentWidth = 0; pNumericFormat.RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfSignificantDigits; pNumericFormat.RoundingValue = 0; pNumericFormat.UseSeparator = true; pNumericFormat.ShowPlusSign = false; //定义UID pMapSurround = pScaleBar; pMapSurround.Name = "ScaleBar"; // UID uid = new UIDClass(); uid.Value = "esriCarto.ScaleLine"; //定义MapSurroundFrame对象IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(uid, null); pMapSurroundFrame.MapSurround = pMapSurround; //定义Envelope设置Element摆放的位置 //IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.PutCoords(8, 2, 14, 4); //IElement pElement = pMapSurroundFrame as IElement; pElement.Geometry = pEnvelope; //IElement pDeletElement = axPageLayoutControl1.FindElementByName("ScaleBar"); //获取PageLayout中的比例尺元素 if (pDeletElement != null) { pGraphicsContainer.DeleteElement(pDeletElement); //如果已经存在比例尺,删除已经存在的比例尺 } pGraphicsContainer.AddElement(pElement, 0); //刷新axPageLayoutControl1的内容 axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); //---------------添加标题------------- //IGraphicsContainer graphicsContainer = axPageStation.PageLayout as IGraphicsContainer; //IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(-14, 26, 35, 26); IRgbColor pColor = new RgbColorClass() { Red = 0, Blue = 0, Green = 0 }; pFont.Name = "宋体"; pFont.Bold = true; ITextSymbol pTextSymbol = new TextSymbolClass() { Color = pColor, //Font = pFont, Size = 30 }; ITextElement pTextElement = new TextElementClass() { Symbol = pTextSymbol, ScaleText = true, Text = "盗墓难度专题图" }; element = pTextElement as ESRI.ArcGIS.Carto.IElement; element.Geometry = envelope; graphicsContainer.AddElement(element, 0); axPageLayoutControl1.Refresh(); }
private void 添加比例尺ToolStripMenuItem_Click(object sender, EventArgs e) { IActiveView pActiveView = axPageLayoutControl1.PageLayout as IActiveView; IMap pMap = pActiveView.FocusMap as IMap; IGraphicsContainer pGraphicsContainer = pActiveView as IGraphicsContainer; IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame; IMapSurround pMapSurround; //设置比例尺样式 IScaleBar pScaleBar = new ScaleLineClass(); pScaleBar.Units = esriUnits.esriKilometers; pScaleBar.Divisions = 4; pScaleBar.Subdivisions = 3; pScaleBar.DivisionsBeforeZero = 0; pScaleBar.UnitLabel = "km"; pScaleBar.LabelPosition = esriVertPosEnum.esriBelow; pScaleBar.LabelGap = 3.6; pScaleBar.LabelFrequency = esriScaleBarFrequency.esriScaleBarDivisionsAndFirstMidpoint; pScaleBar.LabelPosition = esriVertPosEnum.esriBelow; ITextSymbol pTextsymbol = new TextSymbolClass(); pTextsymbol.Size = 1; stdole.StdFont pFont = new stdole.StdFont(); pFont.Size = 3; pFont.Name = "Arial"; pTextsymbol.Font = pFont as stdole.IFontDisp; pTextsymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; pScaleBar.UnitLabelSymbol = pTextsymbol; pScaleBar.LabelSymbol = pTextsymbol; INumericFormat pNumericFormat = new NumericFormatClass(); pNumericFormat.AlignmentWidth = 0; pNumericFormat.RoundingOption = esriRoundingOptionEnum.esriRoundNumberOfSignificantDigits; pNumericFormat.RoundingValue = 0; pNumericFormat.UseSeparator = true; pNumericFormat.ShowPlusSign = false; //定义UID pMapSurround = pScaleBar; pMapSurround.Name = "ScaleBar"; UID uid = new UIDClass(); uid.Value = "esriCarto.ScaleLine"; //定义MapSurroundFrame对象 IMapSurroundFrame pMapSurroundFrame = pMapFrame.CreateSurroundFrame(uid, null); pMapSurroundFrame.MapSurround = pMapSurround; //定义Envelope设置Element摆放的位置 IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.PutCoords(8, 5, 14, 7); IElement pElement = pMapSurroundFrame as IElement; pElement.Geometry = pEnvelope; IElement pDeletElement = axPageLayoutControl1.FindElementByName("ScaleBar");//获取PageLayout中的比例尺元素 if (pDeletElement != null) { pGraphicsContainer.DeleteElement(pDeletElement); //如果已经存在比例尺,删除已经存在的比例尺 } pGraphicsContainer.AddElement(pElement, 0); //刷新axPageLayoutControl1的内容 axPageLayoutControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }