Virtual Earth Map Control SDK, version 3.1 
Drawing Lines and Polygons on the Map 

You can use the Virtual Earth map control to programmatically draw polylines on the map. Each polyline consists of two or more VELatLong objects.

Drawing a Polyline or Polygon

To draw a polyline on the map, follow these steps:

  1. Create an array of VELatLong objects that define each of the vertices of the line or polygon, as follows.

    var points = new Array(
       new VELatLong(45.01188,-111.06687),
       new VELatLong(45.01534,-104.06324),
       new VELatLong(41.01929,-104.06),
       new VELatLong(41.003,-111.05878),
       new VELatLong(45.01188,-111.06687));
  2. Create a new VEPolyline or VEPolygon object, specifying the ID, the array of VELatLong objects, the line color (and fill color, if you are creating a polygon), and the line width (in pixels), as follows.

    var mypoly = new VEPolyline('1', points, linecolor, 2);
    //or
    var mypoly = new VEPolygon('1', points, new VEColor(100,200,200,0.5), 
       new VEColor(255,255,255,1.0), 2)
  3. Call the VEMap.AddPolyline or VEMap.AddPolygon method, passing the VEPolyline or VEPolygon object, as follows.

    map.AddPolyline(mypoly);
    //or
    map.AddPolygon(mypoly);
  4. Optionally, you can change the map view so that the polyline you just added is shown in the map, as follows.

    map.SetMapView(points);

Example

The following example shows the code you need to add a polygon to the map.

var map = null;
function GetMap()
{
   map = new VEMap('myMap');
   map.LoadMap();
   DrawPoly();
}
function DrawPoly()
{
   var points = new Array(
      new VELatLong(45.01188,-111.06687),
      new VELatLong(45.01534,-104.06324),
      new VELatLong(41.01929,-104.06),
      new VELatLong(41.003,-111.05878),
      new VELatLong(45.01188,-111.06687)
      );

   poly = new VEPolygon('1',points);
   poly.SetOutlineWidth(3);
   poly.SetOutlineColor(new VEColor(0,150,100,1.0));
   poly.SetFillColor(new VEColor(0,150,100,0.5));
   map.AddPolygon(poly);
   map.SetMapView(points);

Page view tracker