public bool AddDatasetLayer(IBasicMap pBasicMap, IGroupLayer pParentLayer, IDataset pDataset) { try { if ((pBasicMap == null) & (pParentLayer == null)) { return(false); } if (pDataset == null) { return(false); } Collection pLayersColl = new Collection(); if (!this.GetLayerFormDataset(pDataset, pLayersColl)) { return(false); } if (pLayersColl.Count <= 0) { return(false); } IMapLayers layers = pBasicMap as IMapLayers; foreach (ILayer layer in pLayersColl) { if (layer != null) { if (pParentLayer != null) { pParentLayer.Add(layer); } else { pBasicMap.AddLayer(layer); } if (pParentLayer == null) { layers.MoveLayer(layer, 0); } else if (pBasicMap is IMap) { layers.MoveLayerEx(pParentLayer, pParentLayer, layer, 0); } } } pLayersColl = null; return(true); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.LayerFun", "AddDataLayer", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }
public bool AddGroupLayer(IBasicMap pBasicMap, IGroupLayer pParentLayer, string sLayerName) { try { if (sLayerName == null) { sLayerName = ""; } if (pBasicMap == null) { return(false); } if (string.IsNullOrEmpty(sLayerName)) { sLayerName = "新建图层组"; } IGroupLayer pLayer = null; pLayer = new GroupLayerClass { Name = sLayerName }; if (pParentLayer == null) { pBasicMap.AddLayer(pLayer); } else { pParentLayer.Add(pLayer); } IMapLayers layers = pBasicMap as IMapLayers; if (pParentLayer == null) { layers.MoveLayer(pLayer, 0); } else if (pBasicMap is IMap) { layers.MoveLayerEx(pParentLayer, pParentLayer, pLayer, 0); } return(true); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.LayerFun", "AddGroupLayer", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }
public bool AddGraphicsLayer(IBasicMap pBasicMap, IGroupLayer pParentLayer, string sLayerName) { try { if (sLayerName == null) { sLayerName = ""; } if (pBasicMap == null) { return(false); } if (string.IsNullOrEmpty(sLayerName)) { sLayerName = "<新建图像图层>"; } IGraphicsLayer layer = null; if (this.FindGraphicsLayer(pBasicMap, sLayerName) == null) { layer = new CompositeGraphicsLayerClass(); ILayer layer2 = null; layer2 = layer as ILayer; layer2.Name = sLayerName; pBasicMap.AddLayer(layer as ILayer); IMapLayers layers = pBasicMap as IMapLayers; if (pParentLayer == null) { layers.MoveLayer(layer2, 0); } else if (pBasicMap is IMap) { layers.MoveLayerEx(pParentLayer, pParentLayer, layer2, 0); } } return(true); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.LayerFun", "AddGraphicsLayer", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }
public bool SetLayerPosition(IBasicMap pBasicMap, ILayer pSourceLayer, ILayer pTargetLayer) { try { if (pBasicMap == null) { return(false); } if (pSourceLayer == null) { return(false); } int num = 0; IGroupLayer pParentLayer = null; num = this.FindLayerPosition(pBasicMap, pSourceLayer, ref pParentLayer); if (num == -1) { return(false); } int toIndex = 0; IGroupLayer layer2 = null; if (pTargetLayer == null) { toIndex = 0; layer2 = null; } else if (pTargetLayer is IGroupLayer) { toIndex = 0; layer2 = pTargetLayer as IGroupLayer; } else { toIndex = this.FindLayerPosition(pBasicMap, pTargetLayer, ref layer2) + 1; } if (object.Equals(pParentLayer, layer2)) { if (num == toIndex) { return(false); } if (num < toIndex) { toIndex--; } } IMapLayers layers = pBasicMap as IMapLayers; if ((pParentLayer == null) & (layer2 == null)) { layers.MoveLayer(pSourceLayer, toIndex); } else if (pBasicMap is IMap) { layers.MoveLayerEx(pParentLayer, layer2, pSourceLayer, toIndex); } else { return(false); } return(true); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.LayerFun", "SetLayerPosition", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }
public bool AddGxFileLayer(IBasicMap pBasicMap, IGroupLayer pParentLayer, string sFileName) { try { if (sFileName == null) { sFileName = ""; } if (pBasicMap == null) { return(false); } if (string.IsNullOrEmpty(sFileName)) { OpenFileDialog dialog = new OpenFileDialog { Filter = "图层文件 (*.lyr)|*.lyr", Multiselect = false, Title = "选择输入的图层文件" }; if (dialog.ShowDialog() != DialogResult.OK) { return(false); } sFileName = dialog.FileName; dialog = null; } if (string.IsNullOrEmpty(sFileName)) { return(false); } if (!File.Exists(sFileName)) { Interaction.MsgBox("地图图层加载失败,图层文件 " + sFileName + " 不存在。", MsgBoxStyle.Exclamation, "错误警告"); return(false); } IMapDocument document = null; document = new MapDocumentClass(); if (!document.get_IsMapDocument(sFileName)) { Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n文件不是 MapDocument 文件。", MsgBoxStyle.Exclamation, "失败"); return(false); } if (document.get_IsRestricted(sFileName)) { Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n文件受到限制,无权使用。", MsgBoxStyle.Exclamation, "失败"); return(false); } document.Open(sFileName, null); ILayer pLayer = null; if (document.DocumentType == esriMapDocumentType.esriMapDocumentTypeLyr) { pLayer = document.get_Layer(0, 0); if (pLayer == null) { Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n图层文件或数据错误。", MsgBoxStyle.Exclamation, "加载失败"); } } else { Interaction.MsgBox("文件 " + sFileName + " 无法加载。\r\n文件不是地图图层文件。", MsgBoxStyle.Exclamation, "加载失败"); } document.Close(); document = null; if (pLayer == null) { return(false); } if (pParentLayer == null) { pBasicMap.AddLayer(pLayer); } else { pParentLayer.Add(pLayer); } IMapLayers layers = pBasicMap as IMapLayers; if (pParentLayer == null) { layers.MoveLayer(pLayer, 0); } else if (pBasicMap is IMap) { layers.MoveLayerEx(pParentLayer, pParentLayer, pLayer, 0); } return(true); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.LayerFun", "AddGxFileLayer", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }