Load 3D map control at a specific location

In the latest release of the 3D map control some new properties were added that allow you to specify where the map should appear when loading. The benefit of this is that the map will load at a specific location where as before you had to load the map and see the whole globe then call the FlyTo method to fly to your location. The properties are called StartAltitude, StartPitch, StartHeading, StartLongitude, and StartLatitude. To set these properties you should use an event handler on the RenderEngine.Initialized event. For example:

this.globeControl.Host.RenderEngine.Initialized += new EventHandler(Initialized);

Inside the method that gets called by the Initialized event the data sources, and the initial location information can be loaded:

private void Initialized(object sender, EventArgs e)
           // at this point, the control is fully initialized and we can interact with it without worry.

           // set various data sources, here for elevation data, terrain data, and model data.
           this.globeControl.Host.DataSources.Add(new DataSourceLayerData("Elevation", "Elevation", @"http://go.microsoft.com/fwlink/?LinkID=98774", DataSourceUsage.ElevationMap));
           this.globeControl.Host.DataSources.Add(new DataSourceLayerData("Texture", "Texture", @"http://go.microsoft.com/fwlink/?LinkID=98772", DataSourceUsage.TextureMap));
           this.globeControl.Host.DataSources.Add(new DataSourceLayerData("Models", "Models", @"http://go.microsoft.com/fwlink/?LinkID=98775", DataSourceUsage.Model));

           //Set the intial globe position
           this.globeControl.StartAltitude = 0;
           this.globeControl.StartPitch = -14;
           this.globeControl.StartHeading = 89.42;
           this.globeControl.StartLongitude = -115.12571;
           this.globeControl.StartLatitude = 36.07639;

           // Using this event is the proper way to handle loading and activation.
           this.globeControl.Host.CommunicationManager.AttachToEvent(EngineEvents.Group, EngineEvents.OnPlugInLoaded, "Loaded", PlugInLoaded);

           // Plug-ins can also be loaded by path to a dll, but this one is built-in se we reference by type.
           // If loading by path, it is possible to use both filesystem and http paths.
           // Also, if doing that it may be appropriate to execute the LoadPlugIn call on a worker thread,
           // and handle the result in OnPlugInLoaded.
           Guid g = this.loader.LoadPlugIn(typeof(NavigationPlugIn));           


WinForm application that demonstrates how to do this has been uploaded here: http://cid-e7dba9a4bfd458c5.skydrive.live.com/self.aspx/VE%20Sample%20code/VE3DFlyToExample%7C_WinForm.zip


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s