Virtual Earth—What’s New in the Latest Release

ow in its sixth major release, Virtual Earth offers an entire world of opportunities for innovative web-based mapping. Whether you sell real estate, track assets, need a store locator, or simply have some data you want to map, Microsoft Virtual Earth is ready to provide a stable, high-performance, accurate, and engaging web-based experience for your clients.

The Virtual Earth (VE) platform combines a JavaScript library, a rich set of mapping data and imagery, a set of web services, and a powerful 3D control. Getting started with the platform is trivial; a simple HTML web page is all you need to access VE’s powerful AJAX mapping features. Listing 1 shows a basic “Hello world” 2D example.

The power of the 2D interface comes from JavaScript manipulating the HTML DOM and making AJAX calls directly to Microsoft’s web servers. The interface requires no plug-ins and, in version 6, supports Internet Explorer 6, 7, Firefox 2, and Safari 2. The 3D control installs on demand, supports Internet Explorer and Firefox on Windows-based machines with adequate 3D hardware, and provides users with a seamless “in-browser” experience.

Virtual Earth code development is not tied to any server side technology. As demonstrated in Listing 1, the control relies only on HTML and JavaScript, so you can develop in your favorite editor. Although one obvious IDE/language choice is Microsoft Visual Studio and the ASP.NET AJAX extensions, you can achieve identical results using PHP and other AJAX frameworks?the choice is yours.

New Navigation with a New Default Dashboard
The new navigation dashboard (see Figure 1) provides all the default navigation functionality, including zooming, panning, and changing map styles and map modes. Revamped in nearly every version so far, the latest control has a minimalist look and a smaller download footprint. Users can minimize the control if they need more screen real estate for their current map application.

?
Figure 1. The Default Virtual Earth Dashboard: The default dashboard provides basic navigation functions.

VE has three built-in dashboards you can choose from. You can also turn off VE’s dashboards completely and create your own. To change to a different built-in dashboard, you set the dashboard before you load the map as follows:

   map = new VEMap('myMap');   map.SetDashboardSize(VEDashboardSize.Tiny);   map.LoadMap();

Photosynth-Style Bird’s Eye Images in 3D
The bird’s eye images within Virtual Earth are truly amazing. These are oblique images taken from a low angle that provide high-resolution images of all four sides of a scene. Popular with real estate applications, these images compliment the familiar straight-down orthogonal images, providing far more location detail than simply looking at rooftops.

Incorporating these images in 3D mode is a new feature in Virtual Earth. With an interface style directly based on the upcoming Microsoft Photosynth, users visually select high-resolution scenes to be loaded into the 3D space. When combined with the existing (and ever-expanding) 3D models, the photosynth feature provides developers with an innovative experience to use in their own applications. Figure 2 shows a bird’s eye scene loaded over a set of 3D buildings in New York. Note the outline of surrounding images easily selectable by the user.

?
Figure 2. Photosynth Image: The figure shows Photosynth-style navigation of bird’s eye images in Virtual Earth 3D.

Author’s Note: Here’s a tip: Use the keyboard arrow keys and the dashboard rotate buttons to navigate between the photosynth images seamlessly. You can preview this amazing functionality at http://maps.live.com.

Developers get two new bird’s eye methods in the traditional 2D mode. The first is GetBoundingRectangle():

   VEBirdseyeScene.GetBoundingRectangle();

This method returns an oversized approximation of the bounds of the current scene, which is perfect if you need to query for data within the current scene. For example, you could use the bounding latitude and longitude values returned from this method to query a database for records that lie within this bird’s eye scene, thus loading the records for display in Virtual Earth on demand, and improving your application’s performance.

Unfortunately, due to licensing restrictions, you cannot access exact latitude and longitude values from bird’s eye images.

The second method is:

   VEMap.SetBirdseyeScene(veLatLong,   orientation,zoomLevel,callback); 

This method lets you request a bird’s eye scene based on a latitude/longitude coordinate and zoom level.

To facilitate highly accurate shape placement within bird’s eye scenes, Microsoft has added several new methods. Firstly, you can configure a “shapes accuracy” policy using the method VEMap.SetShapesAccuracy(policy). The options are:

  • None: No shapes are accurately converted (default).
  • Pushpin: Only pushpins are accurately converted.
  • All: All shapes are accurately converted.

Secondly, you can configure the number of shapes to convert accurately using VEMap.SetShapesAccuracyRequestLimit(number). The default is 50. This process is slow, so you should use it only where absolutely required.

Editor’s Note: This article was first published in Code Focus magazine, and is reprinted here by permission.

Create Your Own 3D Models
Virtual Earth has had world-class, highly accurate, 3D models for some time. Now, thanks to a partnership with Dassault, the new 3DVIA technology allows you to create your own models within Virtual Earth just like Figure 3. The application allows you to build your 3D model in a simple environment and add either built-in textures or your own. This allows you to capture an image yourself for use on your custom model.

?
Figure 3. Building a 3D model in 3DVIA: Here’s a basic house with textures generated from a 3D model.

The models themselves are stored at http://maps.live.com in a personal “collection,” and you can add them to your own map by importing that collection as a layer as follows:

The new 3DVIA technology allows you to create your own models within Virtual Earth.
   var l = new VEShapeLayer();   var veLayerSpec = new   VEShapeSourceSpecification(      VEDataType.VECollection,       "54139577DC329980!625", l);   map.ImportShapeLayerData(      veLayerSpec,null,false);

Routing Now Supports Multiple Points

?
Figure 4. Getting Directions: Here’s a route with turn-by-turn directions.

Do you want to enhance your application by letting your users get visual and textual map directions? Great news, the Virtual Earth routing functions have had a complete makeover for version 6.

Routing will overlay a line along the streets and roads and provide turn-by-turn instructions for your selected route, see Figure 4 for an example. The new method VEMap.GetDirections() accepts an array of locations for true multi-point routing and the return method gives a wealth of information about the resulting route, including distances and estimated time. You can format this information into turn-by-turn directions. Listing 2 provides a simple example.

Importantly, the objects added to the map are true VEShape classes. Virtual Earth no longer uses the old VEPushpin, VEPolygon and VEPolyline classes.

The GetDirections method allows you to specify the following options:

  • Whether to display measurements in kilometers or miles
  • Whether to draw the route on the map
  • Route line color
  • The line weight (thickness)
  • Line Zindex (above or below other objects)
  • Whether to set the map view to best fit the route
  • Whether to show a disambiguation dialog box if it can’t determine any of the supplied locations
  • Whether to show error messages
?
Figure 5. Traffic Flow in San Francisco: The overlaid lines show typical traffic flow in the city of San Francisco.

Traffic Overlays Anyone?
Being able to plot a route is great, but how about overlaying the latest traffic flow data, as shown in Figure 5?

VE supports such traffic-flow mapping in an ever-growing number of cities. It’s as simple to use as adding one line of code:

   map.LoadTraffic(true);

You can easily show a built-in legend to explain the colors (customizable options include the title and the position of the legend on the map):

   map.LoadTraffic(true);   map.ShowTrafficLegend(200, 200);   map.SetTrafficLegendText("myTraffic");

Support for SSL (Encrypted, Secure) Web Sites
Virtual Earth targets commercial applications with accurate and feature-rich functionality. Version 6 now supports HTTPS for the growing number of enterprise, e-commerce, and membership applications that require this level of security for communications. Previously, if your site ran under SSL, you either had to redirect to another page or your users had to put up with mixed-content warning messages.

You need to make two changes to the Virtual Earth script URL to enable SSL. First, change the protocol to SSL; second, add a query parameter of s=1. Here’s the complete modified script URL:

   
Author’s Note: SSL functionality is available only to paying Virtual Earth customers at this time.

Localization, First Steps
Microsoft must address a number of different areas to fully localize Virtual Earth. These include the control text, the map tiles themselves, and the web service results. Version 6 provides the first steps towards localization by providing localized direction information for routing. It takes two changes to enable localized results. First, you add a locale query parameter to the Virtual Earth script URL. For example, to localize to French (fr-fr), you would write:

   

Table 1 gives the complete list of supported locales.

Table 1: A complete list of supported locales.

Description

Code

English, Canada

en-ca

English, Great Britain

en-gb

English, United States

en-us

Japanese, Japan

ja-jp

Czech, Czech Republic

cs-cz

Danish, Denmark

da-dk

Dutch, Netherlands

nl-nl

Finnish, Finland

fi-fi

French, France

fr-fr

German, Germany

de-de

Italian, Italy

it-it

Norwegian, Norway

nb-no

Portuguese, Portugal

pt-pt

Spanish, Spain

es-es

Swedish, Sweden

sv-se

Chinese, China

zh-cn

Second, to enable the localized directions, set the property UseMWS to true in the GetDirections method as follows:

   var myRouteOptions = new VERouteOptions();   myRouteOptions.UseMWS = true;   map.GetDirections(['redmond,wa','seattle,wa'],      myRouteOptions);

Improved Geocoding and Confidence Data
Geocoding is the process of assigning latitude and longitude values to data such as street addresses. To position anything on the Virtual Earth map, you need the location as a VELatLong class. Clearly, it is unlikely you’d actually know the coordinates unless you’re getting the data from a GPS device or it’s previously been geocoded. Therefore, Virtual Earth provides geocoding within its routing and, importantly, through the VEMap.Find() method.

The VEMap.Find() method is responsible for geocoding a user-submitted location. This process makes a best guess, based on the text supplied. The method returns an array of VEPlace objects, which contains:

  • VEPlace.LatLong: Gets a VELatLong Class object that represents the location of the found result.
  • VEPlace.Name: Gets the String object that represents Virtual Earth’s unambiguous name for the location.
  • VEPlace.MatchCode: A VEMatchCode enumeration value specifying the match code from the geocoder.
  • VEPlace.MatchConfidence: A VEMatchConfidence enumeration value specifying the match confidence from the geocoder. Values are High, Medium, or Low confidence.

The VEMatchCode enumeration contains these values:

  • None: No match was found.
  • Good: A successful match was found.
  • Ambiguous: A number of possible locations match.
  • UpHierarchy: The match was found by a broader search.
  • Modified: The match was found, but in a modified place.

These classes give you the detailed information you’ll need to customize the results for your application and required accuracy.

Virtual Earth now supports “Roof Top Geocoding” in the United States. Rather than simply marking the location of the address on the road, this process marks the actual house or building at that address. Again, this is a very important feature for real estate applications.

Usage Tracking and Client Identification with Tokens
The Virtual Earth platform now supports a mechanism to track individual usage. Essentially, your web server requests a specific token identifier using a secure web service for each instance of a Virtual Earth map you serve. This token, specific to your application, gets set within the JavaScript Virtual Earth control before the map is loaded:

   var map = new VEMap("mymap");   map.SetClientToken(token);   map.LoadMap();

As JavaScript executes on the client, this token is public. For this reason the token is generated uniquely for each map, specific to your application.

Microsoft has added two new Virtual Earth events to support possible errors with tokens. You can attach to ontokenerror to receive notification if the token is not valid. Second, as the tokens themselves have a configurable lifespan, you attach to ontokenexpire to receive a notification when the token expires.

The usage statistics are then available for review on the Virtual Earth Platform Customer Services site alongside your MapPoint web service usage.

Author’s Note: Microsoft recommends that all commercial applications implement the new tracking system. It will be a requirement of the Service Level Agreement (SLA) offered to commercial customers.

New Tile Set?Hill Shaded
The core imagery of Virtual Earth is broken into tile sets; both the 2D AJAX control and the 3D control load these 256 x 256 images on demand. The “Hill Shaded” set is a new tile set that combines the lightweight, easy-to-read road tiles with a 3D shading effect based on the elevation data (see Figure 6). The result provides an alternative to the existing “Hybrid” tile set which provides the road information over the satellite and aerial photography available in the “Aerial” tile set. To switch to the new shaded tiles, use the new enumeration value in the map load or call:

?
Figure 6. Hill-Shaded Tiles: The hill-shaded tile set supports viewing elevation in Virtual Earth.
   map.SetMapStyle(VEMapStyle.Shaded);

This addition makes four tile sets available, as well as the unique bird’s eye images and textured 3D models making up the imagery of Virtual Earth.

Zooming to the Mouse Pointer?
In VE’s default navigation, the mouse scroll wheel zooms on the center of the screen. However, a new navigation option is available that causes VE to zoom directly to the mouse location itself. The feature can be a little counter-intuitive at first, because that functionality was previously reserved for a double click on the map. However, with a little practice, this lets users zoom to any point on the planet without clicking. You enable the feature with one line of code:

   map.SetMouseWheelZoomToCenter(false); 

Faster Shapes and New Methods
Shapes are interactive elements you can add to your map. These include:

  • Pushpins: These represent a single point.
  • Poly lines: These represent a path of many points.
  • Polygons: These represent a closed area of points.

Zindex
You can now change the Zindex of shapes (their relative vertical position in the image). As shapes can easily overlap, it is important to be able to control which shape appears on top or behind. You’ve probably encountered the same concept in applications such as PowerPoint, where you can send objects backwards or forward along the Z axis. Microsoft has added three new methods to retrieve and set the Zindex value for icons (pushpin), lines, and polygons, collectively called “polyshapes.”

   VEShape.GetZIndex();   VEShape.GetZIndexPolyShape();   VEShape.SetZIndex(icon, polyshape);

Altitude
In 3D mode, you can now position shapes at a specific altitude. The VELatLong class now has two extra properties:

   VELatLong.Altitude   VELatLong.AltitudeMode

The Altitude is a floating point number, while the AltitudeMode is an enumeration that supports the following options:

  • Absolute: This mode specifies altitude is in meters above the WGS 84 ellipsoid.
  • RelativeToGround: This mode specifies altitude is in meters above ground level (default).

This opens up a world of possible 3D mode visualizations for anything above ground. You may have already seen some great applications that track in-flight aircraft online.

Polygons and Poly lines also get a new method to draw a line to the ground from the shape at altitude. This also opens up some interesting visualization options:

   VEShape.SetLineToGround(extrude);

Conditional Zoom Level Range
One common issue with Virtual Earth is that as you zoom out, shapes overlap. You have already seen how you can adjust the Zindex, but now you can hide shapes. Two new methods let you specify the maximum and minimum zoom levels at which a shape is visible:

   VEShape.SetMaxZoomLevel(level);   VEShape.SetMinZoomLevel(level);

Using these methods, you can simply hide some or all of the shapes, or provide additional shapes at other zoom levels, increasing or reducing the shape density.

Reduction of Polygon/Poly Line Accuracy
Enabled by default, Virtual Earth will now remove points within a polygon or poly line that are visually too close at the current zoom level. The idea is to reduce the complexity of object rendering to improve performance. For example, when you view a thousand-point polygon over New York at the country level, it needs only a few points?or may be too small to bother rendering at all.

You can disable this new performance feature with the following code:

   map.EnableShapeDisplayThreshold(false);

Performance of Bulk Add

To upgrade existing applications, rather than adding shapes directly to the map, add your shapes to an array, and then add the shape array to the map in one call.

The Virtual Earth team has made a significant performance improvement for adding many pushpin shapes to the map. The simple change lets you add an array of shapes in the existing AddShape function:

   VEShapeLayer.AddShape(Array);

The performance increase is noticeable; Table 2 shows performance improvements of using the bulk method over a loop of single AddShape() calls.

Table 2: Performance comparison of AddShape() as executed in Internet Explorer 7 under Microsoft Vista x64 on a Dell XPS1330 2.4 Ghz 4 GB RAM.

Number of Pins

Single Add in Loop (sec)

Bulk Add (sec)

1

0.008

0.004

10

0.066

0.022

100

0.632

0.209

500

2.883

1.477

1000

7.264

2.259

2000

21.831

5.644

It’s simple to change most existing applications so they can benefit from this performance improvement. Rather than adding shapes directly to the map, add your shapes to an array, and then add the array of shapes to the map in one call.

Map Cruncher Is Now Part of the Virtual Earth Platform
The core of Virtual Earth is a huge number of accurate image tiles representing the Earth in several different formats. The system allows users to stream only the images required for their current view as they pan and zoom around the planet. This streaming architecture provides a fluid experience and fast load times for such a massive set of data. One powerful feature is the ability to add your own tile layers on top of the map, giving your data overlays or imagery the same highly-scalable performance. Here’s where Map Cruncher comes into play.

?
Figure 7. MapCruncher Beta In Action: MapCruncher lets you import raster and vector-based images and align them with Virtual Earth.

Map Cruncher is a tool that imports raster-based and vector-based images, provides an interface to align those images properly with Virtual Earth, and outputs the tiles in the correct format and naming convention for use with the control. Figure 7 shows Map Cruncher in action. You can also run Map Cruncher from the command line.

Import Your Data Here
Lastly, Virtual Earth can now import the most common geocoding XML format, “KeyHole Markup Language” or KML. The import process is identical to the existing GeoRSS or Live collection import types; Microsoft added a new enumeration: VEDataType.ImportXML. For example:

   var spec = new   VEShapeSourceSpecification(VEDataType.ImportXML,   "http://enteryourkmlurlhere.htm");   map.ImportShapeLayerData(spec);

Unlike GeoRSS, the KML file itself must be located on a publicly accessible web server, not a local file or localhost, because the data gets parsed by maps.live.com.

Conclusion
Virtual Earth has grown into a mature application that’s ready for use in demanding enterprise applications. The recent update added new functionality, improved the user interface, and increased the performance without any breaking changes. Applications using VE version 5 may simply need to change the version number to “6.” Note that, to support this, some functionality from previous versions, such as the old routing method, have been marked as deprecated.

  • VEMap.GetRoute: use VEMap.GetDirections instead.
  • VERouteDeprecated: old VERoute class.
  • VERouteItineraryDeprecated: old VERouteItinerary class.

The deprecated methods still work, but you should update them when you get a chance?and now is the perfect time to update your Virtual Earth applications to the latest version, or begin using this exciting technology to visualize your location-based data in your application.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: