飞啊飞
频道主
ArcGIS Pro 几个公用变量

1.1 几个公用变量
Pro开发中几个公用变量列表如表1-7所列:
表1-7 Pro各个公用变量的含义
在Pro的二次开发中,最主要的包括:
1. MapView(地图视图): 用于展示和操作地图数据的视图界面。
2. LayoutView(布局视图): 用于设计和编辑打印布局,如地图、图例、标注等的排列和样式。
3. ProApp(应用程序): 代表整个Pro应用程序,是许多操作的起点。
4. Project(工程): 指的是Pro中的项目文件,包含地图、数据、布局等。
5. FrameworkApplication与ProApp: 这两者在功能上相似,都代表应用程序级别的接口,但在某些上下文中可能有所不同。
Pro采用面向对象的编程范式。在这种编程范式中,每个对象都有属性(Properties)、方法(Methods)和事件(Events):
l 属性(Property): 描述对象的特征,例如颜色、大小或状态。这些值可以被读取或设置。
l 方法(Methods): 是对象可以执行的行为或动作。方法通常表示为带括号的函数调用,这区别于属性,它们不带括号。
l 事件(Events): 是由对象状态变化或用户交互(如键盘按键、鼠标位置或按钮状态)触发的特定行为。
通过理解这些基本概念,开发者可以更有效地使用Pro SDK来开发GIS应用程序。
1.1.1 MapView的属性和方法
MapView的主要属性如表1-8所列。
表1-8 各个类库的含义
MapView的属性代码在:ButtonMapView属性.cs,具体代码如下:
// 自定义一个继承于Button的新类,名为ButtonMapView属性
internal class ButtonMapView属性 : Button
{
// 重写基类Button的OnClick方法,定义点击按钮时的行为
protected override void OnClick()
{
// 获取当前激活的地图视图,并将其赋值给mapView变量
MapView mapView = MapView.Active;
// 判断当前是否有激活的地图视图,如果没有则显示一个消息框告知用户,然后直接返回
if (mapView == null)
{
MessageBox.Show("不在地图视图");
return;
}
// 获取当前激活视图的地图,并将其赋值给map变量
Map map = mapView.Map;
// 获取当前地图的名字,并将其赋值给MapName变量
string MapName = map.Name;
// 获取当前视图的相机,并将其赋值给camera变量
Camera camera = mapView.Camera;
// 获取当前相机的比例尺,并将其赋值给MapScale变量
double MapScale = camera.Scale;
// 获取当前视图的范围,并将其赋值给envelope变量
Envelope envelope = mapView.Extent;
// 显示一个消息框,显示当前地图的名字、比例尺以及范围的宽度
MessageBox.Show(string.Format("MapName={0}\n,比例尺={1}\n,宽度={2}", MapName, MapScale, envelope.Width, envelope.Height));
// 计算并获取比例尺,并将其赋值给Scale变量
double Scale = camera.ViewportWidth / (mapView.GetViewSize().Width / 96 * 25.4 / 1000);
// 显示一个消息框,显示计算出来的比例尺
MessageBox.Show("自己计算的比例尺:" + Scale.ToString("f2"));
}
}
MapView的主要方法如表1-9所列。
表1-9 各个类库的含义
MapView的方法代码在:ButtonMapView方法.cs,具体代码如下:
protected override void OnClick()
{
MapView mapView = MapView.Active;
if (mapView == null)
{
MessageBox.Show("不在地图视图");
return;
}
Map map = mapView.Map;
mapView.RedrawAsync(true);//刷新
QueuedTask.Run(() =>
{
MessageBox.Show("全屏");
mapView.ZoomToFullExtent();//全屏
});
}
1.1.2 LayoutView的属性和方法
LayoutView的属性如表1-10所列。
表1-10 各个类库的含义
代码在:ButtonLayoutView属性.cs,具体调用如下:
protected override void OnClick()
{
LayoutView layoutView = LayoutView.Active;
if (layoutView == null)
{
MessageBox.Show("不在布局视图");
return;
}
MapFrame mapFrame = layoutView.ActiveMapFrame;
string Name = "";
if (mapFrame != null)
{
Name = mapFrame.Name;
}
Envelope envelope = layoutView.Extent;
Layout layout = layoutView.Layout;
double d = layoutView.ZoomPercentage;//百分比
MessageBox.Show(string.Format("ActivatedMapFrame={0},envelope.width={1},layoutName={2},ZoomPercentage={3}",
Name, envelope.Width, layout.Name, d));
}
LayoutView的方法如表1-11所列
表1-11 LayoutView的方法
代码在ButtonLayoutView方法.cs,代码如下:
protected async override void OnClick()
{
LayoutView layoutView = LayoutView.Active;
if (layoutView == null)
{
MessageBox.Show("不在布局视图");
return;
}
await QueuedTask.Run(() =>
{
layoutView.ClearElementSelection();//清除选择
layoutView.Refresh();//刷新
layoutView.SelectAllElements();//选择所有对象
layoutView.ZoomToWholePage();//全图
});
}
1.1.3 ProApp的属性和方法
ProApp的属性如表1-12所列
表1-12 ProApp的属性
代码在ButtonProApp的属性.cs,具体代码如下:
protected override void OnClick()
{
string ActiveTab = ProApp.ActiveTab;
string Name = ProApp.Name;//名称
string Title = ProApp.Title;//标题
string toolname = ProApp.ActiveTool.Caption;
MessageBox.Show(string.Format("ActiveTab={0},Name={1},Title={2},toolname={3}", ActiveTab, Name, Title, toolname));
foreach (Pane pane in ProApp.Panes)
{
pane.Flash();
//面板的名称和ID
MessageBox.Show(pane.Caption + ":" + pane.ID);
}
}
ProApp的方法如表1-13所列。
表1-13 ProApp的方法
代码在ButtonProApp的方法.cs,具体代码如下:
protected override void OnClick()
{
// 激活名为"esri_mapping_insertTab"的标签页
ProApp.ActivateTab("esri_mapping_insertTab");
// 执行名为"esri_mapping_clearSelectionButton"的命令,清除选中项
ProApp.ExecuteCommand("esri_mapping_clearSelectionButton");
// 通过插件名获取插件对象,名为"esri_mapping_clearSelectionButton"
var plugin = ProApp.GetPlugInWrapper("esri_mapping_clearSelectionButton");
// 检查插件是否可用,如果可用,执行插件的Execute方法
if (plugin.Enabled)
((ICommand)plugin).Execute(null);
// 显示一个消息框,告知用户"关闭"
MessageBox.Show("关闭");
// 异步执行Pro应用程序的关闭操作
ProApp.ShutdownAsync();
}
1.1.4 进度条
代码在:Button进度条.cs,不能在调试程序下运行,在非调试下运行,不然:进度条就不能正确显示出来。
//不能在调试程序下运行,非调试下运行
protected override async void OnClick()
{
using (var progress = new ProgressDialog("显示进度条简单例子", "取消", 100, false))
{
var status = new CancelableProgressorSource(progress);
status.Max = 100;
progress.Show();
await QueuedTask.Run(async () =>
{
for (var idx = 0; idx < 10; idx++)
{
await Task.Delay(1000);//可以写成你需要的其他事情
status.Progressor.Value += 10;
status.Progressor.Status = (status.Progressor.Value * 100 / status.Progressor.Max) + @" % 完成";
status.Progressor.Message = "Message " + status.Progressor.Value;
}
}, status.Progressor);
progress.Hide();
}
}
- 下载图片
- 复制图片
2024-10-30
浏览117
登录后评论
1
评论
分享