多边形联合表示为javascript坐标数组

时间:2015-03-06 10:01:49

标签: javascript google-maps-api-3 polygons

我需要找到表示为geocoordinates的javascript数组的多边形的联合,如下面的代码所示:

           var polygon1 = [[51.49151151647854, -0.20633749635419463],
                [51.491517887745886, -0.20663465247037038],
                [51.49125377257769, -0.20707803457401042], 
                [51.49125377257769, -0.20707803457401042],
                [51.49090541057069, -0.2071046417369189],
                [51.490605858341326, -0.20637621141179352],
                [51.49081102624578, -0.20598780005047956],
                [51.490859930095496, -0.20592173450688733]]


            var polygon2 = [[51.492223312188386, -0.20784254067885688],
                [51.49226262897666, -0.20812681455816695],
                [51.49162516066342, -0.2090258514344801],
                [51.491538051645385, -0.2089717941050469],
                [51.49200661100099, -0.20759325088262348]]

我会在Google地图上使用Google地图Javascript API v3绘制生成的多边形,因此它们的结构也可以像下面的代码一样:

   var googleMapPolygon1 = [
        new google.maps.LatLng(51.49151151647854, -0.20633749635419463),
        new google.maps.LatLng(51.491517887745886, -0.20663465247037038),
        new google.maps.LatLng(51.49125377257769, -0.20707803457401042),
        new google.maps.LatLng(51.49090541057069, -0.2071046417369189),
        new google.maps.LatLng(51.490605858341326, -0.20637621141179352),
        new google.maps.LatLng(51.49081102624578, -0.20598780005047956),
        new google.maps.LatLng(51.490859930095496, -0.20592173450688733),
        new google.maps.LatLng(51.49151151647854, -0.20633749635419463)
  ];

  var googleMapPolygon2 = [
        new google.maps.LatLng(51.492223312188386, -0.20784254067885688),
        new google.maps.LatLng(51.49226262897666, -0.20812681455816695),
        new google.maps.LatLng(51.49162516066342, -0.2090258514344801),
        new google.maps.LatLng(51.491538051645385, -0.2089717941050469),
        new google.maps.LatLng(51.49200661100099, -0.20759325088262348),
        new google.maps.LatLng(51.492223312188386, -0.20784254067885688)
  ]

那么,我可以用什么来找到多边形的联合? 提前谢谢。

编辑:这就是我的工作。我有Voronoi单元阵列结构为多边形(左下图)。而我想要得到的是它们周围的边界(图片右侧的绿色多边形)。 enter image description here

所以,我想我可以通过联合操作得到它。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:-2)

你可以这样做:

var polygon1 = [[51.49151151647854, -0.20633749635419463],
                [51.491517887745886, -0.20663465247037038],
                [51.49125377257769, -0.20707803457401042], 
                [51.49125377257769, -0.20707803457401042],
                [51.49090541057069, -0.2071046417369189],
                [51.490605858341326, -0.20637621141179352],
                [51.49081102624578, -0.20598780005047956],
                [51.490859930095496, -0.20592173450688733]];

var polygon2 = [[51.492223312188386, -0.20784254067885688],
                [51.49226262897666, -0.20812681455816695],
                [51.49162516066342, -0.2090258514344801],
                [51.491538051645385, -0.2089717941050469],
                [51.49200661100099, -0.20759325088262348]];

var union = new google.maps.Polygon({
    paths: polygon1.concat(polygon2)
});