InitMapDocument.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //======================================================================
  2. //
  3. //
  4. //
  5. // CLR 版本: 4.0.30319.269
  6. // 命名空间: Tofly.GISUI.Win.ArcGIS9.License
  7. // 类 名: InitMapDocument
  8. // 创 建 人: 宋 刘 陈
  9. // 创建时间: 2012-11-17 9:49:20
  10. // 修 改 人:
  11. // 修改时间:
  12. //
  13. //======================================================================
  14. using System.IO;
  15. using System.Reflection;
  16. using Tofly.Core.Stereotype;
  17. using Tofly.Core.Util;
  18. using Tofly.Core.Context;
  19. using Tofly.Core.Context.Support;
  20. using Tofly.CoreUI.Plot;
  21. using Tofly.CoreUI.Control;
  22. using Tofly.GISUI.Content;
  23. using Tofly.GISUI.Controls;
  24. using Tofly.Core.ServiceLocator;
  25. using Tofly.GISUI.Win.ArcGIS.Content;
  26. namespace Tofly.GISUI.Win.ArcGIS.License
  27. {
  28. [Component(IsSingleton = "false", Name = "InitMapDocument")]
  29. public class InitMapDocument : IBuildItem
  30. {
  31. #region IBuildItem 成员
  32. private string name = "初始化地图文档";
  33. private string str_tempMdbPath = PathUtil.GetMainPath() + @"\ToflyTemp.mdb";
  34. public string Name
  35. {
  36. get { return name; }
  37. }
  38. private int index = 300;
  39. public int Index
  40. {
  41. get { return index; }
  42. set { index = value; }
  43. }
  44. private IPluginContent plugincontent = null;
  45. public void Build(IPluginContent content)
  46. {
  47. plugincontent = content;
  48. content.ServiceLocator.SetInstance<IDocumentContent>(null, ServiceLocatorKeys.DocumentContent);
  49. IApplicationContext context = ContextRegistry.GetContext();
  50. string path = PathUtil.GetMainPath();
  51. GIS.Carto.IMapDocument mapDocument_Tofly = context.GetObject("GIS_MapDocumentClass") as GIS.Carto.IMapDocument;
  52. FileInfo info_Tofly = new FileInfo(path + @"\temp.Mxd");
  53. if (!info_Tofly.Exists)
  54. {
  55. mapDocument_Tofly.New(path + @"\temp.Mxd");
  56. mapDocument_Tofly.Save(true, true);
  57. mapDocument_Tofly.Close();
  58. mapDocument_Tofly.Open(path + @"\temp.Mxd", "");
  59. }
  60. else
  61. {
  62. //TODO:song 解决默认地图文档里面有图层的问题
  63. mapDocument_Tofly.Open(path + @"\temp.Mxd", "");
  64. if (mapDocument_Tofly.ActiveView.FocusMap.LayerCount > 0)
  65. {
  66. mapDocument_Tofly.ActiveView.FocusMap.ClearLayers();
  67. mapDocument_Tofly.ActiveView.FocusMap.SpatialReference = null;
  68. }
  69. //TODO:song 解决默认地图文档中有元素的问题
  70. Tofly.GIS.Carto.IGraphicsContainer ipGraphicsContainer = mapDocument_Tofly.ActiveView as Tofly.GIS.Carto.IGraphicsContainer;//元素容器
  71. ipGraphicsContainer.DeleteAllElements();
  72. }
  73. mapDocument_Tofly.ActiveView.FocusMap.Name = "图层";
  74. IMapControl mapcontrol = content.ServiceLocator.GetInstance<IControl>(ServiceLocatorKeys.MapControl) as IMapControl;
  75. //Add By huakun 加入自己封装的接口
  76. if (mapcontrol != null)
  77. {
  78. //初始化地图默认工具
  79. content.ServiceLocator.SetInstance<string>("", ServiceLocatorKeys.CurrFun);
  80. var pOpenMap = new FileUI.Common.ConvertBase.OpenMapConvertBaseClass(str_tempMdbPath, mapDocument_Tofly);
  81. pOpenMap.RepalceLayersByMap();
  82. content.ServiceLocator.SetInstance(mapDocument_Tofly, ServiceLocatorKeys.MapDocument);
  83. mapcontrol.Map = mapDocument_Tofly.ActiveView.FocusMap;
  84. mapcontrol.ShowScrollbars = false;
  85. mapcontrol.AutoMouseWheel = false;
  86. mapcontrol.CurrentTool = null;
  87. }
  88. content.ServiceLocator.SetInstance(ContextRegistry.GetContext().GetObject("IDocumentContent",
  89. new object[] { mapDocument_Tofly}) as IDocumentContent,ServiceLocatorKeys.DocumentContent);
  90. content.ServiceLocator.ServiceValueChange += ServiceLocator_ServiceValueChange;
  91. }
  92. private void ServiceLocator_ServiceValueChange(string key, object value)
  93. {
  94. if (key.Contains(ServiceLocatorKeys.MapDocument))
  95. {
  96. IDocumentContent content = ContextRegistry.GetContext().GetObject("IDocumentContent", new object[] { value as GIS.Carto.IMapDocument }) as IDocumentContent;
  97. plugincontent.ServiceLocator.SetInstance(content, ServiceLocatorKeys.DocumentContent);
  98. content.UpdateDocument();
  99. content.ActiveViewContent.IsFixedScale = false;
  100. content.ActiveViewContent.IsFiexdExtent = false;
  101. }
  102. }
  103. #endregion
  104. }
  105. }