123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
-
- using System.IO;
- using System.Reflection;
- using Tofly.Core.Stereotype;
- using Tofly.Core.Util;
- using Tofly.Core.Context;
- using Tofly.Core.Context.Support;
- using Tofly.CoreUI.Plot;
- using Tofly.CoreUI.Control;
- using Tofly.GISUI.Content;
- using Tofly.GISUI.Controls;
- using Tofly.Core.ServiceLocator;
- using Tofly.GISUI.Win.ArcGIS.Content;
- namespace Tofly.GISUI.Win.ArcGIS.License
- {
- [Component(IsSingleton = "false", Name = "InitMapDocument")]
- public class InitMapDocument : IBuildItem
- {
- #region IBuildItem 成员
- private string name = "初始化地图文档";
- private string str_tempMdbPath = PathUtil.GetMainPath() + @"\ToflyTemp.mdb";
- public string Name
- {
- get { return name; }
- }
- private int index = 300;
- public int Index
- {
- get { return index; }
- set { index = value; }
- }
- private IPluginContent plugincontent = null;
- public void Build(IPluginContent content)
- {
- plugincontent = content;
- content.ServiceLocator.SetInstance<IDocumentContent>(null, ServiceLocatorKeys.DocumentContent);
- IApplicationContext context = ContextRegistry.GetContext();
- string path = PathUtil.GetMainPath();
- GIS.Carto.IMapDocument mapDocument_Tofly = context.GetObject("GIS_MapDocumentClass") as GIS.Carto.IMapDocument;
- FileInfo info_Tofly = new FileInfo(path + @"\temp.Mxd");
- if (!info_Tofly.Exists)
- {
- mapDocument_Tofly.New(path + @"\temp.Mxd");
- mapDocument_Tofly.Save(true, true);
- mapDocument_Tofly.Close();
- mapDocument_Tofly.Open(path + @"\temp.Mxd", "");
- }
- else
- {
-
- mapDocument_Tofly.Open(path + @"\temp.Mxd", "");
- if (mapDocument_Tofly.ActiveView.FocusMap.LayerCount > 0)
- {
- mapDocument_Tofly.ActiveView.FocusMap.ClearLayers();
- mapDocument_Tofly.ActiveView.FocusMap.SpatialReference = null;
- }
-
- Tofly.GIS.Carto.IGraphicsContainer ipGraphicsContainer = mapDocument_Tofly.ActiveView as Tofly.GIS.Carto.IGraphicsContainer;
- ipGraphicsContainer.DeleteAllElements();
- }
- mapDocument_Tofly.ActiveView.FocusMap.Name = "图层";
- IMapControl mapcontrol = content.ServiceLocator.GetInstance<IControl>(ServiceLocatorKeys.MapControl) as IMapControl;
-
- if (mapcontrol != null)
- {
-
- content.ServiceLocator.SetInstance<string>("", ServiceLocatorKeys.CurrFun);
- var pOpenMap = new FileUI.Common.ConvertBase.OpenMapConvertBaseClass(str_tempMdbPath, mapDocument_Tofly);
- pOpenMap.RepalceLayersByMap();
- content.ServiceLocator.SetInstance(mapDocument_Tofly, ServiceLocatorKeys.MapDocument);
- mapcontrol.Map = mapDocument_Tofly.ActiveView.FocusMap;
- mapcontrol.ShowScrollbars = false;
- mapcontrol.AutoMouseWheel = false;
- mapcontrol.CurrentTool = null;
- }
-
- content.ServiceLocator.SetInstance(ContextRegistry.GetContext().GetObject("IDocumentContent",
- new object[] { mapDocument_Tofly}) as IDocumentContent,ServiceLocatorKeys.DocumentContent);
- content.ServiceLocator.ServiceValueChange += ServiceLocator_ServiceValueChange;
- }
- private void ServiceLocator_ServiceValueChange(string key, object value)
- {
- if (key.Contains(ServiceLocatorKeys.MapDocument))
- {
- IDocumentContent content = ContextRegistry.GetContext().GetObject("IDocumentContent", new object[] { value as GIS.Carto.IMapDocument }) as IDocumentContent;
- plugincontent.ServiceLocator.SetInstance(content, ServiceLocatorKeys.DocumentContent);
- content.UpdateDocument();
- content.ActiveViewContent.IsFixedScale = false;
- content.ActiveViewContent.IsFiexdExtent = false;
- }
- }
- #endregion
- }
- }
|