arcengine二次开发对已经打开的图层进行关闭
时间: 2023-06-13 17:08:33 浏览: 110
可以使用IWorkspaceEdit接口中的方法来关闭已经打开的图层。具体步骤如下:
1. 获取当前地图文档对象的IWorkspace接口对象。
2. 判断当前地图文档是否处于编辑状态,如果未处于编辑状态,则开启编辑操作。
3. 获取当前地图文档所有打开的图层的IWorkspaceEdit接口对象。
4. 遍历所有的IWorkspaceEdit对象,通过调用其StopEditing方法来关闭已经打开的图层。
5. 结束编辑操作。
示例代码如下:
```
//获取当前地图文档对象
IMapDocument pMapDocument = new MapDocumentClass();
pMapDocument.Open("C:\\data\\test.mxd");
//获取当前地图文档的IWorkspace接口对象
IWorkspace pWorkspace = pMapDocument.ActiveView.FocusMap.Layer[0].FeatureClass.FeatureDataset.Workspace;
//判断地图文档是否在编辑状态,如果未处于编辑状态,则开启编辑操作
IWorkspaceEdit pWorkspaceEdit = pWorkspace as IWorkspaceEdit;
if (!pWorkspaceEdit.IsBeingEdited())
{
pWorkspaceEdit.StartEditing(true);
}
//获取所有打开的图层的IWorkspaceEdit接口对象,并关闭
for (int i = 0; i < pMapDocument.ActiveView.FocusMap.LayerCount; i++)
{
ILayer pLayer = pMapDocument.ActiveView.FocusMap.get_Layer(i);
IWorkspaceEdit pLayerWorkspaceEdit = (pLayer as IDataset).Workspace as IWorkspaceEdit;
if (pLayerWorkspaceEdit != null && pLayerWorkspaceEdit.IsBeingEdited())
{
pLayerWorkspaceEdit.StopEditing(true);
}
}
//结束编辑操作
if (pWorkspaceEdit.IsBeingEdited())
{
pWorkspaceEdit.StopEditing(true);
}
```
相关推荐
![audio/mpeg](https://img-home.csdnimg.cn/images/20210720083646.png)
不错的鼠标点击展开关闭层效果^_^
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
#box,#box2,#box3,#box4{padding:10px;border:1px solid green;}
</style>
<script type="text/javascript">
//=点击展开关闭效果=
function openShutManager(oSourceObj,oTargetObj,shutAble,oOpenTip,oShutTip){
var sourceObj = typeof oSourceObj == "string" ? document.getElementById(oSourceObj) : oSourceObj;
var targetObj = typeof oTargetObj == "string" ? document.getElementById(oTargetObj) : oTargetObj;
var openTip = oOpenTip || "";
var shutTip = oShutTip || "";
if(targetObj.style.display!="none"){
if(shutAble) return;
targetObj.style.display="none";
if(openTip && shutTip){
sourceObj.innerHTML = shutTip;
}
} else {
targetObj.style.display="block";
if(openTip && shutTip){
sourceObj.innerHTML = openTip;
}
}
}
</script>
<title>鼠标点击展开关闭层效果</title>
</head>
<body>
点击展开
这里面放的是box的内容.
点击展开
这里面放的是box的内容.
点击展开
这里面放的是box的内容.
<button onclick="openShutManager(this,'box4',false,'点击关闭','点击展开')">点击展开</button>
这里面放的是box的内容.
</body>
</html>
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)