如何收集遍历多边形列表的所有VELatLong对象?

时间:2011-08-13 17:44:26

标签: javascript bing-maps

这个问题应该很简单,但我无法弄明白。

我想收集所有在JavaScript中迭代多边形列表的VELatLong对象,以便使用SetMapView()方法。

到目前为止,我只能处理2个多边形,我的代码如下所示:

var points = [];

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

// Getting the points for second polygon and Concatenating "points" with "pointsTwo".
 map.AddShape(shapeTwo);

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

map.SetMapView(points);

但是,我想帮助我如何在迭代多边形列表中做同样的事情?

我的迭代代码工作正常,看起来像这样:

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
                     map.AddShape(shape);

                }
             );
         },
         "json"
     );
 }

你能告诉我添加到我的迭代代码中的内容,以便收集遍历多边形列表的所有VELatLong对象吗?

1 个答案:

答案 0 :(得分:0)

这解决了我的问题:

                // 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);
                }