Virtual Earth Map Control
Creating Your First VE Web Page
It's pretty simple to add the VE Map Control to a web page and use it to instantiate an instance of the VEMap class. Here's the basic HTML needed in order to create such a page...
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
var map = null;
map = new VEMap('myMap');
if (map != null) map.Dispose();
<body onload="startVE();" onunload="cleanUp();" style="margin: 0px">
<div style="overflow: hidden; width: 100%; height: 100%;" id="myMap" />
You should note that the first script tag specifies the web handler mapcontrol.ashx as the source. Also, note how an instance of VEMap is created using the body's onload and is eventually disposed of in the cleanUp() function via the body's onunload. In any event, it's pretty easy stuff given the results (go ahead and cut and paste that bit of code into an HTML file and view it in Internet Explorer).
What About Desktop Applications?
Virtual Earth Wrapper for VFP
OK, so the previous section outlines the thought process that eventually lead to the class library that I built to tackle these problems. While working on a VFP project for a customer that involved VE, I looked at that list of classes and enumerations for the Virtual Earth Map Control version 6.2 and basically thought, "Wouldn't it be super cool if those were all VFP classes??!!".
As you'll see in the download, the class library wrapper (virtualearth.vcx) is pretty much a carbon copy of the VE classes. So, most of the documentation and code that's online for VE is of benefit when using it. In addition to the virtualearth.vcx, I've also provided a sample project and form (see screenshot below), so you can try this stuff out right away. The sample project is also intended to provide a little more information regarding how to do some of the things that a developer might want to do with VE in a desktop application. I usually find that learning by example is one of the fastest ways to get up to speed on a technology I'm not very familiar with.
Special Thank You
Before I wrap this blog entry up, I want to express my appreciation for Marc Lyon's efforts. He provided me early feedback and testing for this class library. His enthusiasm for this project was also one of the driving forces behind my completing it as fast as I did.
I also want to thank my client (you know who you are) who has been kind enough to allow me to share this work with the VFP Community. You're about as generous and kind as they come.
Just have fun with Virtual Earth in VFP and see if virtualearth.vcx is useful to you and your applications. In a perfect world, you'd report back to me with any bugs you find, create some examples of your own and blog about them, or seek to improve the library in some way. If you do improve virtualearth.vcx, I'd appreciate it if you would contact me and share the improvements you've implemented. Thank you in advanced to those of you that decide to follow any of the above suggestions.
Until next time... Visual FoxPro Rocks!
Download VirtualEarth.vcx and Sample (approx. 222 KB)
Figure 1: A sample form provided in the download. It gives developers a starting point when beginning to work with the virtualearth.vcx.