This uses the July 2008 CTP of the Windows Live tools. You can download the Windows Live Tools for Visual Studio.
In this post, we're taking a look at using pushpins with the Virtual Earth ASP.NET control. We have a page similar to the previous post, with a map control on it called VEMap.
In the code behind we have a method for adding shapes to the map as this is a multi-step process. First we need to create an object to represent the point, then an object to represent the shape (we'll come to other shape types later, but for the moment, we're just dealing with pushpins), finally we add the shape to the map.
The Page_Load method adds a number of shapes to the map, these pushpins represent locations where Scottish Developers have held user group meetings. The code looks like this:
protected void Page_Load(object sender, EventArgs e)
{
// Glasgow Caledonian University
AddShape(55.8662120997906, -4.25060659646988);
// Dundee University
AddShape(56.4572643488646, -2.97848381102085);
// Microsoft Edinburgh (George Street)
AddShape(55.9525336325169, -3.20506207644939);
// Microsoft Edinburgh (Waterloo Place)
AddShape(55.9535374492407, -3.18680360913277);
}
private void AddShape(double latitude, double longitude)
{
LatLongWithAltitude point = new LatLongWithAltitude(latitude, longitude);
Shape shape = new Shape(ShapeType.Pushpin, point);
VEMap.AddShape(shape);
}
From this we get a fairly standard output when the application is run:

At present, this is all visual. There isn't any real functionality. What we'll do is add some very basic functionality, so that when you hover over a pushpin it tells you something about it. The Shape object has a Description property into which you can put an HTML fragment. So, here is the updated code:
protected void Page_Load(object sender, EventArgs e)
{
// Glasgow Caledonian University
AddShape(55.8662120997906, -4.25060659646988,
"<b>Glasgow Caledonian University</b>");
// Dundee University
AddShape(56.4572643488646, -2.97848381102085,
"<b>Dundee University</b>");
// Microsoft Edinburgh (George Street)
AddShape(55.9525336325169, -3.20506207644939,
"<b>Microsoft Edinburgh</b> (George Street)");
// Microsoft Edinburgh (Waterloo Place)
AddShape(55.9535374492407, -3.18680360913277,
"<b>Microsoft Edinburgh</b> (Waterloo Place)");
}
private void AddShape(double latitude, double longitude, string description)
{
LatLongWithAltitude point = new LatLongWithAltitude(latitude, longitude);
Shape shape = new Shape(ShapeType.Pushpin, point);
shape.Description = description;
VEMap.AddShape(shape);
}
The result when you hover over a pushpin looks like this:

That's all great if you want the default pushpin look. However, you might want to customise the pins so they match more what you are looking for. The Shape class has a CustomIcon property which you can set to be a graphics object. In the following example I've used a simple png file with a red circle and an semi-transparent yellow fill.
The code now looks like this:
private void AddShape(double latitude, double longitude, string description)
{
LatLongWithAltitude point = new LatLongWithAltitude(latitude, longitude);
Shape shape = new Shape(ShapeType.Pushpin, point);
shape.Description = description;
shape.CustomIcon = "images/target.png";
VEMap.AddShape(shape);
}
And the result looks like this:
