打开(激活)带有特定地图的 MapPane(如果存在),或者如果它不存在但无法弄清楚如何实现此目的,则创建它。
c++
private void ActivateOrOpenMapPane(string mapName)
{
var mapProjItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(mp => mp.Name == mapName);
if (mapProjItem != null)
{
// 它已经打开了吗?
var mapPane = ProApp.Panes.OfType<IMapPane>().FirstOrDefault(pane => pane.Caption == mapName);
if (mapPane != null)
{
var pane = mapPane as Pane;
pane.Activate();
}
else
{
// 打开新的地图窗格
mapProjItem.OpenMapPaneAsync();
// 或使用以下内容
// it does the same thing as MapProjectItem.OpenMapPaneAsync
//QueuedTask.Run(() =>
//{
// var map = mapProjItem.GetMap();
// ProApp.Panes.CreateMapPaneAsync(map);
//});
}
}
else
{
// MapName不在项目中
}
}
vb.net
Dim mapProjItem = Project.Current.GetItems(Of MapProjectItem)().FirstOrDefault(Function(mpi) mpi.Name = MapName)
If mapProjItem Is Nothing = False Then
'它已经打开了吗?
Dim mapPane = ProApp.Panes.OfType(Of IMapPane)().FirstOrDefault(Function(mPane) mPane.Caption = MapName)
If mapPane Is Nothing = False Then
Dim Pane As ArcGIS.Desktop.Framework.Contracts.Pane = mapPane
Pane.Activate()
Else
' 打开新的地图窗格
'Await mapProjItem.OpenMapPaneAsync()
'或使用以下内容
'it does the same thing as MapProjectItem.OpenMapPaneAsync
'QueuedTask.Run(() =>
' Dim Map = mapProjItem.GetMap()
'Await ProApp.Panes.CreateMapPaneAsync(Map)
End If
Else
'MapName不在项目中
End If