ArcGIS Pro SDK (七)编辑 13 注解
文章目录
- [ArcGIS Pro SDK (七)编辑 13 注解](#ArcGIS Pro SDK (七)编辑 13 注解)
-
- [1 注释构建工具](#1 注释构建工具)
- [2 以编程方式启动编辑批注](#2 以编程方式启动编辑批注)
- [3 更新批注文本](#3 更新批注文本)
- [4 修改批注形状](#4 修改批注形状)
- [5 修改批注文本图形](#5 修改批注文本图形)
- [6 接地到网格](#6 接地到网格)
环境:Visual Studio 2022 + .NET6 + ArcGIS Pro SDK 3.0
1 注释构建工具
csharp
// 在您的 config.daml 中设置 categoryRefID
// <tool id="..." categoryRefID="esri_editing_construction_annotation" caption="Create Anno" ...>
// 在构造函数中选择 Sketch 类型 Point 或 Line 或 BezierLine...
internal class AnnoConstructionTool : MapTool
{
public AnnoConstructionTool()
{
IsSketchTool = true;
UseSnapping = true;
SketchType = SketchGeometryType.Point;
}
protected async override Task<bool> OnSketchCompleteAsync(Geometry geometry)
{
if (CurrentTemplate == null || geometry == null)
return false;
// 创建编辑操作
var createOperation = new EditOperation();
createOperation.Name = string.Format("Create {0}", CurrentTemplate.Layer.Name);
createOperation.SelectNewFeatures = true;
var insp = CurrentTemplate.Inspector;
var result = await QueuedTask.Run(
() =>
{
// 获取注释属性类
AnnotationProperties annoProperties = insp.GetAnnotationProperties();
// 设置自定义注释属性
annoProperties.TextString = "自定义文本";
annoProperties.Color = ColorFactory.Instance.RedRGB;
annoProperties.FontSize = 24;
annoProperties.FontName = "Arial";
annoProperties.HorizontalAlignment = ArcGIS.Core.CIM.HorizontalAlignment.Right;
annoProperties.Shape = geometry;
// 将注释属性分配回检查器
insp.SetAnnotationProperties(annoProperties);
// 队列特征创建
createOperation.Create(CurrentTemplate.Layer, insp);
// 执行操作
return createOperation.Execute();
});
return result;
}
2 以编程方式启动编辑批注
csharp
var plugin = FrameworkApplication.GetPlugInWrapper("esri_editing_EditVerticesText");
if (plugin.Enabled)
((ICommand)plugin).Execute(null);
3 更新批注文本
csharp
await QueuedTask.Run(() =>
{
// annoLayer 是您的注释图层...
// 使用检查器方法学
// 在 2.x 版本中 - var insp = new Inspector(true);
var insp = new Inspector();
insp.Load(annoLayer, oid);
// 获取注释属性
AnnotationProperties annoProperties = insp.GetAnnotationProperties();
// 设置属性
annoProperties.TextString = "Hello World";
// 将注释属性分配回检查器
insp.SetAnnotationProperties(annoProperties);
// 创建和执行编辑操作
EditOperation op = new EditOperation();
op.Name = "Update annotation";
op.Modify(insp);
op.Execute();
});
4 修改批注形状
csharp
await QueuedTask.Run(
() =>
{
// 不要使用 'Shape'....Shape 是注释文本的边界框,这不是您想要的...
// 在 2.x 版本中 - var insp = new Inspector(true);
var insp = new Inspector();
insp.Load(annoLayer, oid);
AnnotationProperties annoProperties = insp.GetAnnotationProperties();
var shape = annoProperties.Shape;
if (shape.GeometryType != GeometryType.GeometryBag)
{
var newGeometry = GeometryEngine.Instance.Move(shape, 10, 10);
annoProperties.Shape = newGeometry;
insp.SetAnnotationProperties(annoProperties);
EditOperation op = new EditOperation();
op.Name = "Change annotation angle";
op.Modify(insp);
op.Execute();
}
});
5 修改批注文本图形
csharp
await QueuedTask.Run(
() =>
{
var selection = annoLayer.GetSelection();
if (selection.GetCount() == 0)
return;
// 使用第一个选中的要素
// 在 2.x 版本中 - var insp = new Inspector(true);
var insp = new Inspector();
insp.Load(annoLayer, selection.GetObjectIDs().FirstOrDefault());
// 如果不是注释要素,则应返回 null 的 getAnnoProperties
AnnotationProperties annoProperties = insp.GetAnnotationProperties();
// 获取文本图形
CIMTextGraphic textGraphic = annoProperties.TextGraphic;
// 修改文本
textGraphic.Text = "Hello world";
// 通过符号设置 x、y 偏移量
var symbol = textGraphic.Symbol.Symbol;
var textSymbol = symbol as CIMTextSymbol;
textSymbol.OffsetX = 2;
textSymbol.OffsetY = 3;
textSymbol.HorizontalAlignment = HorizontalAlignment.Center;
// 加载更新后的文本图形
annoProperties.LoadFromTextGraphic(textGraphic);
// 将注释属性分配回去
insp.SetAnnotationProperties(annoProperties);
EditOperation op = new EditOperation();
op.Name = "modify symbol";
op.Modify(insp);
bool result = op.Execute();
});
6 接地到网格
csharp
CIMGroundToGridCorrection correction = null;
bool isCorecting = correction.IsCorrecting(); // 等同于 correction != null && correction.Enabled;
bool UsingOffset = correction.UsingDirectionOffset(); // 等同于 correction.IsCorrecting() && correction.UseDirection;
double dOffset = correction.GetDirectionOffset(); // 等同于 correction.UsingDirectionOffset() ? correction.Direction : DefaultDirectionOffset;
bool usingDistanceFactor = correction.UsingDistanceFactor(); // 等同于 correction.IsCorrecting() && correction.UseScale;
bool usingElevation = correction.UsingElevationMode(); // 等同于 correction.UsingDistanceFactor() && c.ScaleType == GroundToGridScaleType.ComputeUsingElevation;
bool usingSFactor = correction.UsingConstantScaleFactor(); //; 等同于 correction.UsingDistanceFactor() && correction.ScaleType == GroundToGridScaleType.ConstantFactor;
double dSFactor = correction.GetConstantScaleFactor(); // 等同于 correction.UsingDistanceFactor() ? correction.ConstantScaleFactor : DefaultConstantScaleFactor;