using SuperMap.Data; using SuperMap.Mapping; using SuperMap.UI; using System.Windows.Forms; namespace WWPipeLine.Map { public class WorkSpaceEx { /// /// 打开工作空间,地图,鹰眼 /// /// /// /// public void OpenMap(MapControl mapControl, MapControl mapControlEagleEye, string lastPath = "") { OpenFileDialog dialog = new OpenFileDialog { Multiselect = true,//该值确定是否可以选择多个文件 Title = "请选择管线工作空间", Filter = "SuperMap 工作空间文件|*.smwu;*.sxwu" }; if (!string.IsNullOrEmpty(lastPath) && System.IO.File.Exists(lastPath)) { Open(lastPath); return; } if (dialog.ShowDialog() == DialogResult.OK) { string file = dialog.FileName; Open(file); Commons.SerializeHelper.IniHelper.Write(Commons.SerializeHelper.IniHelper.KEY_LAST_WORKSPACE_PATH, file); } void Open(string path) { Workspace ws = new Workspace(); WorkspaceConnectionInfo workspaceConnectionInfo = new WorkspaceConnectionInfo(path); if (ws.Open(workspaceConnectionInfo)) { mapControl.Map.Workspace = ws; var mapName = ws.Maps[0]; mapControl.Map.Open(mapName); mapControl.Action = SuperMap.UI.Action.Pan; mapControl.Map.Refresh(); //鹰眼的配置 mapControlEagleEye.Map.Workspace = ws; mapControlEagleEye.Map.Open(mapName); mapControlEagleEye.Map.Layers.Remove("JSLK@CL_PostGreSQL#1"); mapControlEagleEye.Map.Layers.Remove("JSLK@CL_PostGreSQL"); mapControlEagleEye.Map.Layers.Remove("JSJDPT@CL_PostGreSQL"); foreach (Layer layer in mapControlEagleEye.Map.Layers) { layer.IsSelectable = false; layer.IsEditable = false; } mapControlEagleEye.Map.ViewEntire(); mapControlEagleEye.Map.Refresh(); mapControlEagleEye.MarginPanEnabled = false; mapControlEagleEye.IsWaitCursorEnabled = false; mapControlEagleEye.InteractionMode = InteractionMode.CustomAll; mapControlEagleEye.Cursor = Cursors.Arrow; } else { MessageBox.Show("打开工作空间失败"); } } } /// /// 关闭工作空间,地图,鹰眼 /// /// /// public void CloseMap(MapControl mapControl, MapControl mapControlOfEagleEye) { mapControl.Map.Close(); mapControlOfEagleEye.Map.Close(); mapControl.Dispose(); mapControlOfEagleEye.Dispose(); if (mapControl.Map.Workspace != null) { mapControl.Map.Workspace.Close(); mapControl.Map.Workspace.Dispose(); } if (mapControlOfEagleEye.Map.Workspace != null) { mapControlOfEagleEye.Map.Workspace.Close(); mapControlOfEagleEye.Map.Workspace.Dispose(); } } } }