本文主要是介绍基于百度地图api绘制台风轨迹(1),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
基于百度地图api绘制台风轨迹(1)
<!DOCTYPE html>
<html>
<head><meta charset="utf-8"><title>绘制台风路径</title><script src="http://api.map.baidu.com/api?v=2.0&ak=TxwfD55mIGhS3brtR4UP1hMnZLUB3mV9"></script><style type="text/css">html,body,#allmap{height:100%;margin:0;overflow:hidden;font-family:"微软雅黑";}</style>
</head>
<body><div id="allmap"></div><script type="text/javascript">//初始化地图var map = new BMap.Map("allmap");map.centerAndZoom(new BMap.Point(121.5, 25.0), 4); //设置地图中心点和缩放级别map.enableScrollWheelZoom(); //启用滚轮缩放//定义台风路径数据var lats = [22.1,23.4,24.7,26.2,27.9,29.7,31.3,32.8,34.0,34.7,35.1,35.1];var lons = [120.6,122.3,124.0,125.2,126.1,127.1,128.1,129.0,129.9,130.3,130.3,129.9];var grades = [2,2,2,2,2,2,2,2,2,2,2,2];//绘制台风路径var points = [];for (var i = 0; i < lats.length; i++) {points.push(new BMap.Point(lons[i], lats[i]));}var polyline = new BMap.Polyline(points, {strokeColor:"#FF0000", strokeWeight:5}); //定义折线对象map.addOverlay(polyline); //添加折线到地图中//添加台风等级图例var icon1 = new BMap.Icon("http://api.map.baidu.com/img/markers.png",new BMap.Size(23, 25),{offset:new BMap.Size(10, 25),imageOffset:new BMap.Size(0, 0)});var marker1 = new BMap.Marker(new BMap.Point(lons[lons.length-1],lats[lats.length-1]),{icon:icon1});marker1.setTitle("等级:"+grades[grades.length-1]);map.addOverlay(marker1);</script>
</body>
</html>
这篇关于基于百度地图api绘制台风轨迹(1)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!