有了这个功能
drawCircle(pointa, pointb, radius, dir) {
console.log("TESTING POINTA POINTB >>>>>>>>>>>>"+pointa+" - "+pointb);
let lat;
let lng;
var d2r = Math.PI / 180; // degrees to radians
var r2d = 180 / Math.PI; // radians to degrees
var earthsradius = 3963; // 3963 is the radius of the earth in miles or 6371 in km
var points = 32;
// find the raidus in lat/lon
var rlat = (radius / earthsradius) * r2d;
var rlng = rlat / Math.cos(pointa * d2r);
var extp = new Array();
if (dir==1) {var start=0;var end=points+1} // one extra here makes sure we connect the ends
else {var start=points+1;var end=0}
for (var i=start; (dir==1 ? i < end : i > end); i=i+dir) {
var theta = Math.PI * (i / (points/2));
let ey = pointb + (rlng * Math.cos(theta)); // center a + radius x * cos(theta)
let ex = pointa + (rlat * Math.sin(theta)); // center b + radius y * sin(theta)
extp.push({lat: ey, lng: ex});
//console.log("PUSHING TO EXTP >>>>>>>>>>>>",{'lat': ey,'lng': ex});
}
console.log("CHECK EXTP ARRAY >>>>>>>>>>>>",extp);
return extp;
}
应该创建一个数组(extp)并将其返回给我在谷歌地图中使用的函数(this.drawCircle)
this.map.addPolygon({
points: this.points,
holes: this.drawCircle(this.myLat, this.myLong, 1, 1),
'strokeColor': "black",
'strokeWidth': 2,
'fillColor': "#222222"
});
然而,在控制台而不是它给出值,我得到的对象而不是(例如):{lat:85,lng:179.9}这种格式 - 作为回报,它不会在多边形。
检查EXTP ARRAY&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt; [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object], [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object], [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object], [object Object],[object Object],[object Object]
编辑:
如果我更换
this.map.addPolygon({
points: this.points,
holes: this.drawCircle(this.myLat, this.myLong, 1, 1),
'strokeColor': "black",
'strokeWidth': 2,
'fillColor': "#222222"
});
与
this.map.addPolygon({
points: this.points,
holes: [
[
{lat: 29.68224948021748,lng: -23.676965750000022},
{lat: 29.68224948021748,lng: 44.87772174999998},
{lat: 71.82725578445813,lng: 44.87772174999998},
{lat: 71.82725578445813,lng: -23.676965750000022},
]
],
'strokeColor': "black",
'strokeWidth': 2,
'fillColor': "#222222"
});
它工作正常,所以我认为问题仍然是由于extp。有什么想法吗?