Javascript 使用谷歌地图API合并多边形

Javascript 使用谷歌地图API合并多边形,javascript,jquery,google-maps,google-maps-api-3,Javascript,Jquery,Google Maps,Google Maps Api 3,正如你在下面看到的,我有两个边多边形。基本上是两个三角形及其各自的坐标。见: 函数初始化(){ //定义多边形路径的板条坐标。 var bounds=new google.maps.LatLngBounds(); var i; 变量polygords=[ 新的google.maps.LatLng(25.774252,-80.190262), 新google.maps.LatLng(18.466465,-66.118292), 新google.maps.LatLng(32.321384,-64.

正如你在下面看到的,我有两个边多边形。基本上是两个三角形及其各自的坐标。见:

函数初始化(){
//定义多边形路径的板条坐标。
var bounds=new google.maps.LatLngBounds();
var i;
变量polygords=[
新的google.maps.LatLng(25.774252,-80.190262),
新google.maps.LatLng(18.466465,-66.118292),
新google.maps.LatLng(32.321384,-64.757370)
];
对于(i=0;i
#地图{
身高:100%;
}
/*可选:使示例页面填充窗口*/
html,
身体{
身高:100%;
保证金:0;
填充:0;
}

也许您可以合并阵列并删除重复的阵列?比如:

var newPolygon = polygonCoords.concat(polygonCoords2);
然后删除重复的坐标(我从post中获取了此代码):

var sorted_arr=newPolygon.slice().sort();//您可以在这里定义比较函数。
//JS默认使用蹩脚的字符串比较。
//(我们使用slice克隆阵列,以便
//原始阵列将不会被修改)
var结果=[];
对于(var i=0;i

然后将
路径:polygords,
替换为
路径:结果,

是否希望合并为一个(即波多黎各和佛罗里达州的点)的坐标始终是相同的坐标,只是不同多段线的一部分?希望这是有意义的
var sorted_arr = newPolygon.slice().sort(); // You can define the comparing function here. 
                                     // JS by default uses a crappy string compare.
                                     // (we use slice to clone the array so the
                                     // original array won't be modified)
var results = [];
for (var i = 0; i < newPolygon.length - 1; i++) {
    if (sorted_arr[i + 1] == sorted_arr[i]) {
        results.push(sorted_arr[i]);
    }
}