private void LayerAnnotation(IGeoFeatureLayer pGeoFeatLyr, string annoField) { IGeoFeatureLayer pGeoFeatLayer; pGeoFeatLayer = pGeoFeatLyr; IAnnotateLayerPropertiesCollection pAnnoProps; pAnnoProps = pGeoFeatLyr.AnnotationProperties; pAnnoProps.Clear(); IAnnotateLayerProperties pAnnoLayerProps; ILabelEngineLayerProperties pLabelEngine; ILineLabelPosition pPosition; ILineLabelPlacementPriorities pPlacement; IBasicOverposterLayerProperties pBasic; //'定义标注的字体 ITextSymbol pTextSyl; pTextSyl = new TextSymbol(); stdole.IFontDisp pFont; pFont = new stdole.StdFont() as stdole.IFontDisp; pFont.Name = "仿宋"; pFont.Size = 12; pFont.Bold = true; pTextSyl.Font = pFont; IRgbColor pcolor = new RgbColorClass(); pcolor.Red = 255; pcolor.Green = 10; pcolor.Blue = 20; pTextSyl.Color = pcolor; pPosition = new LineLabelPosition(); pPosition.Parallel = false; pPosition.Perpendicular = true; pPlacement = new LineLabelPlacementPriorities(); pBasic = new BasicOverposterLayerProperties(); pBasic.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolyline; pBasic.LineLabelPlacementPriorities = pPlacement; pBasic.LineLabelPosition = pPosition; pLabelEngine = new LabelEngineLayerProperties() as ILabelEngineLayerProperties; pLabelEngine.Symbol = pTextSyl; pLabelEngine.BasicOverposterLayerProperties = pBasic; //field的形式必须是[fieldname] pLabelEngine.Expression = annoField; pAnnoLayerProps = (IAnnotateLayerProperties)pLabelEngine; pAnnoProps.Add(pAnnoLayerProps); pGeoFeatLyr.DisplayAnnotation = true; axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
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(); }