开发者

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

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
 map.AddShape(shapeOne);
 points = shape.GetPoints();

// Getting 开发者_如何学Gothe points for second polygon and Concatenating "points" with "pointsTwo".
 map.AddShape(shapeTwo);

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

                }
             );
         },
         "json"
     );
 }

Can you tell me what to add to my iteration code in order to collect all the VELatLong objects iterating through the list of polygons?


This solved my problem:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜