如何收集所有迭代多边形列表的VELatLong对象

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

本文关键字:列表 VELatLong 对象 多边形 迭代 何收集      更新时间:2023-09-26

这个问题应该很简单,但是我一直没能算出来。

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

到目前为止,我已经能够做到只有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对象迭代多边形列表?

这就解决了我的问题:

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