# VE Imagery Service, Polygons and Polylines

Currently the VE Imagery service does not have the ability to render polygons or polylines on a map image. The high level steps involved to accomplish this are as follows:

1) Calculate the best map view for an array of Location objects.

2) Request map image from the imagery service that matches the best map view calculated in step 1.

3) Calculate the pixel coordinate of each location.

4) Use .NET drawing tools to draw polygons and polylines.

Many of the steps in this article are explained in the article title VE Imagery Service and Custom Icons

The following code block shows how to draw a polygon on a map image from an array of points that form a polygon.

```private void AddPolygon(BestView view, Image map, Location[] polygon){    //define the map as a gaphics object
Graphics graphics = Graphics.FromImage(map);

Point[] points = new Point[polygon.Length];    //calculate pixel points
for (int i = 0; i < polygon.Length; i++)    {        points[i] = LatLongToPixel(polygon[i], view);    }    // Create blue pen for outline of polygon.
Pen bluePen = new Pen(Color.Blue, 1);    //Create brush to fill polygon.
Color transparentGreen = Color.FromArgb(50, 0, 255, 0);
Brush greenBrush = new SolidBrush(transparentGreen);    graphics.DrawPolygon(bluePen, points);    graphics.FillPolygon(greenBrush, points);}```

The following code block shows how to draw a polyline on a map image from an array of points that form a polyline.

```private void AddPolyline(BestView view, Image map, Location[] polyline){    //define the map as a gaphics object
Graphics graphics = Graphics.FromImage(map);

Point[] points = new Point[polyline.Length];    //calculate pixel points
for (int i = 0; i < polyline.Length; i++)    {        points[i] = LatLongToPixel(polyline[i], view);    }    // Create pen.
Pen bluePen = new Pen(Color.Blue, 1);    graphics.DrawLines(bluePen, points);}```

By combining these algorithms with the code in the article; VE Imagery Service and Custom Icons you can add your polygons and polylines to a VE map image. This can be useful to create tile layers when wanting to display a large number of polygons in the JavaScript version of Virtual Earth without having performance issues.