Virtual Earth API: Importing Virtual Earth Collections into VEShapeLayers

The same way you can import GeoRSS Layers into VEShapeLayers, you can also import any public Virtual Earth Collection from Live Search Maps.  It is very simple to do and is probably one of the easiest ways to create a Virtual Earth application.

Steve Lombardi posted a great post awhile back on the Virtual Earth Spaces Blog regarding the 10 Minute Map with steps how to create a user collection in Live Search Maps and then load it in the Virtual Earth API.  Now, with the v5 Virtual Earth API you can still do this very easily, and now even provide more customization using VEShape and VEShapeLayer if you choose to do so.

To import a Virtual Earth Collection, you first need to create a VEShapeLayer and a VEShapeSourceSpecification.  The VEShapeSourceSpecification allows you to specify the shape source type, the shape source, and the shape layer to load the data in.  For a collection, you need to specify the source type as VEDataType.VECollection, specify the source as the Collection ID from Live Search Maps, and pass in a reference to the VEShapeLayer.  Then you can call ImportShapeLayerData on the map with this specification, and you are done!

Here's the example code using a collection with information about the Lewis & Clark Expedition (for your collection, replace the collection ID with the ID of your collection):

var shapeLayer = new VEShapeLayer();
var shapeSpec = new VEShapeSourceSpecification(VEDataType.VECollection,"B41BBC2FFB8342CD!107", shapeLayer);

To customize things further, you can pass in an optional callback to the ImportShapeLayerData call and customize the VEShapes.

Here's some sample code that changes the icon of the VEShapes when displaying the collection.  Notice to iterate through the VEShapes in the collection, we do exactly what we did when importing GeoRSS layers.  We can get iterate through the shapes and modify any of the VEShape properties that we want to customize.

function onFeedLoad(layer)
   var numShapes = layer.GetShapeCount();
   for(var i=0; i < numShapes; ++i)
      var s = layer.GetShapeByIndex(i);
      s.SetCustomIcon("<img src='hiking_icon.gif'/>");

var shapeLayer = new VEShapeLayer();
var shapeSpec = new VEShapeSourceSpecification(VEDataType.VECollection,"B41BBC2FFB8342CD!107", shapeLayer);
map.ImportShapeLayerData(shapeSpec, onFeedLoad);

Here's a link to the complete example:

Virtual Earth API Collections Example

 For more information, see the Virtual Earth Interactive SDK.

Comments (4)

  1. RedCoat999 says:

    Out of the methods you have posted for importing locations for pushpins which is the quickest?  I have a database of 150 and growing points to add.


  2. tanvir.huda says:

    Hello Keith

    I have read your web blog about adding custom GeoRSS layer in VE5. I have added custom pushpin icon using VEShape object. It works fine in 2D mode.

    But when i shift to 3D mode the custom push pin ICON disappear and instead it shows the default pushpin icon. Can you please help me why it is doing so? Is there any limitation in VE displaying custom ICON as a pushpin in 3D mode. I have also set the full URI but it is not working.

    Hope to hear from you.

    Thanks in advance.



  3. antoniochagoury says:


    Great article.

    Is there a way to change the IconUrl at the same time you create the layer?

    In the old v3 you could do this:

    velayer.IconUrl = "YourIcon.gif";

    This does not appear to be the case anymore, and in my case, I do not want to change the icon with a call back to "OnFeedLoaded" as in your example.

    Any ideas?

    Thank you.

  4. Keith Kinnan says:

    Currently, to modify icons in a layer, you have to modify the icon in the VEShapeLayer callback.

Skip to main content