Adding a Virtual Earth 3D Plug-in to your webpage
Note: this entry references code for an older version of VE3D. The newest code samples are here.
Want to try custom code for the 3D view of Virtual Earth? This is the place to find out how!
What do I need?
· Virtual Earth 3D installed. Navigate to maps.live.com, click the 3D button, and follow the upgrade/install steps.
· Visual Studio 2005 or higher and some c# coding skills (any .NET language actually, but samples will be in C#).
· This package.
If you do not have Visual Studio installed, you can download a free version of Visual Studio 2008 here. See notes at the end of the post for details.
Extract the samples zip to c:\Samples (or any other directory, but you'll have to fix up some paths in the projects). There's a Readme, but you should be able to just open the sln in Visual Studio, set one of the projects to the Startup project, and hit F5. For this post, we'll just talk about the basics of how the plug-in will be loaded.
Try building and launching the project SimpleObjectPlacement.
By default, you'll get an IE window with a script warning. This only happens because we're loading the html off the local drive, and will not happen if we point to a web server.
You can change startup behavior by modifying the values in the Debug pane of the project.
Once there you should see the globe, and after a moment it will zoom to off the coast of Africa to see a floating cube.
map = new VEMap('myMap');
map.LoadMap(null, 2, 'a', false, VEMapMode.Mode3D);
control3D = map.vemapcontrol.Get3DControl();
Events are just callbacks when certain things happen. In this case, when a plug-in is finished loading the SDK will try to call a function called "On3DPlugInLoaded". It has to be this way because the LoadPlugInDll method is asynchronous -- otherwise we'd have to sit and wait for loading to complete, causing a negative user experience. But you don't have to worry much about this, just know that you can listen to events and you'll be called when things happen. You can also fire your own events, which we'll get to later. In this case, if you look at the handler you'll see when we finish loading the plug-in we'll activate it. We could do more, but this is the minimum.
You can specify a plug-in to load in two ways. First is like this, with a local file path. Second is by specifying the fully qualified name. Either method requires that the plug-in be installed in the GAC, which is an unfortunate security limitation that we hope to relax in the future. You can get installed into the GAC by using utilities that come with VS, or by writing an MSI installer. We'll get into more on that later. All the samples here install their output into the GAC as a post-build step to help you get past these details.
When the plug-in is loaded, then we start executing the C# code. If you put breakpoints in SimpleObjectPlugIn.cs, you'll see it gets a call to the constructor, and then one to the Activate function. In a future post we'll walk through the details of what happens next, how the cube gets into the world, and why it changes color when you mouse over it. In the meantime, try playing with the other samples. Let us know what you think, and please enjoy.
Notes on VS 2008 and VS 2008 Express:
If you use either of these, you'll have to run the solution upgrade wizard. It should be painless, but you may encounter some of the following issues:
VS 2008 Full and Express:
If you get errors on build about gacutil and return code 3, you may need to update the path in the project pre- and post-build steps to "$(DevEnvDir)..\..\..\Microsoft SDKs\Windows\v6.0A\bin\gacutil".
VS 2008 Express:
A message about a property not supported. This is related to the last point below, and can be ignored.
A message about Solution Items not supported (VS Express). This is just the readme file and can be ignored (you can still read the readme by just navigating to c:\samples).
Express only builds to the Release bin path, so the html files (TestPage.htm) need to be updated such that the LoadPlugInDll call points to bin\\Release instead of bin\\Debug.
VS Express doesn't support debugging a different process than the one launched. This is tricky because plug-ins run in the browser's process. To run the plug-in samples you'll need to build the project, and then run the html file manually in your favorite browser. However, you can debug a forms app as normal, so you can work around this by debugging your code inside the SimpleForm sample, and then copying to the plug-in. We apologize for this inconvenience, but it was free after all ;)
The intellisense files in the samples zip have been updated to be more complete.