ArcGIS Pro 一些效果的实现
程序员文章站
2022-05-24 23:46:52
...
目录
1、隐藏目录停靠窗格
这个貌似通过配置没法解决,试了很多办法,最后发现在 ArcGIS.Desktop.Core.Events.ActivePaneInitializedEvent事件中写代码可以在界面完全展示前可以隐藏目录停靠窗。调用的地方写在ConfigurationManager类的方法中。
ArcGIS.Desktop.Core.Events.ActivePaneInitializedEvent.Subscribe((args)=>
{
var dockPane = FrameworkApplication.DockPaneManager.Find("esri_core_projectDockPane");
dockPane.Hide();
});
2、工程打开事件
ArcGIS.Desktop.Mapping.Events.LayersAddedEvent.Subscribe((args) =>
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show($"加载了{args.Layers.Count()}个图层。");
});
3、图层打开事件
Action<ProjectEventArgs> OnProjectOpened = (arg) =>
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show($"加载了【{arg.Project.URI}】工程。");
};
ProjectOpenedEvent.Subscribe(OnProjectOpened); //subscribe to Project opened event
4、取消ArcGIS Pro打开
protected override void OnApplicationInitializing(CancelEventArgs cancelEventArgs)
{
//// 此处插入自定义登录窗体的逻辑
frmLogin frmLogin = new frmLogin();
if (!(frmLogin.ShowDialog() ?? false))
{
cancelEventArgs.Cancel = true;
}
}
5、控制其它tab页面的显示
Button的Onclick事件
internal class Button_StartEdit : Button
{
private bool _isEditing;
protected override void OnClick()
{
if (!_isEditing)
FrameworkApplication.State.Activate("acme_edit");
else
FrameworkApplication.State.Deactivate("acme_edit");
_isEditing = !_isEditing;
DialogHelper dlgHelper = new DialogHelper();
dlgHelper.ShowInformation("", string.Format("{0}编辑成功!", _isEditing ? "开启" : "停止"));
}
protected override void OnUpdate()
{
if (!_isEditing)
Caption = "开启编辑";
else
Caption = "停止编辑";
}
}
DAML配置
<conditions>
<insertCondition id="acme_editing" caption="editing">
<state id="acme_edit" />
</conditions>
=======================我是分割线=========================
<tab id="tab2" caption="编辑(自定义)" condition="acme_editing" keytip="Z2">
<!--<group refID="esri_core_clipboardGroup"/>-->
<group refID="esri_editing_Manage" />
<group refID="esri_editing_Snapping" />
<group refID="esri_editing_Features" />
<group refID="esri_editing_selectionGroup" />
<group refID="ConstructionTool_Group1" />
<group refID="Construction_Tool" />
<!--<group refID="esri_editing_EditGallery"/>-->
<!--<group refID="esri_editing_elevationGroup"/>-->
</tab>
6、 禁止地图窗格和内容、目录停靠窗体跨进程拖拽图层
ArcGIS Pro 默认是可以跨进程拖拽图层到其它Pro应用程序的,通过isDropTarget属性控制拖拽。
var dockCatagory = database.Root.Descendants(nsp + "dockPane").First(ele => ele.Attribute("id").Value.Equals("esri_core_projectDockPane"));
dockCatagory.Add(new XAttribute("isDropTarget", "false"));
//// 禁止地图和内容窗体拖拽内容
dockCatagory = database.Root.Descendants(nsp + "dockPane").First(ele => ele.Attribute("id").Value.Equals("esri_core_contentsDockPane"));
dockCatagory.Add(new XAttribute("isDropTarget", "false"));
dockCatagory = database.Root.Descendants(nsp + "pane").First(ele => ele.Attribute("id").Value.Equals("esri_mapping_mapPane"));
dockCatagory.Add(new XAttribute("isDropTarget", "false"));
//// 如果节点有此属性通过修改属性的方式
//dockCatagory.Attribute("isDropTarget").Value = "false";
7、隐藏所以的Pro的tab页
var nsp = database.Root.Name.Namespace;
var tabElements = from seg in database.Root.Descendants(nsp + "tab") select seg;
var elements = new HashSet<XElement>();
foreach (var tabElement in tabElements)
{
if (tabElement.Parent == null
|| tabElement.Parent.Name.LocalName.StartsWith("backstage"))
continue;
var id = tabElement.Attribute("id");
if (id == null) continue;
if (id.Value.StartsWith("esri"))
elements.Add(tabElement);
}
foreach (var element in elements)
{
element.Remove();
}
8、如何隐藏授权提示
在Pro2.2中提供了隐藏功能,之前的版本不支持。
9、消息提示
if (!_IsAdd)
{
ArcGIS.Desktop.Framework.FrameworkApplication.RemoveNotification(notification);
}
else
{
notification.Title = "提示";
notification.Message = "xxxxxxxxxx";
notification.ImageUrl = @"pack://application:,,,/ArcGIS.Desktop.Resources;component/Images/AddInDesktop16.png";
ArcGIS.Desktop.Framework.FrameworkApplication.AddNotification(notification);
}
_IsAdd = !_IsAdd;
10、统一处理未处理的异常
Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
11、自定义控件不出现在加载项Tab页
appearsOnAddInTab属性控制是否显示在加载项tab页面。
<group id="TDProAppModule_Group1" caption="编辑" appearsOnAddInTab="false" keytip="Z2">
<!-- host controls within groups -->
<button refID="Button_StartEdit" size="large" />
<button refID="TestDemo_ProAppModule_Controls_Dockpane_Catalog_ShowButton" size="large" />
</group>