public static IElement CreateTextElement(IPoint point, IColor color, string text, IFontConfig fontConfig) { stdole.IFontDisp fontDisp = new StdFontClass() as IFontDisp; fontDisp.Name = fontConfig.Font.Name; fontDisp.Size = (decimal)fontConfig.Font.Size; fontDisp.Italic = fontConfig.Font.Italic; fontDisp.Underline = fontConfig.Font.Underline; fontDisp.Bold = fontConfig.Font.Bold; fontDisp.Strikethrough = fontConfig.Font.Strikeout; ITextSymbol textSymbol = new TextSymbolClass(); textSymbol.Font = fontDisp; textSymbol.Color = color; textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter; textSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter; ITextElement textElement = new TextElementClass(); textElement.Symbol = textSymbol; textElement.ScaleText = true; textElement.Text = text; IElement element = textElement as IElement; element.Geometry = point; return(element); }
/// <summary> /// 获取字体格式 /// </summary> /// <param name="fontType">类型</param> /// <param name="fontSize">大小</param> /// <param name="isBold">是否加粗</param> /// <returns>字体格式</returns> public static StdFont GetFont(string fontType = "宋体", decimal fontSize = 18, bool isBold = false) { StdFont myFont = new StdFontClass(); myFont.Name = fontType; myFont.Size = fontSize; myFont.Bold = isBold; return(myFont); }
public static IFontDisp CreateFont(string pFontName, float pSize) { StdFontClass class2 = new StdFontClass(); class2.Name = pFontName; class2.Size = Convert.ToDecimal(pSize); class2.Bold = false; class2.Italic = false; class2.Underline = false; class2.Strikethrough = false; return (class2 as IFontDisp); }
public static IFontDisp CreateFont(string pFontName, float pSize, bool pBold, bool pItalic, bool pUnderline, bool pStroke) { StdFontClass class2 = new StdFontClass(); class2.Name = pFontName; class2.Size = Convert.ToDecimal(pSize); class2.Bold = pBold; class2.Italic = pItalic; class2.Underline = pUnderline; class2.Strikethrough = pStroke; return (class2 as IFontDisp); }
public static IFontDisp CreateFont(string pFontName, float pSize) { StdFontClass class2 = new StdFontClass(); class2.Name = pFontName; class2.Size = Convert.ToDecimal(pSize); class2.Bold = false; class2.Italic = false; class2.Underline = false; class2.Strikethrough = false; return(class2 as IFontDisp); }
public static IFontDisp CreateFont(string pFontName, float pSize, bool pBold, bool pItalic, bool pUnderline, bool pStroke) { StdFontClass class2 = new StdFontClass(); class2.Name = pFontName; class2.Size = Convert.ToDecimal(pSize); class2.Bold = pBold; class2.Italic = pItalic; class2.Underline = pUnderline; class2.Strikethrough = pStroke; return(class2 as IFontDisp); }
private void updateFromUI() { ITextSymbol pTmpTextSymbol = new TextSymbolClass(); //字体 IFontDisp pFont = new StdFontClass() as IFontDisp; pFont.Name = this.cmbBoxFontName.Text; pFont.Size = decimal.Parse(this.FontSize.Text); pFont.Bold = this.toolBtnBold.Checked; pFont.Italic = this.toolBtnIntend.Checked; pFont.Underline = this.toolBtnUnderline.Checked; pFont.Strikethrough = this.toolBtnStrikethrough.Checked; pTmpTextSymbol.Font = pFont; //颜色 if (this.FontColor.SelectedColor != null) { pTmpTextSymbol.Color = ClsGDBDataCommon.ColorToIColor(FontColor.SelectedColor); } //角度 pTmpTextSymbol.Angle = double.Parse(this.TextAngle.Text); //字体对齐方式 if (this.toolBtnLeft.Checked == true) { pTmpTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; } else if (this.toolBtnCenter.Checked == true) { pTmpTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter; } else if (this.toolBtnRight.Checked == true) { pTmpTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight; } else if (this.toolBtnBoth.Checked == true) { pTmpTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull; } //字符间距、行间距 IFormattedTextSymbol pFormattedTextSymbol = pTmpTextSymbol as IFormattedTextSymbol; pFormattedTextSymbol.CharacterSpacing = dbiCharSpacing.Value; pFormattedTextSymbol.Leading = dbiLineLeading.Value; pTextElement.Symbol = pTmpTextSymbol; pTextElement.Text = this.txtAddText.Text; }
/// <summary> /// 配置指定的注记要素 /// </summary> /// <param name="feature">要修改的注记要素</param> /// <param name="pointGeometry">注记要素坐标</param> /// <param name="text">注记内容</param> /// <param name="fontSize"></param> /// <param name="verticalAlignment"></param> /// <param name="horizontalAlignment"></param> public void ConfigAnnotation(IFeature feature, IGeometry pointGeometry, string text, int fontSize, esriTextVerticalAlignment verticalAlignment, esriTextHorizontalAlignment horizontalAlignment) { IFontDisp font = new StdFontClass() as IFontDisp; font.Name = "宋体"; font.Bold = true; IFormattedTextSymbol formattedTextSymbol = new TextSymbolClass(); formattedTextSymbol.Font = font; formattedTextSymbol.Size = fontSize; formattedTextSymbol.VerticalAlignment = verticalAlignment; formattedTextSymbol.HorizontalAlignment = horizontalAlignment; formattedTextSymbol.Angle = 0; formattedTextSymbol.CharacterSpacing = 10; formattedTextSymbol.CharacterWidth = 80; formattedTextSymbol.FlipAngle = 90; formattedTextSymbol.Leading = 0; formattedTextSymbol.WordSpacing = 10; formattedTextSymbol.Text = text; IColor rgb = new RgbColorClass(); rgb.RGB = 15354; formattedTextSymbol.Color = rgb; ITextElement textElement = new TextElementClass(); textElement.Symbol = formattedTextSymbol; textElement.Text = text; IElement element = textElement as IElement; element.Geometry = pointGeometry; element.Geometry.Envelope.Width = 0.06; IAnnotationFeature2 annotationFeature2 = feature as IAnnotationFeature2; try { // annotationFeature2.Annotation.Geometry = pointGeometry; annotationFeature2.Annotation = element; annotationFeature2.Status = esriAnnotationStatus.esriAnnoStatusPlaced; feature.Store(); } catch { } }
//插入标题 public void InsertTitle() { this.SetCurrentTool(); IActiveView pAV; IGraphicsContainer pGraphicsContainer; IPoint pPoint; ITextElement pTextElement; IElement pElement; ITextSymbol pTextSymbol; IRgbColor pColor; pAV = m_pageLayoutControl.ActiveView; pGraphicsContainer = m_pageLayoutControl.GraphicsContainer; pTextElement = new TextElementClass(); IFontDisp pFont = new StdFontClass() as IFontDisp; pFont.Bold = true; pFont.Name = "宋体"; pFont.Size = 23; pColor = new RgbColorClass(); pColor.Red = 0; pColor.Blue = 0; pColor.Green = 0; pTextSymbol = new TextSymbolClass(); pTextSymbol.Color = (IColor)pColor; pTextSymbol.Font = pFont; pTextElement.Text = "新建图名"; pTextElement.Symbol = pTextSymbol; pPoint = new PointClass(); pPoint.X = 9; pPoint.Y = 25; pElement = (IElement)pTextElement; pElement.Geometry = (IGeometry)pPoint; pGraphicsContainer.AddElement(pElement, 0); pAV.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
/// <summary> /// 添加文本 /// </summary> /// <param name="axPageLayoutControl1">目标PageLayoutControl的Name属性</param> /// <param name="fontsize">字体尺寸</param> /// <param name="thimaticMapName">图名</param> private void AddTextElement(AxPageLayoutControl axPageLayoutControl1, decimal fontsize, string thimaticMapName) { //创建PageLayout对象 IPageLayout pPageLayout = axPageLayoutControl1.PageLayout; //将PageLayout强转成IActiveView IActiveView pAV = (IActiveView)pPageLayout; //将PageLayout强转成IGraphicsContainer IGraphicsContainer graphicsContainer = (IGraphicsContainer)pPageLayout; //实例化文本元素 ITextElement pTextElement = new TextElementClass(); //实例化字体元素 IFontDisp pFont = new StdFontClass() as IFontDisp; pFont.Bold = true; pFont.Name = "宋体"; pFont.Size = fontsize; //实例化IRgbColor IRgbColor pColor = new RgbColorClass(); pColor.Red = 0; pColor.Green = 0; pColor.Blue = 0; //实例化文本符号 ITextSymbol pTextSymbol = new TextSymbolClass(); pTextSymbol.Color = (IColor)pColor; pTextSymbol.Font = pFont; //赋值元素文本和符号 pTextElement.Text = thimaticMapName; pTextElement.Symbol = pTextSymbol; //实例化一个点 IPoint pPoint = new PointClass(); pPoint.X = 1; pPoint.Y = 1; //实例化一个元素 IElement pElement = (IElement)pTextElement; pElement.Geometry = (IGeometry)pPoint; graphicsContainer.AddElement(pElement, 0); //真正实现部分刷新 pAV.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
private ITextSymbol GetDefaultTextSymbol() { try { ITextSymbol symbol = null; symbol = new TextSymbolClass { Angle = double.Parse(UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "Angle")), Color = this.DefaultFontColor, Size = double.Parse(UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "Size")), Text = UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "Text") }; if (UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "HorizontalAlignment") == esriTextHorizontalAlignment.esriTHACenter.ToString()) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter; } else if (UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "HorizontalAlignment") == esriTextHorizontalAlignment.esriTHAFull.ToString()) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull; } else if (UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "HorizontalAlignment") == esriTextHorizontalAlignment.esriTHALeft.ToString()) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; } else if (UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "HorizontalAlignment") == esriTextHorizontalAlignment.esriTHARight.ToString()) { symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight; } if (UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "HorizontalAlignment") == esriTextVerticalAlignment.esriTVABaseline.ToString()) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABaseline; } else if (UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "HorizontalAlignment") == esriTextVerticalAlignment.esriTVABottom.ToString()) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom; } else if (UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "HorizontalAlignment") == esriTextVerticalAlignment.esriTVACenter.ToString()) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter; } else if (UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "HorizontalAlignment") == esriTextVerticalAlignment.esriTVATop.ToString()) { symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop; } IFontDisp font = null; if (symbol.Font == null) { font = new StdFontClass() as IFontDisp; } else { font = symbol.Font; } font.Name = UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "FontName"); font.Size = decimal.Parse(UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "FontSize")); font.Bold = bool.Parse(UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "FontBold")); font.Italic = bool.Parse(UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "FontItalic")); font.Underline = bool.Parse(UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "FontUnderline")); font.Strikethrough = bool.Parse(UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "FontStrikethrough")); symbol.Font = font; IFormattedTextSymbol symbol2 = null; symbol2 = symbol as IFormattedTextSymbol; if (esriTextDirection.esriTDAngle.ToString() == UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "Direction")) { symbol2.Direction = esriTextDirection.esriTDAngle; } else if (esriTextDirection.esriTDHorizontal.ToString() == UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "Direction")) { symbol2.Direction = esriTextDirection.esriTDHorizontal; } else if (esriTextDirection.esriTDVertical.ToString() == UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "Direction")) { symbol2.Direction = esriTextDirection.esriTDVertical; } ISimpleTextSymbol symbol3 = null; symbol3 = symbol as ISimpleTextSymbol; symbol3.XOffset = double.Parse(UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "XOffset")); symbol3.YOffset = double.Parse(UtilFactory.GetConfigOpt().GetConfigValue2("TextSymbol", "YOffset")); return(symbol); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.SymbolFun", "GetDefaultTextSymbol", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(null); } }
// ========================================================================= // Event handlers // ========================================================================= private void AvEventsAfterDraw(IDisplay display, esriViewDrawPhase phase) { try { if ((_measurement != null) && (_point != null)) { if ((phase == esriViewDrawPhase.esriViewForeground) && _measurement.IsOpen && _measurement.DrawPoint && (!double.IsNaN(_point.X)) && (!double.IsNaN(_point.Y))) { GsExtension extension = GsExtension.GetExtension(); if (extension.InsideScale()) { // ReSharper disable UseIndexedProperty // ReSharper disable CSharpWarnings::CS0612 display.StartDrawing(display.hDC, (short)esriScreenCache.esriNoScreenCache); IDisplayTransformation dispTrans = display.DisplayTransformation; double distance = dispTrans.FromPoints(PointSize); var fontDisp = new StdFontClass { Bold = false, Name = "Arial", Italic = false, Underline = false, Size = (decimal)FontSize }; ISymbol textSymbol = new TextSymbolClass { Font = fontDisp as IFontDisp }; display.SetSymbol(textSymbol); double distanceP = (distance * 3) / 4; IPoint pointText = new PointClass { X = _point.X + distanceP, Y = _point.Y + distanceP }; CultureInfo ci = CultureInfo.InvariantCulture; string text = _index.ToString(ci); display.DrawText(pointText, text); foreach (var observation in _observations) { double[] obs = observation.Value; if (obs.Length >= 2) { double xdir = (_point.X - obs[0]) / 2; double ydir = (_point.Y - obs[1]) / 2; string imageId = observation.Key; IColor color = Converter.ToRGBColor(ObsColor.ContainsKey(imageId) ? ObsColor[imageId] : Color.DarkGray); ISymbol lineSymbol = new SimpleLineSymbolClass { Color = color, Width = 1.25 }; display.SetSymbol(lineSymbol); var polylineClass3 = new PolylineClass(); polylineClass3.AddPoint(new PointClass { X = _point.X + xdir, Y = _point.Y + ydir }); polylineClass3.AddPoint(new PointClass { X = obs[0], Y = obs[1] }); display.DrawPolyline(polylineClass3); color = Converter.ToRGBColor(Color.LightGray); lineSymbol = new SimpleLineSymbolClass { Color = color, Width = 0.75 }; display.SetSymbol(lineSymbol); display.DrawPolyline(polylineClass3); } } display.FinishDrawing(); // ReSharper restore CSharpWarnings::CS0612 // ReSharper restore UseIndexedProperty } } } } catch (Exception ex) { Trace.WriteLine(ex.Message, "MeasurementPoint.avEventsAfterDraw"); } }
private void AxMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e) { //屏幕坐标点转化为地图坐标点 pPointPt = (axMapControl1.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); if (e.button == 1) { IActiveView pActiveView = axMapControl1.ActiveView; IEnvelope pEnvelope = new EnvelopeClass(); switch (pMouseOperate) { #region 拉框放大 case "ZoomIn": pEnvelope = axMapControl1.TrackRectangle(); //如果拉框范围为空则返回 if (pEnvelope == null || pEnvelope.IsEmpty || pEnvelope.Height == 0 || pEnvelope.Width == 0) { return; } //如果有拉框范围,则放大到拉框范围 pActiveView.Extent = pEnvelope; pActiveView.Refresh(); break; #endregion #region 拉框缩小 case "ZoomOut": pEnvelope = axMapControl1.TrackRectangle(); //如果拉框范围为空则退出 if (pEnvelope == null || pEnvelope.IsEmpty || pEnvelope.Height == 0 || pEnvelope.Width == 0) { return; } //如果有拉框范围,则以拉框范围为中心,缩小倍数为:当前视图范围/拉框范围 else { double dWidth = pActiveView.Extent.Width * pActiveView.Extent.Width / pEnvelope.Width; double dHeight = pActiveView.Extent.Height * pActiveView.Extent.Height / pEnvelope.Height; double dXmin = pActiveView.Extent.XMin - ((pEnvelope.XMin - pActiveView.Extent.XMin) * pActiveView.Extent.Width / pEnvelope.Width); double dYmin = pActiveView.Extent.YMin - ((pEnvelope.YMin - pActiveView.Extent.YMin) * pActiveView.Extent.Height / pEnvelope.Height); double dXmax = dXmin + dWidth; double dYmax = dYmin + dHeight; pEnvelope.PutCoords(dXmin, dYmin, dXmax, dYmax); } pActiveView.Extent = pEnvelope; pActiveView.Refresh(); break; #endregion #region 漫游 case "Pan": axMapControl1.Pan(); break; #endregion #region 择要素 case "SelFeature": IEnvelope pEnv = axMapControl1.TrackRectangle(); IGeometry pGeo = pEnv as IGeometry; //矩形框若为空,即为点选时,对点范围进行扩展 if (pEnv.IsEmpty == true) { tagRECT r; r.left = e.x - 5; r.top = e.y - 5; r.right = e.x + 5; r.bottom = e.y + 5; pActiveView.ScreenDisplay.DisplayTransformation.TransformRect(pEnv, ref r, 4); pEnv.SpatialReference = pActiveView.FocusMap.SpatialReference; } pGeo = pEnv as IGeometry; axMapControl1.Map.SelectByShape(pGeo, null, false); axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); break; #endregion #region 要素选择 case "SelectFeature": IPoint point = new PointClass(); IGeometry pGeometry = point as IGeometry; axMapControl1.Map.SelectByShape(pGeometry, null, false); axMapControl1.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); break; #endregion #region 距离量算 case "MeasureLength": //判断追踪线对象是否为空,若是则实例化并设置当前鼠标点为起始点 if (pNewLineFeedback == null) { //实例化追踪线对象 pNewLineFeedback = new NewLineFeedbackClass(); pNewLineFeedback.Display = (axMapControl1.Map as IActiveView).ScreenDisplay; //设置起点,开始动态线绘制 pNewLineFeedback.Start(pPointPt); dToltalLength = 0; } else //如果追踪线对象不为空,则添加当前鼠标点 { pNewLineFeedback.AddPoint(pPointPt); } //pGeometry = m_PointPt; if (dSegmentLength != 0) { dToltalLength = dToltalLength + dSegmentLength; } break; #endregion #region 面积量算 case "MeasureArea": if (pNewPolygonFeedback == null) { //实例化追踪面对象 pNewPolygonFeedback = new NewPolygonFeedback(); pNewPolygonFeedback.Display = (axMapControl1.Map as IActiveView).ScreenDisplay; ; pAreaPointCol.RemovePoints(0, pAreaPointCol.PointCount); //开始绘制多边形 pNewPolygonFeedback.Start(pPointPt); pAreaPointCol.AddPoint(pPointPt, ref missing, ref missing); } else { pNewPolygonFeedback.AddPoint(pPointPt); pAreaPointCol.AddPoint(pPointPt, ref missing, ref missing); } break; #endregion #region 添加文字 case "AddCharacters": { //本例的实现类似于前面测量工具的实现 //在工具条添加自定义的工具之后,在其Click事件中用m_flag变量记录操作 //然后在MapControl的OnMouseDown事件的适当位置添加如下代码: IFontDisp font = new StdFontClass() as IFontDisp; font.Bold = true; font.Name = "Arial"; font.Size = 20; IColor pColor = new RgbColorClass(); pColor.RGB = 0; ITextSymbol pTextSymbol = new TextSymbolClass(); pTextSymbol.Size = 200; pTextSymbol.Font = font; pTextSymbol.Color = pColor; IPoint pPoint = new PointClass(); pPoint.PutCoords(e.mapX, e.mapY); ITextElement pTextElement = new TextElementClass(); pTextElement.Symbol = pTextSymbol; pTextElement.Text = toolStripTextBox1.Text; IElement pElement = pTextElement as IElement; pElement.Geometry = pPoint as IGeometry; axMapControl1.ActiveView.GraphicsContainer.AddElement(pElement, 3); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); } break; #endregion #region 添加线型元素 case "AddLine": IGraphicsContainer pGra = axMapControl1.Map as IGraphicsContainer; IActiveView pAv = pGra as IActiveView; IGeometry pgeo = axMapControl1.TrackLine(); AddLineElement(pgeo, pGra); break; #endregion #region 缓冲区闪烁 case "Buffer": //IMap pMap = axMapControl1.Map; IPoint pt = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y); ITopologicalOperator pTopo = pt as ITopologicalOperator; IGeometry pGeo1 = pTopo.Buffer(50); IColor pColor1 = new RgbColorClass(); pColor1.RGB = 2556; SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass(); simpleFillSymbol.Color = pColor1; ISymbol symbol = simpleFillSymbol as ISymbol; pActiveView.ScreenDisplay.SetSymbol(symbol); pActiveView.ScreenDisplay.DrawPolygon(pGeo1); //pMap.SelectByShape(pGeo1, null, false); //闪动 axMapControl1.FlashShape(pGeo1, 26, 200, symbol); //ThreadInfo threadInfo = new ThreadInfo(); //threadInfo.pActiveView = pActiveView; //GPU并行 //threadInfo.e = e; //ThreadPool.QueueUserWorkItem(new WaitCallback(processfile), threadInfo); axMapControl1.ActiveView.Refresh(); break; #endregion default: break; } } }
private IElement MakeATextElement(IPoint pPoint, string strText, double fontsize) { IRgbColor pRGBColor; ITextElement pTextElement; ITextSymbol pTextSymbol; IElement pElement; pRGBColor = new RgbColorClass(); pRGBColor.Blue = 0; pRGBColor.Red = 0; pRGBColor.Green = 0; pTextElement = new TextElementClass(); pElement = pTextElement as IElement; pElement.Geometry = pPoint; IFontDisp pFontDisp = new StdFontClass() as IFontDisp; pFontDisp.Name = "Time NewRoman"; pFontDisp.Bold = true; pTextSymbol = new TextSymbolClass(); pTextSymbol.Font = pFontDisp; pTextSymbol.Color = pRGBColor; pTextSymbol.Size = fontsize; pTextElement.Symbol = pTextSymbol; pTextElement.Text = strText; return pElement; }
public static void AddTextElement(AxPageLayoutControl PageLayoutControl, double x, double y, string textName) { IPageLayout pPageLayout; IActiveView pAV; IGraphicsContainer pGraphicsContainer; IPoint pPoint; ITextElement pTextElement; IElement pElement; ITextSymbol pTextSymbol; IRgbColor pColor; pPageLayout = PageLayoutControl.PageLayout; pAV = (IActiveView)pPageLayout; pGraphicsContainer = (IGraphicsContainer)pPageLayout; pTextElement = new TextElementClass(); IFontDisp pFont = new StdFontClass() as IFontDisp; pFont.Bold = true; pFont.Name = "宋体"; pFont.Size = 26; pColor = new RgbColorClass(); pColor.Red = 255; pTextSymbol = new TextSymbolClass(); pTextSymbol.Color = (IColor)pColor; pTextSymbol.Font = pFont; pTextElement.Text = textName; pTextElement.Symbol = pTextSymbol; pPoint = new PointClass(); pPoint.X = x; pPoint.Y = y; pElement = (IElement)pTextElement; pElement.Geometry = (IGeometry)pPoint; pGraphicsContainer.AddElement(pElement, 0); pAV.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null); }
/// <summary> /// 对生成的各图层进行符号、标注设置 /// </summary> /// <param name="impfilepath">导入符号mxd文件路径</param> /// <param name="passpoint">生成的点图层</param> /// <param name="passline">生成的线图层</param> public void ImpSymbolFromFile(string impfilepath, ILayer passpoint, ILayer passline) { IMapDocument pMapDocument = new MapDocumentClass(); pMapDocument.Open(impfilepath, null); IMap pMap = pMapDocument.Map[0]; for (int i = 0; i < pMap.LayerCount; i++) { ILayer pLayerSymbol = pMap.get_Layer(i); if (pLayerSymbol is IFeatureLayer && pLayerSymbol.Name.Contains("point")) { IFeatureLayer pFLayerSymbol = pLayerSymbol as IFeatureLayer; IGeoFeatureLayer pGFLayerSymbol = pFLayerSymbol as IGeoFeatureLayer; IFeatureLayer pFPasspointWait = passpoint as IFeatureLayer; IGeoFeatureLayer pGPasspointWait = pFPasspointWait as IGeoFeatureLayer; if (pGFLayerSymbol != null) { pGPasspointWait.Renderer = pGFLayerSymbol.Renderer; IAnnotateLayerProperties pAnnoLayerP; // = new LabelEngineLayerPropertiesClass();//渲染图层的符号图层标注 IElementCollection PELECOLL; //queryitem的参数,用不到 IElementCollection pelecoll; //同上 pGFLayerSymbol.AnnotationProperties.QueryItem(0, out pAnnoLayerP, out PELECOLL, out pelecoll); ILabelEngineLayerProperties pLabelEenLayPro = pAnnoLayerP as ILabelEngineLayerProperties; IFontDisp pFont = new StdFontClass() as IFontDisp; ITextSymbol pTextSymbol = new TextSymbolClass(); pTextSymbol.Color = pLabelEenLayPro.Symbol.Color; pFont.Bold = pLabelEenLayPro.Symbol.Font.Bold; pFont.Italic = pLabelEenLayPro.Symbol.Font.Italic; pFont.Strikethrough = pLabelEenLayPro.Symbol.Font.Strikethrough; pFont.Underline = pLabelEenLayPro.Symbol.Font.Underline; pFont.Name = pLabelEenLayPro.Symbol.Font.Name; pFont.Size = pLabelEenLayPro.Symbol.Font.Size; pTextSymbol.Font = pFont; pGPasspointWait.AnnotationProperties.Clear(); ILabelEngineLayerProperties pLabelWaitLayPro = new LabelEngineLayerPropertiesClass();//设置待渲染图层的标注 pLabelWaitLayPro.Expression = pLabelEenLayPro.Expression; pLabelWaitLayPro.Symbol = pTextSymbol; IAnnotateLayerProperties pAnnLayProWait = pLabelWaitLayPro as IAnnotateLayerProperties;//新生成的符号图层设置标注 pAnnLayProWait.DisplayAnnotation = true; pAnnLayProWait.FeatureLayer = pGPasspointWait; pAnnLayProWait.LabelWhichFeatures = esriLabelWhichFeatures.esriVisibleFeatures; pAnnLayProWait.WhereClause = ""; pGPasspointWait.AnnotationProperties.Add(pAnnLayProWait); pGPasspointWait.DisplayAnnotation = true; } } else if (pLayerSymbol is IFeatureLayer && pLayerSymbol.Name.Contains("line")) { IFeatureLayer pFLayerSymbol = pLayerSymbol as IFeatureLayer; IGeoFeatureLayer pGFLayerSymbol = pFLayerSymbol as IGeoFeatureLayer; IFeatureLayer pFPasspointWait = passline as IFeatureLayer; IGeoFeatureLayer pGPasspointWait = pFPasspointWait as IGeoFeatureLayer; if (pGFLayerSymbol != null) { pGPasspointWait.Renderer = pGFLayerSymbol.Renderer; IAnnotateLayerProperties pAnnoLayerP = new LabelEngineLayerPropertiesClass(); //符号图层标注 IElementCollection PELECOLL; //queryitem的参数,用不到 IElementCollection pelecoll; //同上 pGFLayerSymbol.AnnotationProperties.QueryItem(0, out pAnnoLayerP, out PELECOLL, out pelecoll); ILabelEngineLayerProperties pLabelEenLayPro = pAnnoLayerP as ILabelEngineLayerProperties; IFontDisp pFont = new StdFontClass() as IFontDisp; ITextSymbol pTextSymbol = new TextSymbolClass(); pTextSymbol.Color = pLabelEenLayPro.Symbol.Color; pFont.Bold = pLabelEenLayPro.Symbol.Font.Bold; pFont.Italic = pLabelEenLayPro.Symbol.Font.Italic; pFont.Strikethrough = pLabelEenLayPro.Symbol.Font.Strikethrough; pFont.Underline = pLabelEenLayPro.Symbol.Font.Underline; pFont.Name = pLabelEenLayPro.Symbol.Font.Name; pFont.Size = pLabelEenLayPro.Symbol.Font.Size; pTextSymbol.Font = pFont; pGPasspointWait.AnnotationProperties.Clear(); ILabelEngineLayerProperties pLabelWaitLayPro = new LabelEngineLayerPropertiesClass();//设置待渲染图层的标注 pLabelWaitLayPro.Expression = pLabelEenLayPro.Expression; pLabelWaitLayPro.Symbol = pTextSymbol; IAnnotateLayerProperties pAnnLayProWait = pLabelWaitLayPro as IAnnotateLayerProperties;//新生成的符号图层设置标注 pAnnLayProWait.DisplayAnnotation = true; pAnnLayProWait.FeatureLayer = pGPasspointWait; pAnnLayProWait.LabelWhichFeatures = esriLabelWhichFeatures.esriVisibleFeatures; pAnnLayProWait.WhereClause = ""; pGPasspointWait.AnnotationProperties.Add(pAnnLayProWait); pGPasspointWait.DisplayAnnotation = true; } } } m_pTOCCtl.SetBuddyControl(m_pMapCtl); m_pTOCCtl.ActiveView.Refresh(); m_pMapCtl.ActiveView.Refresh(); }
/** * @fn CreateTitleSymbol * @date 2013.03.04 * @author Ge Xizhi * @brief 图例标题样式 * @param 返回 ITextSymbol * @param * @version 1.1 * @par 修改历史: * <作者> <时间> <版本编号> <修改原因>\n */ //图例标题字体设计 private ITextSymbol CreateTitleSymbol() { ITextSymbol pTitleSymbol = new TextSymbolClass(); IFontDisp pFont = new StdFontClass() as IFontDisp; pTitleSymbol.Color = ClsGDBDataCommon.ColorToIColor(btTitleColor.SelectedColor); //字体大小 pFont.Size = decimal.Parse(this.cboBoxTitleFontSize.Text); //字体名 pFont.Name = this.cboBoxTitleFontName.Text; //字体加粗 if (this.toolBtnBold.Checked == true) { pFont.Bold = true; } //倾斜 if (this.toolBtnIntend.Checked == true) { pFont.Italic = true; } else { pFont.Italic = false; } //下划线 if (this.toolBtnUnderline.Checked == true) { pFont.Underline = true; } else { pFont.Underline = false; } //中间线 if (this.toolBtnStrikethrough.Checked == true) { pFont.Strikethrough = true; } else { pFont.Strikethrough = false; } //将字体赋值给pTitleSymbol pTitleSymbol.Font = pFont; //字体在水平方向的位置 if (this.toolBtnLeft.Checked == true) { pTitleSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; } else if (this.toolBtnCenter.Checked == true) { pTitleSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter; } else if (this.toolBtnRight.Checked == true) { pTitleSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHARight; } else if (this.toolBtnBoth.Checked == true) { pTitleSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull; } //返回样式 return(pTitleSymbol); }
//创建图例 private void CreateLegend() { ILegendFormat pLegendFormat = new LegendFormatClass(); IMapSurroundFrame pMapSurroundFrame = new MapSurroundFrameClass(); pActiveView = m_hookHelper.ActiveView as IActiveView; pMap = pActiveView.FocusMap; //边框、背景、阴影的间距 if (txtLegendFrameGap.Text != null && pSymbolBorder != null) { pSymbolBorder.Gap = double.Parse(this.txtLegendFrameGap.Text); } if (txtLegendFrameGap.Text != null && pSymbolBackground != null) { pSymbolBackground.Gap = double.Parse(this.txtLegendFrameGap.Text); } if (txtLegendFrameGap.Text != null && pSymbolShadow != null) { pSymbolShadow.VerticalSpacing = double.Parse(this.txtLegendFrameGap.Text) + 10; pSymbolShadow.HorizontalSpacing = double.Parse(this.txtLegendFrameGap.Text) + 10; } //边框、背景、阴影的角度 if (txtLegendFrameAngle.Text != null && pSymbolBorder != null) { pSymbolBorder.CornerRounding = short.Parse(txtLegendFrameAngle.Text); } if (txtLegendFrameAngle.Text != null && pSymbolBackground != null) { pSymbolBackground.CornerRounding = short.Parse(txtLegendFrameAngle.Text); } if (txtLegendFrameAngle.Text != null && pSymbolShadow != null) { pSymbolShadow.CornerRounding = short.Parse(txtLegendFrameAngle.Text); } //边框、背景、阴影 IFrameProperties pFrameProperties = pMapSurroundFrame as IFrameProperties; if (pSymbolBorder != null) { pFrameProperties.Border = pSymbolBorder; } if (pSymbolBackground != null) { pFrameProperties.Background = pSymbolBackground; } if (pSymbolShadow != null) { pFrameProperties.Shadow = pSymbolShadow; } //显示标题 pLegendFormat.ShowTitle = true; //标题位置 pLegendFormat.TitlePosition = esriRectanglePosition.esriTopSide; //标题样式 pLegendFormat.TitleSymbol = CreateTitleSymbol(); //第四界面从上到下图例各部分之间的距离 pLegendFormat.TitleGap = double.Parse(txtTitleAndLegend.Text); pLegendFormat.VerticalItemGap = double.Parse(txtLegendItems.Text); pLegendFormat.HorizontalItemGap = double.Parse(txtColumns.Text); pLegendFormat.HeadingGap = double.Parse(txtHeadings.Text); pLegendFormat.TextGap = double.Parse(txtLabelsAndDescription.Text); pLegendFormat.VerticalPatchGap = double.Parse(txtPatchesV.Text); pLegendFormat.HorizontalPatchGap = double.Parse(txtPatchAndLabels.Text); pLegendFormat.LayerNameGap = 2; //图面的样式以及高度和宽度 if (pLinePatch != null) { pLegendFormat.DefaultLinePatch = pLinePatch; } if (pAreaPatch != null) { pLegendFormat.DefaultAreaPatch = pAreaPatch; } pLegendFormat.DefaultPatchHeight = double.Parse(this.txtPatchHeight.Text); pLegendFormat.DefaultPatchWidth = double.Parse(this.txtPatchWith.Text); //创建图例 ILegend pLegend = new LegendClass_2(); //图例名称 //pLegend.Name = this.txtLegendTitle.Text; pLegend.AutoVisibility = false; //显示显示的图层 pLegend.AutoAdd = false; //自动添加新数据到图例 pLegend.AutoReorder = true; //根据图层顺序自动排列 pLegend.Title = this.txtLegendTitle.Text; pLegend.Format = pLegendFormat; pLegend.Map = pMap; pLegend.ClearItems(); //pLegend.Refresh(); //图例列数 double pLegendColumn = double.Parse(this.LegendColumn.Text); //图例中要包含的图层个数为 pSelectedidx.Count double pLegendItemCount = pSelectedidx.Count; //计算图例分裂的位置 int ColumnPos = (int)(pLegendItemCount / pLegendColumn); double remainder = (pLegendItemCount % pLegendColumn) / pLegendColumn; if (remainder >= 0.5) { ColumnPos = ColumnPos + 1; } //设置添加到图例的图层 for (int i = 0; i < pSelectedidx.Count; i++) { ILegendItem pLegendItem = new HorizontalLegendItemClass(); ILayer pLayer = (ILayer)(pMap.get_Layer(pSelectedidx[i])); if (!pLayer.Valid) { continue; } pLegendItem.Layer = pLayer; //显示标注和描述 pLegendItem.ShowDescriptions = true; pLegendItem.ShowLabels = true; //标注和描述字体样式 ITextSymbol pLDTextSymbol = new TextSymbolClass(); IFontDisp pLDFont = new StdFontClass() as IFontDisp; IRgbColor pLDColor = new RgbColorClass(); pLDColor.Red = 0; pLDColor.Green = 0; pLDColor.Blue = 0; pLDTextSymbol.Color = pLDColor; pLDFont.Size = (decimal)8; pLDFont.Name = "宋体"; pLDTextSymbol.Font = pLDFont; ILegendClassFormat pLegendClassFormat = new LegendClassFormatClass(); pLegendClassFormat.LabelSymbol = pLDTextSymbol; pLegendClassFormat.DescriptionSymbol = pLDTextSymbol; pLegendItem.LegendClassFormat = pLegendClassFormat; //图层名称是否显示 if (pLegendItem.Layer is IFeatureLayer) { if (((IGeoFeatureLayer)pLegendItem.Layer).Renderer is ISimpleRenderer) { pLegendItem.ShowHeading = false; pLegendItem.ShowLayerName = false; } else { pLegendItem.ShowLayerName = true; pLegendItem.ShowHeading = true; //图层名称和头文件的样式 ITextSymbol pLHTextSymbol = new TextSymbolClass(); IFontDisp pLHFont = new StdFontClass() as IFontDisp; IRgbColor pLHColor = new RgbColorClass(); pLDColor.Red = 0; pLDColor.Green = 0; pLDColor.Blue = 0; pLHTextSymbol.Color = pLHColor; pLHFont.Name = "宋体"; pLHFont.Size = 10; pLHFont.Bold = true; pLHTextSymbol.Font = pLHFont; pLHTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; pLegendItem.HeadingSymbol = pLHTextSymbol; pLegendItem.LayerNameSymbol = pLHTextSymbol; } } else if (pLegendItem.Layer is IRasterLayer) { pLegendItem.ShowLayerName = true; pLegendItem.ShowHeading = true; //图层名称和头文件的样式 ITextSymbol pLHTextSymbol = new TextSymbolClass(); IFontDisp pLHFont = new StdFontClass() as IFontDisp; IRgbColor pLHColor = new RgbColorClass(); pLDColor.Red = 0; pLDColor.Green = 0; pLDColor.Blue = 0; pLHTextSymbol.Color = pLHColor; pLHFont.Name = "宋体"; pLHFont.Size = 10; pLHFont.Bold = true; pLHTextSymbol.Font = pLHFont; pLHTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; pLegendItem.HeadingSymbol = pLHTextSymbol; pLegendItem.LayerNameSymbol = pLHTextSymbol; } //列数设置 if (ColumnPos <= 1) { pLegendItem.NewColumn = true; } else if (ColumnPos > 1 && i > 0) { int columnI = i % ColumnPos; if (columnI == 0) { pLegendItem.NewColumn = true; } } ILegendLayout pLegendLayout = pLegendFormat as ILegendLayout; pLegendLayout.ScaleGraphicsOnResize = false; //将图层及样式设计加入图例中 pLegend.AddItem(pLegendItem); pLegend.Refresh(); } //将图例加载到PageLayout上 IGraphicsContainer pGraphicsContainer = pActiveView.GraphicsContainer; IMapFrame pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame; if (pMapFrame == null) { return; } pMapSurroundFrame.MapFrame = pMapFrame; pMapSurroundFrame.MapSurround = (IMapSurround)pLegend; IElement pElement = (IElement)pMapSurroundFrame; IPageLayout pPageLayout = (IPageLayout)pActiveView; IPage pPage = pPageLayout.Page; double pWidth = pPage.PrintableBounds.XMax / 10.0; double pHeigth = pPage.PrintableBounds.YMin / 10.0; IEnvelope pEnvelope = new EnvelopeClass(); pEnvelope.PutCoords(pWidth, pHeigth, pWidth + 6, pHeigth + 6); pElement.Geometry = (IGeometry)pEnvelope; pGraphicsContainer.AddElement((IElement)pMapSurroundFrame, 0); m_hookHelper.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, pMapSurroundFrame, null); }
private void btnuse_Click(object sender, EventArgs e) { try { IFontDisp pFont = new StdFontClass() as IFontDisp; pTextSymbol.Color = ClsGDBDataCommon.ColorToIColor(symbolcolor.SelectedColor); pFont.Bold = toolBtnBold.Checked; pFont.Italic = toolBtnIntend.Checked; pFont.Strikethrough = toolBtnStrikethrough.Checked; pFont.Underline = toolBtnUnderline.Checked; pFont.Name = cmbfont.Text; pFont.Size = decimal.Parse(cmbsize.Text); pTextSymbol.Font = pFont; IGeoFeatureLayer pGeoLayer = (IGeoFeatureLayer)pLayer; pGeoLayer.AnnotationProperties.Clear(); ILabelEngineLayerProperties pLabelEngine = new LabelEngineLayerPropertiesClass(); pLabelEngine.Symbol = pTextSymbol; //pLabelEngine2.BasicOverposterLayerProperties = pBasicProperties as IBasicOverposterLayerProperties; if (cmbfields.Text.Contains("[") && cmbfields.Text.Contains("]")) { pLabelEngine.Expression = cmbfields.Text; } else { string Exptext = "[" + cmbfields.Text + "]"; pLabelEngine.Expression = Exptext; } IBasicOverposterLayerProperties4 pBasic = new BasicOverposterLayerPropertiesClass(); //pBasic.PolygonPlacementMethod = esriOverposterPolygonPlacementMethod.esriAlwaysHorizontal; if (chkOverLap.Checked) { pBasic.GenerateUnplacedLabels = true; } if (pLayer is IFeatureLayer) { IFeatureLayer featureLayer = pLayer as FeatureLayer; if (featureLayer.FeatureClass == null) { return; } if (featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint) { IPointPlacementPriorities pPointPlace = new PointPlacementPrioritiesClass(); pBasic.PointPlacementMethod = esriOverposterPointPlacementMethod.esriAroundPoint; pBasic.PointPlacementOnTop = radioCenterTop.Checked; SetPointPlacementPriorities(pPointPlace); pBasic.PointPlacementPriorities = pPointPlace; } else if (featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) { //更改角度 //= new LineLabelPositionClass(); IClone pSrcClone = pBasic.LineLabelPosition as IClone; IClone pDstClone = pSrcClone.Clone(); ILineLabelPosition pLineLabelPosition = pDstClone as ILineLabelPosition; if (pLineLabelPosition != null) { if (radioBtnHorizontal.Checked) { pLineLabelPosition.Horizontal = true; pLineLabelPosition.Parallel = false; pLineLabelPosition.Perpendicular = false; } if (radioBtnPerpendicular.Checked) { pLineLabelPosition.Horizontal = false; pLineLabelPosition.Parallel = false; pLineLabelPosition.Perpendicular = true; } if (radioBtnParallel.Checked) { pLineLabelPosition.Horizontal = false; pLineLabelPosition.Parallel = true; pLineLabelPosition.Perpendicular = false; } } pBasic.LineLabelPosition = pLineLabelPosition; //pBasic.PerpendicularToAngle = true; } else if (featureLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon) { pBasic.PolygonPlacementMethod = esriOverposterPolygonPlacementMethod.esriAlwaysHorizontal; } } //赋给labelEngine pLabelEngine.BasicOverposterLayerProperties = pBasic as IBasicOverposterLayerProperties; IAnnotateLayerProperties pAnnoLayerP = (IAnnotateLayerProperties)pLabelEngine; pAnnoLayerP.DisplayAnnotation = chklabel.Checked; pAnnoLayerP.FeatureLayer = pGeoLayer; pAnnoLayerP.LabelWhichFeatures = esriLabelWhichFeatures.esriVisibleFeatures; pAnnoLayerP.WhereClause = ""; pGeoLayer.AnnotationProperties.Add(pAnnoLayerP); pGeoLayer.DisplayAnnotation = chklabel.Checked; pMapControl.ActiveView.Refresh(); //if (pTocControl.Buddy == pMapControl.Object) //{ // pTocControl.SetBuddyControl(pMapControl); // pMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); // pTocControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); //} //else if (pTocControl.Buddy.Equals(pSceneControl.Object)) //{ // pTocControl.SetBuddyControl(pSceneControl); // IActiveView pActiveView = pSceneControl.Scene as IActiveView; // pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pLayer, null); // pTocControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); //} } catch (System.Exception ex) { } }
private void AddElement(IPolyline polyline) { try { ArcGIS.Common.Editor.Editor.StartEditOperation(); string strLineInfo = CommonHelper.GetIntersectInformationFlagLineOnlyOne(polyline, _cheQiConfig, _feature); if (string.IsNullOrWhiteSpace(strLineInfo)) { MessageBox.Show(@"扯旗字段为空,请重新设置扯旗字段", @"扯旗", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } IPoint referPoint = new PointClass(); referPoint.X = _polyline.ToPoint.X; referPoint.Y = _polyline.ToPoint.Y; stdole.IFontDisp fontDisp = new StdFontClass() as IFontDisp; fontDisp.Name = _cheQiConfig.FontName; fontDisp.Size = _cheQiConfig.FontSize; fontDisp.Italic = _cheQiConfig.Italic; fontDisp.Underline = _cheQiConfig.Underline; fontDisp.Bold = _cheQiConfig.Bold; fontDisp.Strikethrough = _cheQiConfig.Strikethrough; ITextSymbol textSymbol = new TextSymbolClass(); textSymbol.Size = (double)_cheQiConfig.FontSize; textSymbol.Font = fontDisp; textSymbol.Color = _cheQiConfig.FontColor; textSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft; ITextElement textElement = new TextElementClass(); textElement.Text = strLineInfo; textElement.Symbol = textSymbol; textElement.ScaleText = true; IPoint textPoint = new PointClass(); textPoint.X = referPoint.X; textPoint.Y = referPoint.Y + 1; IElement element = textElement as IElement; element.Geometry = textPoint; IFeature annoFeature = _cheQiConfig.FlagAnnoLayer.FeatureClass.CreateFeature(); IAnnotationClassExtension annotationClassExtension = _cheQiConfig.FlagAnnoLayer.FeatureClass.Extension as IAnnotationClassExtension; IAnnotationFeature annotationFeature = new AnnotationFeatureClass(); annotationFeature = annoFeature as IAnnotationFeature; annotationFeature.Annotation = element; annotationFeature.LinkedFeatureID = _feature.OID; annoFeature.Store(); _context.ActiveView.ScreenDisplay.StartDrawing(_context.ActiveView.ScreenDisplay.hDC, 0); annotationClassExtension.Draw(annotationFeature, _context.ActiveView.ScreenDisplay, null); _context.ActiveView.ScreenDisplay.FinishDrawing(); double maxLength = annoFeature.Shape.Envelope.Width; IFeatureClass flagLineFeatureClass = _cheQiConfig.FlagLineLayer.FeatureClass; IFeature feature = flagLineFeatureClass.CreateFeature(); IPointCollection pointCollection = _polyline as IPointCollection; IPoint point = new PointClass(); point.Y = referPoint.Y; point.X = referPoint.X + maxLength; pointCollection.AddPoint(point); feature.Shape = pointCollection as IPolyline; feature.Store(); _context.ActiveView.Refresh(); } catch (Exception exception) { MessageBox.Show(exception.Message); } finally { ArcGIS.Common.Editor.Editor.StartEditOperation(); } }
/// <summary> /// 标注符号 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnsymbol_Click(object sender, EventArgs e) { FrmTextSymbol frmtext = new FrmTextSymbol(); frmtext.StartPosition = FormStartPosition.CenterScreen; frmtext.ShowInTaskbar = false; frmtext.ShowDialog(); pTextSymbol = frmtext.GetTextSymbol(); if (pTextSymbol != null) { stdole.IFontDisp pFont = pTextSymbol.Font; symbolcolor.SelectedColor = ClsGDBDataCommon.IColorToColor(pTextSymbol.Color); //cmbfont.Text = pTextSymbol.Font.Name; for (int i = 0; i < cmbfont.Items.Count; i++) { if (cmbfont.Items[i].ToString() == pTextSymbol.Font.Name) { cmbfont.SelectedIndex = i; } } cmbsize.Text = pTextSymbol.Size.ToString(); if (pFont.Bold == true) { toolBtnBold.Checked = true; } else { toolBtnBold.Checked = false; } if (pFont.Italic == true) { toolBtnIntend.Checked = true; } else { toolBtnIntend.Checked = false; } if (pFont.Underline == true) { toolBtnUnderline.Checked = true; } else { toolBtnUnderline.Checked = false; } if (pFont.Strikethrough == true) { toolBtnStrikethrough.Checked = true; } else { toolBtnStrikethrough.Checked = false; } } else { IFontDisp pFont = new StdFontClass() as IFontDisp; pTextSymbol.Color = ClsGDBDataCommon.ColorToIColor(symbolcolor.SelectedColor); pFont.Bold = toolBtnBold.Checked; pFont.Italic = toolBtnIntend.Checked; pFont.Strikethrough = toolBtnStrikethrough.Checked; pFont.Underline = toolBtnUnderline.Checked; pFont.Name = cmbfont.Text; pFont.Size = decimal.Parse(cmbsize.Text); pTextSymbol.Font = pFont; } }
//创建文字比例尺 private void CreateScaleText() { //文字比例尺样式:绝对类型和相对类型 if (ckBoxAsolute.Checked) { ScaleText.Style = esriScaleTextStyleEnum.esriScaleTextAbsolute; ScaleText.Separator = txtSeparator.Text; } else if (ckBoxRelative.Checked) { ScaleText.Style = esriScaleTextStyleEnum.esriScaleTextRelative; ScaleText.Separator = txtSeparator.Text; } //布局单位 if (cmbBoxPageUnits.SelectedItem.ToString() == "Centimeters") { ScaleText.PageUnits = esriUnits.esriCentimeters; ScaleText.PageUnitLabel = txtPageLabel.Text; } else if (cmbBoxPageUnits.SelectedItem.ToString() == "Inches") { ScaleText.PageUnits = esriUnits.esriInches; ScaleText.PageUnitLabel = txtPageLabel.Text; } else if (cmbBoxPageUnits.SelectedItem.ToString() == "Points") { ScaleText.PageUnits = esriUnits.esriPoints; ScaleText.PageUnitLabel = txtPageLabel.Text; } //地图单位 if (cmbBoxMapUnits.SelectedItem.ToString() == "Centimeters") { ScaleText.MapUnits = esriUnits.esriCentimeters; ScaleText.MapUnitLabel = txtMapLabel.Text; } else if (cmbBoxMapUnits.SelectedItem.ToString() == "Decimal Degrees") { ScaleText.MapUnits = esriUnits.esriDecimalDegrees; ScaleText.MapUnitLabel = txtMapLabel.Text; } else if (cmbBoxMapUnits.SelectedItem.ToString() == "Decimeters") { ScaleText.MapUnits = esriUnits.esriDecimeters; ScaleText.MapUnitLabel = txtMapLabel.Text; } else if (cmbBoxMapUnits.SelectedItem.ToString() == "Feet") { ScaleText.MapUnits = esriUnits.esriFeet; ScaleText.MapUnitLabel = txtMapLabel.Text; } else if (cmbBoxMapUnits.SelectedItem.ToString() == "Inches") { ScaleText.MapUnits = esriUnits.esriInches; ScaleText.MapUnitLabel = txtMapLabel.Text; } else if (cmbBoxMapUnits.SelectedItem.ToString() == "Kilometers") { ScaleText.MapUnits = esriUnits.esriKilometers; ScaleText.MapUnitLabel = txtMapLabel.Text; } else if (cmbBoxMapUnits.SelectedItem.ToString() == "Meters") { ScaleText.MapUnits = esriUnits.esriMeters; ScaleText.MapUnitLabel = txtMapLabel.Text; } else if (cmbBoxMapUnits.SelectedItem.ToString() == "Miles") { ScaleText.MapUnits = esriUnits.esriMiles; ScaleText.MapUnitLabel = txtMapLabel.Text; } else if (cmbBoxMapUnits.SelectedItem.ToString() == "Millimeters") { ScaleText.MapUnits = esriUnits.esriMillimeters; ScaleText.MapUnitLabel = txtMapLabel.Text; } else if (cmbBoxMapUnits.SelectedItem.ToString() == "Nautical Miles") { ScaleText.MapUnits = esriUnits.esriNauticalMiles; ScaleText.MapUnitLabel = txtMapLabel.Text; } else if (cmbBoxMapUnits.SelectedItem.ToString() == "Points") { ScaleText.MapUnits = esriUnits.esriPoints; ScaleText.MapUnitLabel = txtMapLabel.Text; } else if (cmbBoxMapUnits.SelectedItem.ToString() == "Unknown Units") { ScaleText.MapUnits = esriUnits.esriUnknownUnits; ScaleText.MapUnitLabel = txtMapLabel.Text; } else if (cmbBoxMapUnits.SelectedItem.ToString() == "Yards") { ScaleText.MapUnits = esriUnits.esriYards; ScaleText.MapUnitLabel = txtMapLabel.Text; } if (TextSymbol == null) { //字体样式 ITextSymbol pTextSymbol = new TextSymbolClass(); IFontDisp pFont = new StdFontClass() as IFontDisp; pFont.Name = this.cboBoxFontName.Text; pFont.Size = decimal.Parse(this.cboBoxFontSize.Text); if (FontColor.SelectedColor != null) { pTextSymbol.Color = ClsGDBDataCommon.ColorToIColor(FontColor.SelectedColor); } //风格 if (toolBtnBold.Checked == true) { pFont.Bold = true; } else { pFont.Bold = false; } if (toolBtnIntend.Checked == true) { pFont.Italic = true; } else { pFont.Italic = false; } if (toolBtnUnderline.Checked == true) { pFont.Underline = true; } else { pFont.Underline = false; } if (toolBtnStrikethrough.Checked == true) { pFont.Strikethrough = true; } else { pFont.Strikethrough = false; } pTextSymbol.Font = pFont; ScaleText.Symbol = pTextSymbol; } else if (TextSymbol != null) { ScaleText.Symbol = TextSymbol; } //设置边框、阴影、背景的距离和圆角 //边框、背景、阴影距离、角度 if (SymbolBorder != null) { if (this.txtBorderGap.Text != null) { SymbolBorder.Gap = double.Parse(this.txtBorderGap.Text); } if (txtBorderAngle.Text != null) { SymbolBorder.CornerRounding = short.Parse(this.txtBorderAngle.Text); } } if (SymbolBackground != null) { if (txtBackgroundGap.Text != null) { SymbolBackground.Gap = double.Parse(this.txtBackgroundGap.Text); } if (txtBackgroundAngle.Text != null) { SymbolBackground.CornerRounding = short.Parse(this.txtBackgroundAngle.Text); } } if (SymbolShadow != null) { if (txtShadowX.Text != null) { SymbolShadow.HorizontalSpacing = double.Parse(this.txtShadowX.Text); } if (txtShadowY.Text != null) { SymbolShadow.VerticalSpacing = double.Parse(this.txtShadowY.Text); } if (txtShadowAngle.Text != null) { SymbolShadow.CornerRounding = short.Parse(this.txtShadowAngle.Text); } } //添加边框、背景、阴影 IFrameProperties pFrameProperties = pMapSurroundFrame as IFrameProperties; if (SymbolBorder != null) { pFrameProperties.Border = SymbolBorder; } if (SymbolBackground != null) { pFrameProperties.Background = SymbolBackground; } if (SymbolShadow != null) { pFrameProperties.Shadow = SymbolShadow; } }