I finally got around to taking a look at the SDK docs for Virtual Earth 6.1 and the feature list continues to grow and continues to impress, however rather than just dumping a list of new features, I’m going to write a few samples to demonstrate the new features.

New Map Options

First and foremost, the VEMap.LoadMap() method has slightly changed and includes the parameter mapOptions, which allows for greater customization of the map control. This property is of type VEMapOptions and implements the following properties:

  • EnableBirdseye: A Boolean property used to indicate whether Birdseye is available. If set to false the Birdseye map icon will be absent from the control.
  • EnableDashboardLabels: A Boolean property used to indicate whether or not labels appear on the map when a user clicks the Aerial or Birdseye map style buttons on the map control dashboard.

The code below demonstrates how this parameter can be specified when defining a new map, note that no other parameters of the VEMap.LoadMap() method are specified, thus we should set their value to null, unless of course we wish to define the other properties.

<script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1"></script>
<script type="text/javascript">
    function loadMap()
    {
        var map = new VEMap('veMap');
        
        var options = new VEMapOptions();
        options.EnableBirdseye = false;
        options.EnableDashboardLabels = false;
        
        map.LoadMap(null, null, null, null, null, null, null, options);
    }
</script>

The map control will not include the Birdseye option, as shown below.

image

Importing Google Earth KML Data

When indicating a KML document that should be loaded in Virtual Earth you must reference the URL. The document cannot be referenced as a local file, secondly the web server should be configured to deliver the KML document, that is, the mime type for the extension .kml should be set to application/vnd.google-earth.kml+xml. For example, consider that we wish to export our Sightseeing folder from Google Earth, host the KML on our web server and import the data into a Virtual Earth control.

Configuring KML MIME Type in IIS 7

First and foremost, we must ensure that the MIME type is setup for the .KML extension, this can be accomplished in IIS 7 by opening Internet Information Services Manager, selecting your web server or web site from the Connections pane and double clicking the MIME types icon, as shown below.

image

After the MIME types window opens, click the Add link from the Actions pane and enter the following details:

File Name Extension: kml
MIME Type: application/vnd.google-earth.kml+xml

As shown below:

image

Click the OK button.

Exporting Locations from Google Earth

We've got some great Sightseeing locations saved in the Sightseeing folder in Google Earth, we can use Google Earth to export the content of the folder to a KML document, host the document on our web server and import the KML data into Virtual Earth. To export the data from Google Earth let's go ahead and launch Google Earth, right click the Sightseeing folder from the Places window pane and select Save As, as shown below.

image

When the Save As window opens, ensure that the save as file type is KML. Save the file to any location and open the document in any text editor. We're going to configure the icon image URL before we upload the KML document to our web server. After the file has opened, directly beneath the <Document> element you should see a <Name> and <Style> element, the <Icon> element is a child of the <Style> element, here is where we can set our icon URL. The URL I'm using is:

http://virtualglobetrotting.com/images/icon.png

We can define the icon URL as shown below:

image

Save the changes and upload the KML document to your web server.

Importing the Data into Virtual Earth

We'll import the shape data into a new VEShapeLayer and then this layer can be added to the map. To do this, we can create an object of type VEShapeSourceSpecification and indicate the shape source, type and the optional layer the shapes should be imported into. This object has the following properties:

  • Type: A VEDataType enumeration used to indicate the source data type. Valid options are: ImportXML, GeoRSS and VECollection. For this example we're going to specify ImportXML as we wish to import KML data.
  • LayerSource: The URL pointing to the KML data source. Again, this should be an actual URL accessible from the Internet, not a local file nor a localhost web server.
  • Layer: An optional object of type VEShapeLayer. All VEShape objects are contained within this layer after importing them. If this property is NULL, the shape objects will be placed directly onto the map.

Finally, the VEMap.ImportShapeLayerData() method should be invoked, passing as arguments the VEShapeSourceSpecification object, along with an event handler method that will be invoked after the data has been imported and a Boolean value indicating whether or not the map should be scaled and positioned to best display the imported collection.

The code below demonstrates this.

<%@ Page Language="C#" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1"></script>
   1:  
   2:     <script type="text/javascript">
   3:         function loadMap()
   4:         {
   5:             var map = new VEMap('veMap');
   6:             map.LoadMap();
   7:             
   8:             // Import KML data
   9:             var layer = new VEShapeLayer();
  10:  
  11:             var sourceSpec = new VEShapeSourceSpecification(VEDataType.ImportXML, 
  12:                 'http://magmainteractive.net/kml/Sightseeing.kml', 
  13:                 layer);
  14:             
  15:             map.ImportShapeLayerData(sourceSpec, onFeedLoad, true);
  16:             
  17:         }
  18:         
  19:          function onFeedLoad(feed)
  20:          {
  21:             alert('KML data loaded! ' + feed.GetShapeCount());
  22:          }
  23:     
</script> </head> <body onload="loadMap()";> <form id="form1" runat="server"> <div id="veMap" style="position:absolute; width:750px; height:550px"></div> </form> </body> </html>

Note that the VEShapeLayer object created by the VEMap.ImportShapeLayerData() method will be passed to the indicated callback event handler. Finally, our application now looks something like that shown below.

image

Well, it look's like I'm out of time for now, I need to get some other stuff done, however I'll continue to blog about some of the new features in Visual Earth 6.1. Until then, don't forget to check out the MSDN SDK documentation for Virtual Earth 6.1!