如何组织AxTOCControl里面的数据,实际上是组织AXMapControl的数据,将添加的数据进行整理。代码在最后面。
思路参考自:
https://blog.csdn.net/u012488787/article/details/39028813 ,比想象的简单的多
加载图层事件:
http://zhihu.esrichina.com.cn/question/20551
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//004900000051000000
http://blog.sciencenet.cn/blog-971075-1016456.html
#region 图层分组方法 private void UpdateTOCControlLayers(AxMapControl axMap) { if (axMap.Map.LayerCount == 0) { return; } IMapLayers mapLayers = axMap.Map as IMapLayers; //设置axtoccontrol的首层名称为“图层” axMap.Map.Name = "图层"; List<string> listGroupLyrNames = new List<string>() { "总规", "分规", "控规"}; foreach (string groupLayerName in listGroupLyrNames) { IGroupLayer basemapGroupLayer = new GroupLayerClass(); basemapGroupLayer.Name = groupLayerName; axMap.Map.AddLayer(basemapGroupLayer); //将所有要素图层作为二级目录 IEnumLayer enumLayer = LayersGetUtil.GetEnumLayer(axMapControl1.Map); enumLayer.Reset(); ILayer layer = enumLayer.Next(); while (layer != null) { //如果图层名截取的字符串跟图层组名称相同 if (GetGroupNameOfLayer(layer) == groupLayerName) { mapLayers.MoveLayerEx(null, basemapGroupLayer, layer, 0); } layer = enumLayer.Next(); } basemapGroupLayer.Expanded = false; } } private string GetGroupNameOfLayer(ILayer layer) { string matchGroupName = null; IDataLayer dataLayer = layer as IDataLayer; IDatasetName datasetName = dataLayer.DataSourceName as IDatasetName; string groupName = datasetName.Name.Substring(0, 2); switch (groupName.ToUpper()) { case "ZG": matchGroupName = "总规"; break; case "FG": matchGroupName = "分规"; break; case "KG": matchGroupName = "控规"; break; default: break; } return matchGroupName; } #endregion