echartsGL_taxiRoutesOfCapeTown.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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_taxiRoutesOfCapeTown"></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
  26. type="text/javascript"
  27. include="echarts,echarts-gl,shapefile"
  28. src="../../dist/mapboxgl/include-mapboxgl.js"
  29. ></script>
  30. <script type="text/javascript">
  31. var data;
  32. var attribution =
  33. "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  34. "| Image <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a> | </span>" +
  35. "<a href='https://echarts.baidu.com' target='_blank'>© 2018 " +
  36. resources.title_3baidu +
  37. ' ECharts Echarts-gl</a>';
  38. var host = window.isLocal ? window.server : 'https://iserver.supermap.io';
  39. var tileURL = host + '/iserver/services/map-china400/rest/maps/ChinaDark/zxyTileImage.png?z={z}&x={x}&y={y}';
  40. var myChart = echarts.init(document.getElementById('map'));
  41. var ENCODE_SCALE = 1e6;
  42. //解码数据格式
  43. function decodeLine(line) {
  44. var result = [];
  45. var prevX = line[0];
  46. var prevY = line[1];
  47. for (var i = 0; i < line[2].length; i += 2) {
  48. var x = line[2].charCodeAt(i) - 64;
  49. var y = line[2].charCodeAt(i + 1) - 64;
  50. // ZigZag decoding
  51. x = (x >> 1) ^ -(x & 1);
  52. y = (y >> 1) ^ -(y & 1);
  53. // Delta deocding
  54. x += prevX;
  55. y += prevY;
  56. prevX = x;
  57. prevY = y;
  58. // Dequantize
  59. result.push([x / ENCODE_SCALE, y / ENCODE_SCALE, 10]);
  60. }
  61. return result;
  62. }
  63. var geoJSON = {
  64. type: 'FeatureCollection',
  65. features: []
  66. };
  67. var regions = [];
  68. shapefile.open('../data/taxiRoutesOfCapeTown.shp', '../data/taxiRoutesOfCapeTown.dbf').then(function(source) {
  69. return source.read().then(function append(result) {
  70. if (result.done) {
  71. cbk(geoJSON);
  72. return;
  73. }
  74. var feature = result.value;
  75. feature.properties.name = geoJSON.features.length + '';
  76. regions.push({
  77. name: geoJSON.features.length + '',
  78. value: 1,
  79. height: feature.properties.SHAPE_leng * 10000
  80. });
  81. geoJSON.features.push(feature);
  82. return source.read().then(append);
  83. });
  84. });
  85. function cbk(geoJSON) {
  86. $.get('../data/taxiRoutesOfCapeTown.json', function(data) {
  87. var lines = data.map(function(track) {
  88. return {
  89. coords: decodeLine(track)
  90. };
  91. });
  92. //修改v3.8.5 echarts.js文件的BUG
  93. // echarts.parseGeoJSON = echarts.parseGeoJson;
  94. echarts.registerMap('buildings', geoJSON);
  95. myChart.setOption({
  96. mapbox: {
  97. center: [18.424552361777955, -33.92188144682616],
  98. zoom: 14,
  99. pitch: 50,
  100. bearing: -10,
  101. altitudeScale: 2,
  102. style: {
  103. version: 8,
  104. sources: {
  105. 'raster-tiles': {
  106. attribution: attribution,
  107. type: 'raster',
  108. tiles: [tileURL],
  109. tileSize: 256
  110. }
  111. },
  112. layers: [
  113. {
  114. id: 'simple-tiles',
  115. type: 'raster',
  116. source: 'raster-tiles',
  117. minzoom: 0,
  118. maxzoom: 22
  119. }
  120. ]
  121. },
  122. postEffect: {
  123. enable: true,
  124. screenSpaceAmbientOcclusion: {
  125. enable: true,
  126. intensity: 1.2,
  127. radius: 6,
  128. quality: 'low'
  129. },
  130. screenSpaceReflection: {
  131. enable: true
  132. }
  133. },
  134. light: {
  135. main: {
  136. intensity: 1,
  137. shadow: true,
  138. shadowQuality: 'high'
  139. },
  140. ambient: {
  141. intensity: 0
  142. },
  143. ambientCubemap: {
  144. texture: '../data/taxiRoutesOfCapeTown.hdr',
  145. exposure: 2,
  146. diffuseIntensity: 1,
  147. specularIntensity: 2
  148. }
  149. }
  150. },
  151. series: [
  152. {
  153. type: 'lines3D',
  154. coordinateSystem: 'mapbox',
  155. effect: {
  156. show: true,
  157. constantSpeed: 5,
  158. trailWidth: 2,
  159. trailLength: 0.8,
  160. trailOpacity: 1,
  161. spotIntensity: 10
  162. },
  163. blendMode: 'lighter',
  164. polyline: true,
  165. lineStyle: {
  166. width: 0.1,
  167. color: 'rgb(200, 40, 0)',
  168. opacity: 0
  169. },
  170. data: lines
  171. },
  172. {
  173. type: 'map3D',
  174. map: 'buildings',
  175. coordinateSystem: 'mapbox',
  176. shading: 'realistic',
  177. silent: true,
  178. instancing: true,
  179. data: regions,
  180. itemStyle: {
  181. color: '#444'
  182. },
  183. realisticMaterial: {
  184. metalness: 1,
  185. roughness: 0.2
  186. }
  187. }
  188. ]
  189. });
  190. //获取mapbox对象
  191. var mapbox = myChart
  192. .getModel()
  193. .getComponent('mapbox3D')
  194. .getMapbox();
  195. mapbox.addControl(new mapboxgl.NavigationControl(), 'top-left');
  196. });
  197. }
  198. window.addEventListener('keydown', function() {
  199. myChart.dispatchAction({
  200. type: 'lines3DToggleEffect',
  201. seriesIndex: 0
  202. });
  203. });
  204. </script>
  205. </body>
  206. </html>