当前位置 : 主页 > 网页制作 > JQuery >

jquery – 如何在Bing地图中添加半径圆?

来源:互联网 收集:自由互联 发布时间:2021-06-15
我在这里看到了它: http://www.somebody4u.com/Profile/Live 但我找不到用api(ajax)做的方法. Bing Maps V7不包含绘制圆方法. 通过绘制几个小段,圆圈必须“近似”. var key = .....; // API access keyvar MM =
我在这里看到了它:
http://www.somebody4u.com/Profile/Live

但我找不到用api(ajax)做的方法.

Bing Maps V7不包含绘制圆方法.

通过绘制几个小段,圆圈必须“近似”.

var key = .....; // API access key

var MM = Microsoft.Maps;
var R = 6371; // earth's mean radius in km

var map = new Microsoft.Maps.Map(this.element[0], {credentials: key, disableKeyboardInput: true});

var radius = ...;      //radius of the circle
var latitude = ...;    //latitude of the circle center
var longitude = ...;   //longitude of the circle center

var backgroundColor = new Microsoft.Maps.Color(10, 100, 0, 0);
var borderColor = new Microsoft.Maps.Color(150, 200, 0, 0);

var lat = (latitude * Math.PI) / 180;     
var lon = (longitude * Math.PI) / 180;
var d = parseFloat(radius) / R;
var circlePoints = new Array();

for (x = 0; x <= 360; x += 5) {
    var p2 = new MM.Location(0, 0);
    brng = x * Math.PI / 180;
    p2.latitude = Math.asin(Math.sin(lat) * Math.cos(d) + Math.cos(lat) * Math.sin(d) * Math.cos(brng));

    p2.longitude = ((lon + Math.atan2(Math.sin(brng) * Math.sin(d) * Math.cos(lat), 
                     Math.cos(d) - Math.sin(lat) * Math.sin(p2.latitude))) * 180) / Math.PI;
            p2.latitude = (p2.latitude * 180) / Math.PI;
            circlePoints.push(p2);
}

var polygon = new MM.Polygon(circlePoints, { fillColor: backgroundColor, strokeColor: borderColor, strokeThickness: 1 });

map.entities.push(polygon);
网友评论