Welcome to MSDN Blogs Sign in | Join | Help

Virtual Earth API: Bulk Adding Pushpins to a Layer to Improve Performance

One of the new features from the Virtual Earth v6 Map Control API is the ability to bulk add groups of pushpins to the map in one step.  This improves performance when putting a large number of pushpins on the map since the HTML markup of the pushpins is serialized and inserted in the map in one operation.

Bulk adding pushpins to the map consists of 3 steps:

  1. Create an array of pushpins
  2. Create an empty shape layer and add it to the map
  3. Add the array of pushpins to the shape layer

For example:

1. Create an array with a large number of pushpins:

var center = map.GetCenter();

var shapes = new Array();
for (i=0 ; i < 150; ++i)
{
     var shape = new VEShape(VEShapeType.Pushpin, new VELatLong(center.Latitude + Math.random()*20 - 10, center.Longitude + Math.random()*20 - 10));
     shapes.push(shape);
}

2. Create an empty shape layer and add it to the map:

var shapeLayer = new VEShapeLayer();
map.AddShapeLayer(shapeLayer);

3. Add the array of pushpins to the shape layer:

shapeLayer.AddShape(shapes);

Here's a link to a working sample which adds pushpins to the map using the new bulk add approach.  It has a checkbox which allows you to turn off the bulk add and add the pushpins in the normal manner so you can compare the performance improvement between bulk add and the traditional approach.  The time to execute a bulk add operation tends to be about 1/2 the time of the traditional approach.

Virtual Earth API Bulk Add Pushpin Sample

Published Tuesday, November 20, 2007 3:49 PM by keithkin

Comments

# MSDN Blog Postings &raquo; Virtual Earth API: Bulk Adding Pushpins to a Layer to Improve Performance

Wednesday, November 21, 2007 8:11 AM by Walter Stiers - Academic Relations Team (BeLux)

# Virtual Earth API: Series of information

A set of blog entries has been published recently. The details are on Keith Kinnan's Weblog . They also

Wednesday, November 21, 2007 9:04 AM by Noticias externas

# Virtual Earth API: Series of information

A set of blog entries has been published recently. The details are on Keith Kinnan&#39;s Weblog . They

Anonymous comments are disabled
 
Page view tracker