ARCGIS PRO DSK GraphicsLayer创建文本要素

embedded/2024/11/13 15:33:52/

一、判断GraphicsLayer层【地块注记】是否存在,如果不存在则新建、如果存在则删除所有要素

Dim GraphicsLayer = pmap.GetLayersAsFlattenedList().OfType(Of ArcGIS.Desktop.Mapping.GraphicsLayer).FirstOrDefault() '获取当前map对象中的GetLayer图层
Await QueuedTask.Run(Sub()If GraphicsLayer Is Nothing = True Then'创建 GraphicsLayerIf pmap.MapType <> MapType.Map Then Exit Sub       ' Not 2DDim gl_param = New GraphicsLayerCreationParamsgl_param.Name = "地块注记"'默认情况下会添加到目录的顶部GraphicsLayer = LayerFactory.Instance.CreateLayer(Of ArcGIS.Desktop.Mapping.GraphicsLayer)(gl_param, pmap)Else'全选文本Dim zj_zdmane As String = ""zj_zdmane = "地块注记"Dim elements = GraphicsLayer.GetElementsAsFlattenedList().Where(Function(gele As GraphicElement) gele.Name.StartsWith(zj_zdmane)) ’获取GetLayer图层中定义的元素(本例为text)'删除选择textGraphicsLayer.SelectElements(elements)GraphicsLayer.RemoveElements(GraphicsLayer.GetSelectedElements())End IfMapView.Active.Redraw(True)  '视图刷新End Sub)

二、CreateTextGraphicElement 方法
       ​GraphicElement CreateTextGraphicElement( 
                IElementContainer elementContainer,
                TextType textType,
                Geometry geometry,
                CIMTextSymbol textSymbol,
                string text,
                string elementName,
                bool select,                    【可选】
                ElementInfo elementInfo 【可选】
             )
             textType:要创建的文本图形的类型​

成员描述
CircleParagraph圆文本
EllipseParagraph椭圆文本
NoneNone- 默认
PointText点文本
PolygonParagraph多边形文本
RectangleParagraph矩形文本
SplinedText沿直线或曲线样条的文本

三、检查应用程序中是否有特定字体可用于 Pro 会话。 必须在 MCT 上调用此方法。IsFontAvailable 方法 (SymbolFactory)
public bool IsFontAvailable( 
                  string fontName,   
                  string fontStyle,
                  FontType fontType,
                  List<CIMFontVariation> fontVariationSettings
               )
               fontName:字体簇的名称。
               fontStyle :字体样式的名称。
               fontType:字体类型。
               fontVariationSettings:要应用的任何字体变体设置。可以为 null。
返回值:一个布尔值,表示字体是否可用。例如:

Dim BOOT=SymbolFactory.Instance.IsFontAvailable("Arial", "Bold", FontType.Unspecified, null)

四、创建文本
1、创建简单的文本符号(Creates a simple text symbol)创建一个大小为8.5、字体系列为“Corbel”、字体样式为“Regular”的简单黑色文本符号。

Await QueuedTask.Run(Sub()pmap = MapView.Active.Map  ‘获取激活的map对象Dim GraphicsLayer = pmap.GetLayersAsFlattenedList().OfType(Of ArcGIS.Desktop.Mapping.GraphicsLayer).FirstOrDefault()  ‘获取的GraphicsLayer对象Dim TextSymbol =SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8.5, "Corbel", "Regular")'文本的偏移量TextSymbol.OffsetX = 0.5TextSymbol.OffsetY = 0.5Dim Location As MapPoint = MapPointBuilderEx.CreateMapPoint(PX,PY)Dim text As String = "Forest Grove"Dim polyTxtElm As GraphicElement = ElementFactory.Instance.CreateTextGraphicElement(GraphicsLayer, TextType.PointText, Location, TextSymbol, text, "地块注记")End Sub)

效果:

2、创建创建带有光晕环的文本符号(Creates a text symbol with a halo)

Await QueuedTask.Run(Sub()pmap = MapView.Active.Map  ‘获取激活的map对象Dim GraphicsLayer = pmap.GetLayersAsFlattenedList().OfType(Of ArcGIS.Desktop.Mapping.GraphicsLayer).FirstOrDefault()  ‘获取的GraphicsLayer对象Dim haloPoly = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.RedRGB, SimpleFillStyle.Solid)Dim TextSymbol = SymbolFactory.Instance.ConstructTextSymbol(haloPoly, 10, "Arial", "Bold")'文本的偏移量TextSymbol.OffsetX = 0.5TextSymbol.OffsetY = 0.5Dim Location As MapPoint = MapPointBuilderEx.CreateMapPoint(PX,PY)Dim text As String = "Portland"Dim polyTxtElm As GraphicElement = ElementFactory.Instance.CreateTextGraphicElement(GraphicsLayer, TextType.PointText, Location, TextSymbol, text, "地块注记")End Sub)

 效果:

3、创建简单的牵引文本符号(Creates a text symbol with a halo)

Await QueuedTask.Run(Sub()pmap = MapView.Active.Map  ‘获取激活的map对象Dim GraphicsLayer = pmap.GetLayersAsFlattenedList().OfType(Of ArcGIS.Desktop.Mapping.GraphicsLayer).FirstOrDefault()  ‘获取的GraphicsLayer对象Dim textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 10, "Verdana", "Regular")Dim lineCalloutSymbol = new CIMSimpleLineCallout()Dim lineSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 1, SimpleLineStyle.DashDotDot)lineCalloutSymbol.LineSymbol = lineSymbol'文本的偏移量TextSymbol.OffsetX = 10TextSymbol.OffsetY = 10textSymbol.Callout = lineCalloutSymbolDim Location As MapPoint = MapPointBuilderEx.CreateMapPoint(PX,PY)Dim text As String = "Forest Grove"Dim polyTxtElm As GraphicElement = ElementFactory.Instance.CreateTextGraphicElement(GraphicsLayer, TextType.PointText, Location, TextSymbol, text, "地块注记")End Sub)

效果:

4、创建圆角矩形的牵引文本框符号(Creates a balloon callout text symbol)

Await QueuedTask.Run(Sub()pmap = MapView.Active.Map  ‘获取激活的map对象Dim GraphicsLayer = pmap.GetLayersAsFlattenedList().OfType(Of ArcGIS.Desktop.Mapping.GraphicsLayer).FirstOrDefault()  ‘获取的GraphicsLayer对象Dim Location As MapPoint = MapPointBuilderEx.CreateMapPoint(PX,PY)Dim textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.WhiteRGB, 11, "Corbel", "Regular")Dim balloonCallout = new CIMBalloonCallout()BalloonCallout.BalloonStyle = BalloonCalloutStyle.RoundedRectangleDim polySymbol = SymbolFactory.Instance.ConstructPolygonSymbol(ColorFactory.Instance.BlackRGB, SimpleFillStyle.Solid)BalloonCallout.BackgroundSymbol = polySymbolBalloonCallout.Margin = new CIMTextMarginWith BalloonCallout.Margin.Left = 5.Right = 5.Bottom = 5.Top = 5End WithTextSymbol.Callout = balloonCalloutDim text As String = "Forest Grove"Dim polyTxtElm As GraphicElement = ElementFactory.Instance.CreateTextGraphicElement(GraphicsLayer, TextType.RectangleParagraph, Location, TextSymbol, text, "地块注记")End Sub)

效果:

5、创建点符号的文本符号(Creates a point callout text symbol)

Await QueuedTask.Run(Sub()pmap = MapView.Active.Map  ‘获取激活的map对象Dim GraphicsLayer = pmap.GetLayersAsFlattenedList().OfType(Of ArcGIS.Desktop.Mapping.GraphicsLayer).FirstOrDefault()  ‘获取的GraphicsLayer对象Dim textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.WhiteRGB, 6, "Tahoma", "Bold")Dim shieldCalloutSymbol = new CIMPointSymbolCallout()Dim symbolStyleItem = GetPointSymbol("ArcGIS 2D", "Shield 1")             ShieldCalloutSymbol.PointSymbol = symbolStyleItem.Symbol as CIMPointSymbolShieldCalloutSymbol.PointSymbol.SetSize(18.0)TextSymbol.Callout = shieldCalloutSymbolDim Location As MapPoint = MapPointBuilderEx.CreateMapPoint(PX,PY)Dim text As String = "I5"Dim polyTxtElm As GraphicElement = ElementFactory.Instance.CreateTextGraphicElement(GraphicsLayer, TextType.PointText, Location, TextSymbol, text, "地块注记")End Sub)

效果:

6、创建设置矩形背景色的牵引文本框符号(Creates a background callout text symbol)

Await QueuedTask.Run(Sub()pmap = MapView.Active.Map  ‘获取激活的map对象Dim GraphicsLayer = pmap.GetLayersAsFlattenedList().OfType(Of ArcGIS.Desktop.Mapping.GraphicsLayer).FirstOrDefault()  ‘获取的GraphicsLayer对象Dim Location As MapPoint = MapPointBuilderEx.CreateMapPoint(PX,PY)Dim textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8, "Tahoma", "Bold")Dim backgroundCalloutSymbol = new CIMBackgroundCallout()Dim lineSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 1, SimpleLineStyle.DashDotDot)Dim aquaBackground = ColorFactory.Instance.CreateRGBColor(190, 255, 232, 100)Dim polySymbol = SymbolFactory.Instance.ConstructPolygonSymbol(aquaBackground, SimpleFillStyle.Solid)BackgroundCalloutSymbol.LeaderLineSymbol = lineSymbolTextSymbol.OffsetX = 10TextSymbol.OffsetY = 10BackgroundCalloutSymbol.BackgroundSymbol = polySymbolDim accentSymbol = SymbolFactory.Instance.ConstructLineSymbol(ColorFactory.Instance.BlackRGB, 2, SimpleLineStyle.Solid)BackgroundCalloutSymbol.AccentBarSymbol = accentSymbolBackgroundCalloutSymbol.Margin = new CIMTextMarginWith BalloonCallout.Margin.Left = 5.Right = 5.Bottom = 5.Top = 5End WithTextSymbol.Callout = backgroundCalloutSymbolDim text As String = "Forest Grove"Dim polyTxtElm As GraphicElement = ElementFactory.Instance.CreateTextGraphicElement(GraphicsLayer,TextType.RectangleParagraph, poly, TextSymbol, text, "地块注记")End Sub)

效果:


http://www.ppmy.cn/embedded/86795.html

相关文章

C#测试控制台程序调用Quartz.NET的基本用法

Quartz.Net是常用的任务调用框架之一&#xff0c;既能在客户端程序中使用&#xff0c;也支持在网页程序后台调用。本文结合参考文献4中的示例代码学习其在控制台程序中的基本用法。   VS2022新建控制台项目&#xff0c;在Nuget包管理器中搜索并安装Quartz包&#xff0c;如下所…

Dav_笔记11:SQL Tuning Overview-sql调优 之 1

Introduction to SQL Tuning SQL调优简介 SQL调优涉及以下基本步骤&#xff1a; ■通过查看系统中可用的过去SQL执行历史记录&#xff0c;识别负责大量应用程序工作负载和系统资源的高负载或顶级SQL语句 ■验证查询优化器为这些语句生成的执行计划是否合理执行 ■实施纠正…

PHP Filesystem 简介

PHP Filesystem 简介 PHP 是一种广泛使用的开源服务器端脚本语言&#xff0c;特别适用于网页开发。在 PHP 中&#xff0c;Filesystem 是一个功能丰富的库&#xff0c;提供了一系列用于文件系统操作的函数。这些函数允许开发者读取、写入、修改和删除文件和目录&#xff0c;以及…

探索WebKit的画布世界:HTML5 <canvas> 元素的深度解析

探索WebKit的画布世界&#xff1a;HTML5 <canvas> 元素的深度解析 HTML5的<canvas>元素为Web开发带来了强大的图形绘制能力。它允许开发者使用JavaScript在网页上绘制图形&#xff0c;实现动画和复杂的视觉效果。WebKit&#xff0c;作为许多现代浏览器的渲染引擎&…

如何在AWS免费撸一年的服务器

亚马逊云服务器是一家领先的云计算服务提供商&#xff0c;为用户提供了丰富的云计算服务和资源。对于初创企业或个人开发者来说&#xff0c;AWS的免费套餐是一个不错的选择。那么&#xff0c;如何在AWS免费撸一年的服务器呢&#xff1f;九河云来为读者们分享一些经验。 首先&a…

STM32智能工业监控系统教程

目录 引言环境准备智能工业监控系统基础代码实现&#xff1a;实现智能工业监控系统 4.1 数据采集模块 4.2 数据处理与控制模块 4.3 通信与网络系统实现 4.4 用户界面与数据可视化应用场景&#xff1a;工业监控与优化问题解决方案与优化收尾与总结 1. 引言 智能工业监控系统通…

力扣刷题--674. 最长连续递增序列【简单】

题目描述 给定一个未经排序的整数数组&#xff0c;找到最长且 连续递增的子序列&#xff0c;并返回该序列的长度。 连续递增的子序列 可以由两个下标 l 和 r&#xff08;l < r&#xff09;确定&#xff0c;如果对于每个 l < i < r&#xff0c;都有 nums[i] < num…

jdk8——lambda表达式

在 Java 8 中引入了 Lambda 表达式&#xff0c;使得代码更加简洁和易读。Lambda 表达式是一种匿名函数&#xff0c;可以作为参数传递给方法或者存储在变量中。它主要用于简化函数式编程。 Lambda 表达式只能用于实现函数式接口。函数式接口是只包含一个抽象方法的接口&#xf…