Using Virtual Earth version 5.0, you can create driving routes with automatically generated pushpins along the route that contain the driving itinerary inside the pushpin bubbles. After a VEMap.GetRoute call is made in Version 5.0, a VERoute object is returned. The VERoute has itinerary directions but has no information as to the co-ordinate of the route pushpins and no access to their InfoBox descriptions. This article will discuss how to manipulate these pushpins and generate your own version 5.0 route pushpins.
Figure 1 – Customized route pushpins
The “_dm” Object
To actually manipulate these route pushpins, it’s important to take a look at the “_dm” object. Basically this object is part of the VEMap class and is used to handle calls to/from the Virtual Earth’s directions.ashx handler. You will utilize the _dm.RemoveRoutePins method to clear all the existing route pins (without removing the route polyline or any existing pushpins on the map) and the _dm.veroutecache array, which holds the route pushpins.
Figure 2 – Breaking down the “_dm” object using Firebug
When a route is generated in version 5.0, the _dm.veroutecache array is populated with the resulting route pushpins in the route callback function. Upon further inspection (see highlighted in Figure 3), you will notice that the pushpins being stored in the _dm.veroutecache array are actually version 4.0 pushpins. You can export all the version 4.0 pushpin information and generate your own set of version 5.0 pushpins.
Figure 3 – A Version 4.0 pushpin being wrapped inside the veroutecache
To create your own customized route pushpins:
- In your route callback, iterate through the veroutecache and pull out the pushpin information to generate your own VEShape instance
- Store your created VEShape in an array
- Make a call to _dm.RemoveRoutePins
- Pull the VEShapes out of your array and plot them on the map.
It’s important to note that a call to _dm.RemoveRoutePins will delete all the route pins on the map as well as clearing the veroutecache, so you will need to examine all the old route pushpin information before you delete the actual pushpins from your map.
You can find the sample code of how to do this here. I’ve also added in the start/end markers (which are the first and last elements in the veroutecache array). Finally, I’ve included customized numbered pushpins which was taken from Keith Kinnan’s blog at: http://blogs.msdn.com/keithkin/archive/2007/05/16/virtual-earth-api-creating-numbered-pushpins.aspx
Article contributed by Derek Chan (www.infusion.com). Have you got something to contribute?