百度地图轨迹动画
    轨迹动画 - 图1

    1. <!DOCTYPE html>
    2. <html>
    3. <head>
    4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    5. <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    6. <style type="text/css">
    7. body,
    8. html,
    9. #allmap {
    10. width: 100%;
    11. height: 100%;
    12. overflow: hidden;
    13. margin: 0;
    14. font-family: "微软雅黑";
    15. }
    16. #allmap {
    17. position: relative;
    18. }
    19. #tools {
    20. position: absolute;
    21. left: 0;
    22. top: 0;
    23. z-index: 1000;
    24. }
    25. </style>
    26. <script type="text/javascript"
    27. src="https://api.map.baidu.com/api?type=webgl&v=1.0&ak=G1LFyjrNGIkns5OfpZnrCGAKxpycPLwb"></script>
    28. <script type="text/javascript"
    29. src="https://api.map.baidu.com/library/TrackAnimation/src/TrackAnimation_min.js"></script>
    30. <title>地图展示</title>
    31. </head>
    32. <body>
    33. <div id="allmap"></div>
    34. <div id="tools">
    35. <button id="start">播放动画</button>
    36. <button id="end">停止播放</button>
    37. </div>
    38. </body>
    39. </html>
    40. <script type="text/javascript">
    41. var bmap = new BMapGL.Map("allmap"); // 创建Map实例
    42. bmap.centerAndZoom(new BMapGL.Point(116.297611, 40.047363), 17); // 初始化地图,设置中心点坐标和地图级别
    43. bmap.enableScrollWheelZoom(true); // 开启鼠标滚轮缩放
    44. var path = [{
    45. 'lng': 116.297611,
    46. 'lat': 40.047363
    47. }, {
    48. 'lng': 116.302839,
    49. 'lat': 40.048219
    50. }, {
    51. 'lng': 116.308301,
    52. 'lat': 40.050566
    53. }, {
    54. 'lng': 116.305732,
    55. 'lat': 40.054957
    56. }, {
    57. 'lng': 116.304754,
    58. 'lat': 40.057953
    59. }, {
    60. 'lng': 116.306487,
    61. 'lat': 40.058312
    62. }, {
    63. 'lng': 116.307223,
    64. 'lat': 40.056379
    65. }];
    66. var point = [];
    67. for (var i = 0;i < path.length;i++) {
    68. point.push(new BMapGL.Point(path[i].lng, path[i].lat));
    69. }
    70. var pl = new BMapGL.Polyline(point);
    71. var trackAni = new BMapGLLib.TrackAnimation(bmap, pl, {
    72. overallView: true, // 动画完成后自动调整视野到总览
    73. tilt: 30, // 轨迹播放的角度,默认为55
    74. duration: 20000, // 动画持续时长,默认为10000,单位ms
    75. delay: 3000 // 动画开始的延迟,默认0,单位ms
    76. });
    77. document.getElementById('start').addEventListener('click', function () {
    78. trackAni.start();
    79. });
    80. document.getElementById('end').addEventListener('click', function () {
    81. trackAni.cancel(); // 强制停止动画
    82. });
    83. </script>

    http://www.youbaobao.xyz/datav-docs/guide/guide/bmap-harder.html#%E7%99%BE%E5%BA%A6%E5%9C%B0%E5%9B%BE%E8%BD%A8%E8%BF%B9%E5%8A%A8%E7%94%BB