2 回答
TA贡献1853条经验 获得超18个赞
function drawCircle(lat, lng, radius, strokeColor, strokeWidth, strokeOpacity, fillColor, fillOpacity) {
var d2r = Math.PI / 180;
var r2d = 180 / Math.PI;
var Clat = radius * 0.014483; // Convert statute miles into degrees latitude
var Clng = Clat / Math.cos(lat * d2r);
var Cpoints = [];
// 计算圆周上33个点的经纬度,若需要圆滑些,可以增加圆周的点数
for (var i = 0; i < 33; i++) {
var theta = Math.PI * (i / 16);
Cy = lat + (Clat * Math.sin(theta));
Cx = lng + (Clng * Math.cos(theta));
var P = new GPoint(Cx, Cy);
Cpoints.push(P);
}
strokeColor = strokeColor || "#0055ff"; // 边框颜色,默认"#0055ff"
strokeWidth = strokeWidth || 1; // 边框宽度,默认1px
strokeOpacity = strokeOpacity || 1; // 边框透明度,默认不透明
fillColor = fillColor || strokeColor; // 填充颜色,默认同边框颜色
fillOpacity = fillOpacity || 0.1; // 填充透明度,默认0.1
var polygon = new GPolygon(Cpoints, strokeColor, strokeWidth, strokeOpacity, fillColor, fillOpacity);
map.addOverlay(polygon);
}
- 2 回答
- 0 关注
- 630 浏览
添加回答
举报