echartsGL_flightPath.html 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <html>
  5. <head>
  6. <meta charset='utf-8'/>
  7. <title data-i18n="resources.title_flightPath"></title>
  8. <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no'/>
  9. <style>
  10. body {
  11. margin: 0;
  12. padding: 0;
  13. }
  14. #map {
  15. position: absolute;
  16. top: 0;
  17. bottom: 0;
  18. width: 100%;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <div id='map'></div>
  24. <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
  25. <script type="text/javascript" include="echarts,echarts-gl" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  26. <script type="text/javascript">
  27. // 数据来自 https://uber.github.io/deck.gl/#/examples/core-layers/line-layer
  28. var data;
  29. var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  30. "| Image <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a> | </span>" +
  31. "<a href='https://echarts.baidu.com' target='_blank'>© 2018 " + resources.title_3baidu + " ECharts Echarts-gl</a>";
  32. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  33. var tileURL = host + "/iserver/services/map-china400/rest/maps/ChinaDark/zxyTileImage.png?z={z}&x={x}&y={y}";
  34. var dataFile = "../data/flightpath.txt";
  35. var myChart = echarts.init(document.getElementById('map'));
  36. //获取mapbox对象
  37. $.get(dataFile, function (text) {
  38. var data = decodeFlightPathData(text);
  39. var dataAll = [];
  40. for (var i = 0; i < 4; i++) {
  41. dataAll = dataAll.concat(data.map(function (item) {
  42. return {
  43. name: item.name,
  44. coords: item.coords.map(function (coord) {
  45. return coord.slice();
  46. })
  47. };
  48. }));
  49. }
  50. myChart.setOption({
  51. mapbox: {
  52. center: [0, 51.5],
  53. zoom: 8,
  54. pitch: 60,
  55. altitudeScale: 5,
  56. style: {
  57. "version": 8,
  58. "sources": {
  59. "raster-tiles": {
  60. "attribution": attribution,
  61. "type": "raster",
  62. "tiles": [tileURL],
  63. "tileSize": 256,
  64. },
  65. },
  66. "layers": [{
  67. "id": "simple-tiles",
  68. "type": "raster",
  69. "source": "raster-tiles",
  70. "minzoom": 0,
  71. "maxzoom": 22
  72. }]
  73. },
  74. postEffect: {
  75. enable: true,
  76. bloom: {
  77. intensity: 0.4
  78. }
  79. }
  80. },
  81. series: [{
  82. type: 'lines3D',
  83. coordinateSystem: 'mapbox',
  84. effect: {
  85. show: true,
  86. constantSpeed: 40,
  87. trailWidth: 2,
  88. trailLength: 0.15,
  89. trailOpacity: 1
  90. },
  91. blendMode: 'lighter',
  92. polyline: true,
  93. lineStyle: {
  94. width: 1,
  95. color: 'rgb(50, 60, 170)',
  96. opacity: 0.1
  97. },
  98. data: dataAll
  99. }]
  100. });
  101. window.addEventListener('keydown', function () {
  102. myChart.dispatchAction({
  103. type: 'lines3DToggleEffect',
  104. seriesIndex: 0
  105. });
  106. });
  107. //获取mapbox对象
  108. if (myChart.getModel()) {
  109. var mapbox = myChart.getModel().getComponent('mapbox3D').getMapbox();
  110. mapbox.addControl(new mapboxgl.NavigationControl(), 'top-left');
  111. }
  112. });
  113. function decodePolyline(str, precision) {
  114. var index = 0;
  115. var lat = 0;
  116. var lng = 0;
  117. var coordinates = [];
  118. var shift = 0;
  119. var result = 0;
  120. var byte = null;
  121. var latitude_change;
  122. var longitude_change;
  123. var factor = Math.pow(10, precision || 5);
  124. while (index < str.length) {
  125. byte = null;
  126. shift = 0;
  127. result = 0;
  128. do {
  129. byte = str.charCodeAt(index++) - 63;
  130. result |= (byte & 0x1f) << shift;
  131. shift += 5;
  132. } while (byte >= 0x20);
  133. latitude_change = ((result & 1) ? ~(result >> 1) : (result >> 1));
  134. shift = result = 0;
  135. do {
  136. byte = str.charCodeAt(index++) - 63;
  137. result |= (byte & 0x1f) << shift;
  138. shift += 5;
  139. } while (byte >= 0x20);
  140. longitude_change = ((result & 1) ? ~(result >> 1) : (result >> 1));
  141. lat += latitude_change;
  142. lng += longitude_change;
  143. coordinates.push([lng / factor, lat / factor]);
  144. }
  145. return coordinates;
  146. }
  147. function decodeFlightPathData(text) {
  148. var lines = text.split('\n');
  149. var result = [];
  150. lines.forEach(function (line) {
  151. if (!line) {
  152. return;
  153. }
  154. var parts = line.split('\t');
  155. var coords0 = parts[2].split('\x01').map(function (str) {
  156. return decodePolyline(str, 5)
  157. });
  158. var coords1 = parts[3].split('\x01').map(function (str) {
  159. return decodePolyline(str, 1)
  160. });
  161. var coords = [];
  162. coords0.forEach(function (lineStr, i) {
  163. for (var j = 1; j < lineStr.length; j++) {
  164. var prevPt0 = coords0[i][j - 1],
  165. prevPt1 = coords1[i][j - 1],
  166. currPt0 = coords0[i][j],
  167. currPt1 = coords1[i][j];
  168. coords.push(
  169. [prevPt0[0], prevPt0[1], prevPt1[0]],
  170. [currPt0[0], currPt0[1], currPt1[0]]
  171. );
  172. }
  173. });
  174. result.push({
  175. name: parts[0],
  176. country: parts[1],
  177. coords: coords
  178. });
  179. });
  180. return result;
  181. }
  182. </script>
  183. </body>
  184. </html>