`
myzhijie
  • 浏览: 28045 次
  • 性别: Icon_minigender_1
  • 来自: 郑州
社区版块
存档分类
最新评论

bing map 画圆

阅读更多

    最近需要在bing 地图上画圆,因为bing 地图没有直接提供画圆的API,画起来比较麻烦,经过在网上的查找终于找到了画圆的方法。下面的代码是我整理过的代码,其中画圆函数来至网络。因为画圆比较困难,所以分享给大家,让大家也少走弯路。

    

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>bing map画圆</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<script type="text/javascript"
			src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2&mkt=zh-cn"></script>
		<script type="text/javascript">
         var map     = null;
         function GetMap()
         {
            map = new VEMap('myMap');
            map.LoadMap();
            map.SetZoomLevel(14);
            var latLon=new VELatLong(34.79248399030799,113.69712352752688);
            //设置地图中心点
            map.SetCenter(latLon);
            map.SetMouseWheelZoomToCenter(false);
            //画圆,以地图中心latLon为圆心,半径为1km 画圆
            drawCircle(latLon,1);
         }
		 //画圆函数 origin 圆心,radius 半径 单位km
		function drawCircle(origin, radius) {
			var earthRadius = 6371;
		    //圆心纬度
			var lat = (origin.Latitude * Math.PI) / 180;
		    //圆心经度
			var lon = (origin.Longitude * Math.PI) / 180;
			var d = parseFloat(radius) / earthRadius;
			var points = new Array();
			for (i = 0; i <= 360; i++) {
				var point = new VELatLong(0, 0);
				var bearing = i * Math.PI / 180; 
				point.Latitude = Math.asin(Math.sin(lat) * Math.cos(d) + Math.cos(lat) * Math.sin(d) * Math.cos(bearing));
				point.Longitude = ((lon + Math.atan2(Math.sin(bearing) * Math.sin(d) * Math.cos(lat), Math.cos(d) - Math.sin(lat) * Math.sin(point.Latitude))) * 180) / Math.PI;
				point.Latitude = (point.Latitude * 180) / Math.PI;
				points.push(point);
			}
			var circle = new VEShape(VEShapeType.Polygon, points);
			//设置无边缘
			circle.SetLineColor(new VEColor(255, 0, 0, 0));
			circle.HideIcon();
			map.AddShape(circle);
		}
      </script>
	</head>
	<body onload="GetMap();">
		<div id='myMap'
			style="position: relative; width: 400px; height: 400px;"></div>
	</body>
</html>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics