PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/Main/src/DynamicDataDisplay.VirtualEarthDisplay/GlobeViewControl.xaml.cs

#
C# | 273 lines | 207 code | 30 blank | 36 comment | 17 complexity | 24e6a95073ed73180442653d84236479 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using Microsoft.MapPoint.Rendering3D;
  15. using System.Globalization;
  16. using System.Reflection;
  17. using Microsoft.MapPoint.PlugIns;
  18. using Microsoft.MapPoint.Rendering3D.NavigationControl;
  19. using Microsoft.MapPoint.Rendering3D.Utility;
  20. using System.Windows.Interop;
  21. using DynamicDataDisplay.VirtualEarthDisplay.Visualization;
  22. namespace DynamicDataDisplay.VirtualEarthDisplay
  23. {
  24. /// <summary>
  25. /// Interaction logic for GlobeViewControl.xaml
  26. /// </summary>
  27. public partial class GlobeViewControl : UserControl
  28. {
  29. private Requirements requirements;
  30. private VirtualEarthViewBase viewBase;
  31. private PlugInLoader loader;
  32. private bool doneLoading = false;
  33. private static bool userClose = false;
  34. private bool maximized = false;
  35. Window fullScreenWindow;
  36. private bool labelsOn = false;
  37. private bool roadViewOn = false;
  38. private DataVisualizationPlugin mainPlugin;
  39. public DataVisualizationPlugin MainPlugin
  40. {
  41. get { return mainPlugin; }
  42. }
  43. public GlobeViewControl()
  44. {
  45. InitializeComponent();
  46. requirements = new Requirements();
  47. //Check if VE3D is installed
  48. Type veCheckType = Type.GetTypeFromProgID("Microsoft.SentinelVirtualEarth3DProxy.SentinelVE3DProxy");
  49. if (veCheckType != null)
  50. {
  51. object veCheckObject = Activator.CreateInstance(veCheckType);
  52. object veVersion = veCheckType.InvokeMember("CurrentVersion", BindingFlags.GetProperty, null, veCheckObject, null);
  53. if (veVersion != null)
  54. {
  55. if (double.Parse(veVersion.ToString(), CultureInfo.InvariantCulture) > 4.0)
  56. {
  57. // create the control and set Forms properties.
  58. this.viewBase = new VirtualEarthViewBase();
  59. this.viewBase.Name = "globeControl";
  60. this.viewBase.TabIndex = 0;
  61. this.viewBase.SendToBack();
  62. mainHost.Child = viewBase;
  63. this.loader = PlugInLoader.CreateLoader(this.viewBase.Host);
  64. this.viewBase.Host.RenderEngine.Initialized += EngineInitialized;
  65. }
  66. else
  67. {
  68. this.Content = requirements;
  69. }
  70. }
  71. }
  72. else
  73. {
  74. this.Content = requirements;
  75. }
  76. }
  77. private void EngineInitialized(object sender, EventArgs e)
  78. {
  79. // at this point, the control is fully initialized and we can interact with it without worry.
  80. // set various data sources, here for elevation data, terrain data, and model data.
  81. this.viewBase.Host.DataSources.Add(new DataSourceLayerData("Elevation", "Elevation", @"http://maps.live.com//Manifests/HD.xml", DataSourceUsage.ElevationMap));
  82. this.viewBase.Host.DataSources.Add(new DataSourceLayerData("Texture", "Texture", @"http://maps.live.com//Manifests/AT.xml", DataSourceUsage.TextureMap));
  83. this.viewBase.Host.DataSources.Add(new DataSourceLayerData("Models", "Models", @"http://maps.live.com//Manifests/MO.xml", DataSourceUsage.Model));
  84. // set some visual display variables
  85. this.viewBase.Host.WorldEngine.Environment.AtmosphereDisplay = Microsoft.MapPoint.Rendering3D.Atmospherics.EnvironmentManager.AtmosphereStyle.Scattering;
  86. this.viewBase.Host.WorldEngine.Environment.CelestialDisplay = Microsoft.MapPoint.Rendering3D.Atmospherics.EnvironmentManager.CelestialStyle.Regular;
  87. this.viewBase.Host.RenderEngine.Graphics.Settings.UseAnisotropicFiltering = true;
  88. this.viewBase.Host.WorldEngine.Environment.SunPosition = null; // this means to use real-time lighting
  89. this.viewBase.Host.WorldEngine.EnableInertia = true;
  90. // Using this event is the proper way to handle loading and activation.
  91. this.viewBase.Host.CommunicationManager.AttachToEvent(EngineEvents.Group, EngineEvents.OnPlugInLoaded, "Loaded", PlugInLoaded);
  92. // Plug-ins can also be loaded by path to a dll, but this one is built-in se we reference by type.
  93. // If loading by path, it is possible to use both filesystem and http paths.
  94. // Also, if doing that it may be appropriate to execute the LoadPlugIn call on a worker thread,
  95. // and handle the result in OnPlugInLoaded.
  96. this.loader.LoadPlugIn(typeof(NavigationPlugIn));
  97. this.mainPlugin =
  98. this.loader.GetPlugInInfo(this.loader.LoadPlugIn(typeof(DataVisualizationPlugin))).PlugIn as DataVisualizationPlugin;
  99. doneLoading = true;
  100. }
  101. private void PlugInLoaded(string functionName, CommunicationParameter param)
  102. {
  103. CommunicationParameterSet set = (CommunicationParameterSet)param.Value;
  104. CommunicationParameter success;
  105. CommunicationParameter path;
  106. CommunicationParameter guid;
  107. if (set.TryGetValue("success", out success) &&
  108. set.TryGetValue("plugInPath", out path) &&
  109. set.TryGetValue("guid", out guid) &&
  110. (bool)success.Value == true)
  111. {
  112. this.loader.ActivatePlugIn(new Guid((string)guid.Value), null);
  113. }
  114. }
  115. public override string ToString()
  116. {
  117. return "Virtual Earth";
  118. }
  119. /// <summary>
  120. /// Enter Full Screen Mode
  121. /// </summary>
  122. /// <param name="sender"></param>
  123. /// <param name="e"></param>
  124. private void MenuButton_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  125. {
  126. if (!maximized)
  127. {
  128. fullScreenWindow = new Window();
  129. this.Content = new TextBlock { Text = "Control Content Maximized" };
  130. fullScreenWindow.Title = "Virtual Earth";
  131. fullScreenWindow.Loaded += delegate
  132. {
  133. HwndSource source = (HwndSource)PresentationSource.FromDependencyObject(fullScreenWindow);
  134. source.AddHook(WindowProc);
  135. };
  136. fullScreenWindow.Content = mainGrid;
  137. fullScreenWindow.WindowStyle = WindowStyle.None;
  138. fullScreenWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  139. fullScreenWindow.WindowState = WindowState.Maximized;
  140. fullScreenWindow.Closing += new System.ComponentModel.CancelEventHandler(w_Closing);
  141. maximized = true;
  142. fullScreenWindow.Show();
  143. }
  144. else
  145. {
  146. fullScreenWindow.Content = null;
  147. fullScreenWindow.Close();
  148. this.Content = mainGrid;
  149. maximized = false;
  150. }
  151. }
  152. /// <summary>
  153. /// Reset camera position
  154. /// </summary>
  155. /// <param name="sender"></param>
  156. /// <param name="e"></param>
  157. private void MenuButton_MouseLeftButtonUp_1(object sender, MouseButtonEventArgs e)
  158. {
  159. this.viewBase.Host.Navigation.FlyTo(LatLonAlt.CreateUsingDegrees(0, 0, 20000000), -90.0, 0.0);
  160. }
  161. /// <summary>
  162. /// Enable/Disable Labels
  163. /// </summary>
  164. /// <param name="sender"></param>
  165. /// <param name="e"></param>
  166. private void MenuButton_MouseLeftButtonUp_2(object sender, MouseButtonEventArgs e)
  167. {
  168. this.viewBase.Host.DataSources.Remove("Texture", "Texture");
  169. if (labelsOn)
  170. {
  171. this.viewBase.Host.DataSources.Add(new DataSourceLayerData("Texture", "Texture", @"http://maps.live.com//Manifests/AT.xml", DataSourceUsage.TextureMap));
  172. labelsOn = false;
  173. if (roadViewOn)
  174. roadViewOn = false;
  175. }
  176. else
  177. {
  178. this.viewBase.Host.DataSources.Add(new DataSourceLayerData("Texture", "Texture", @"http://maps.live.com//Manifests/HT.xml", DataSourceUsage.TextureMap));
  179. labelsOn = true;
  180. if (roadViewOn)
  181. roadViewOn = false;
  182. }
  183. }
  184. /// <summary>
  185. /// Enable/Disable Road View
  186. /// </summary>
  187. /// <param name="sender"></param>
  188. /// <param name="e"></param>
  189. private void MenuButton_MouseLeftButtonUp_3(object sender, MouseButtonEventArgs e)
  190. {
  191. this.viewBase.Host.DataSources.Remove("Texture", "Texture");
  192. if (!roadViewOn)
  193. {
  194. this.viewBase.Host.DataSources.Add(new DataSourceLayerData("Texture", "Texture", @"http://maps.live.com//Manifests/RT.xml", DataSourceUsage.TextureMap));
  195. roadViewOn = true;
  196. }
  197. else
  198. {
  199. if (labelsOn)
  200. {
  201. this.viewBase.Host.DataSources.Add(new DataSourceLayerData("Texture", "Texture", @"http://maps.live.com//Manifests/HT.xml", DataSourceUsage.TextureMap));
  202. }
  203. else
  204. {
  205. this.viewBase.Host.DataSources.Add(new DataSourceLayerData("Texture", "Texture", @"http://maps.live.com//Manifests/AT.xml", DataSourceUsage.TextureMap));
  206. }
  207. roadViewOn = false;
  208. }
  209. }
  210. private static IntPtr WindowProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
  211. {
  212. switch (msg)
  213. {
  214. case 0x112:
  215. if ((LOWORD((int)wParam) & 0xfff0) == 0xf060)
  216. userClose = true;
  217. break;
  218. default:
  219. break;
  220. }
  221. return IntPtr.Zero;
  222. }
  223. private static int LOWORD(int n)
  224. {
  225. return (n & 0xffff);
  226. }
  227. void w_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  228. {
  229. if (userClose)
  230. {
  231. e.Cancel = true;
  232. userClose = false;
  233. }
  234. }
  235. /// <summary>
  236. /// Indicates if VE Control was correctly initialized
  237. /// </summary>
  238. public bool DoneLoading
  239. {
  240. get { return doneLoading; }
  241. }
  242. }
  243. }