# How to collect all the VELatLong objects iterating through a list of polygons?

• ### Question

• Hi, this question should be quite simple, but I haven't been able to figure it out.

I want to collect all the VELatLong objects iterating through a list of polygons in JavaScript in order to use the SetMapView() method.

So far I have been able to do with just 2 polygons and my code looks like this:

var points = [];

// Getting the points for first polygon
points = shapeOne.GetPoints();

// Getting the points for second polygon and Concatenating "points" with "pointsTwo".

pointsTwo = shapeTwo.GetPoints();
points.concat(pointsTwo);

map.SetMapView(points);

But I would like help to how I can do the same thing iterating through a list of polygons?

My iteration code works fine, it looks like this:

function btnPolygons_Click()
{

\$.post
(
"/Search/GetPolygons",
null,
function (items) {
\$.each
(
items,
function (i, polygonItem) {

var wktShape = polygonItem.PolygonWKT
// Create a VEShape from the WKT representation
var shape = VirtualEarthWKT.ShapeFromWKT(wktShape);
// Add VEShape to Map

}
);
},
"json"
);
}

rune007
• Moved by Saturday, March 10, 2012 10:33 AM (From:Bing Maps: Map Control and Web services Development)
Saturday, August 13, 2011 5:07 PM

• I solved my problem by putting this code in my iteration code:

// Getting the points of the first iteration.
if (i == 0)
{
points = shape.GetPoints();
}

// Concatenating the points of the first iteration to the following iterations.
else
{
pointsTwo = shape.GetPoints();
points = points.concat(pointsTwo);
}

// Setting the map view in the last iteration.
if (i == items.length - 1)
{
map.SetMapView(points);
}

rune007
• Marked as answer by Sunday, August 14, 2011 4:00 PM
Sunday, August 14, 2011 4:00 PM