Как собрать все объекты VELatLong, проходящие через список полигонов? - PullRequest
0 голосов
/ 13 августа 2011

этот вопрос должен быть довольно простым, но я не смог понять его.

Я хочу собрать все объекты VELatLong, перебирая список полигонов в JavaScript, чтобы использовать метод 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 голосов
/ 14 августа 2011

Это решило мою проблему:

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