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:
- Create an array of pushpins
- Create an empty shape layer and add it to the map
- Add the array of pushpins to the shape layer
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));
2. Create an empty shape layer and add it to the map:
var shapeLayer = new VEShapeLayer();
3. Add the array of pushpins to the shape layer:
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.