效果图:
* [![20200508_183147.mp4 (447.42KB)](https://gw.alipayobjects.com/mdn/prod_resou/afts/img/ANNs6TKOR3isAAAAAAAAAAABkARQnAQ)](https://www.yuque.com/blueheart/blog/hlckeg?_lake_card=%7B%22status%22%3A%22done%22%2C%22name%22%3A%2220200508_183147.mp4%22%2C%22size%22%3A458163%2C%22percent%22%3A100%2C%22taskId%22%3A%222NVucy2b3K0o%22%2C%22margin%22%3Atrue%2C%22id%22%3A%22hB5dr%22%2C%22videoId%22%3A%22inputs%2Fprod%2Fyuque%2F2020%2F726433%2Fmp4%2F1588934122691-c09f232d-a7ea-4082-ac13-010540d9a07d.mp4%22%2C%22card%22%3A%22video%22%7D#hB5dr)> 上代码,方便以后查阅!

1、html 文件

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>个人轨迹图</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  7. <meta name="apple-mobile-web-app-capable" content="yes"> <!-- Fullscreen Landscape on iOS -->
  8. <link rel="stylesheet" href="../css/common.css">
  9. </head>
  10. <body>
  11. <div id="main"></div>
  12. <script src="../js/echarts.js"></script>
  13. <script src="../js/echarts-gl.min.js"></script>
  14. <script src="../js/jquery.min.js"></script>
  15. <script src="../js/bmap.min.js"></script>
  16. <script src="../data/data.js"></script>
  17. <script src="../set/settings.js"></script>
  18. <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=yPCSLTLWeViz91a5GxkPcn5d2OzQlkcY"></script>
  19. <script>
  20. var myChart = echarts.init(document.getElementById('main'));
  21. console.log(data);
  22. if(colorOrWidth == 0){
  23. var lines2 = data.features.map(function(theD){
  24. return{
  25. coords:theD.geometry.coordinates
  26. }
  27. })
  28. };
  29. if(colorOrWidth == 1){
  30. var lines2 = data.features.map(function(theD){
  31. return{
  32. coords:theD.geometry.coordinates,
  33. lineStyle:{
  34. normal:{
  35. color: theColorRamp[theD.properties.value-1],
  36. }
  37. }
  38. }
  39. })
  40. }
  41. if(colorOrWidth == 2){
  42. var lines2 = data.features.map(function(theD){
  43. return{
  44. coords:theD.geometry.coordinates,
  45. lineStyle:{
  46. normal:{
  47. width: theD.properties.value * theWidthRatio,
  48. }
  49. }
  50. }
  51. })
  52. }
  53. if(colorOrWidth == 3){
  54. var lines2 = data.features.map(function(theD){
  55. return{
  56. coords:theD.geometry.coordinates,
  57. lineStyle:{
  58. normal:{
  59. color: theColorRamp[theD.properties.value-1],
  60. width: theD.properties.value * theWidthRatio
  61. }
  62. }
  63. }
  64. })
  65. }
  66. myChart.setOption(option = {
  67. bmap: {
  68. center: theCenter,
  69. zoom: theZoom,
  70. roam: true,
  71. mapStyle: {
  72. 'styleJson': mapStyle
  73. }
  74. },
  75. series: [{
  76. type: 'lines',
  77. coordinateSystem: 'bmap',
  78. polyline: true,
  79. data: lines2,
  80. silent: true,
  81. lineStyle: {
  82. normal: {
  83. // color: '#c23531',
  84. color: theColor,
  85. opacity: theOpac,
  86. width: theWidth
  87. }
  88. },
  89. progressiveThreshold: 500,
  90. progressive: 200
  91. }, {
  92. type: 'lines',
  93. coordinateSystem: 'bmap',
  94. polyline: true,
  95. data: lines2,
  96. lineStyle: {
  97. normal: {
  98. width: 0
  99. }
  100. },
  101. effect: {
  102. period: thePeriod,
  103. constantSpeed: theSpeed,
  104. show: effectShow,
  105. trailLength: theEffLength,
  106. symbolSize: theEffWidth
  107. },
  108. zlevel: 1
  109. }]
  110. });
  111. </script>
  112. </body>
  113. </html>

2、setting 文件

  1. // 此脚本用于修改图表的参数
  2. // 路线属性
  3. var colorOrWidth = 3; // 0代表既不用色彩也不用宽度来表示值,1代表用色彩,2代表用宽度,3代表二者皆用
  4. var theColorRamp = ['#49FF94', '#FFFD2A', '#FF2594', '#ff2a36', '#e0f3f8', '#ffffbf', '#fee090', '#fdae61', '#f46d43', '#d73027']; // 路线颜色
  5. var theWidthRatio = 0.2 // 宽度与值的比值
  6. // 固定属性,当该属性没有和值相关,会自动设成如下值
  7. var theColor = 'rgb(200, 35, 45)'; // 线的颜色
  8. var theWidth = 3; // 线的宽度
  9. var theOpac = 0.3; // 线的透明度
  10. // 地图相关
  11. var theCenter = [114.066239, 22.531889]; // 中心点坐标
  12. var theZoom = 18; //视角远近 数字
  13. // 动画效果
  14. var effectShow = true;// 是否展示动画
  15. var theSpeed = 0; // 尾迹速度,当尾迹速度不等于 0 时,使用单次循环时间作为速度依据
  16. var thePeriod = 2; // 单次循环时间,只有当尾迹速度为 0 时才能生效
  17. var theEffWidth = 6; // 尾迹宽度
  18. var theEffLength = 0.5; // 尾迹长度
  19. // 百度地图
  20. // 百度地图的accesstoken需要到 html 的第18行 自行进行替换
  21. var mapStyle = [
  22. {
  23. "featureType": "water",
  24. "elementType": "all",
  25. "stylers": {
  26. "color": "#021019"
  27. }
  28. },
  29. {
  30. "featureType": "highway",
  31. "elementType": "geometry.fill",
  32. "stylers": {
  33. "color": "#000000"
  34. }
  35. },
  36. {
  37. "featureType": "highway",
  38. "elementType": "geometry.stroke",
  39. "stylers": {
  40. "color": "#147a92"
  41. }
  42. },
  43. {
  44. "featureType": "arterial",
  45. "elementType": "geometry.fill",
  46. "stylers": {
  47. "color": "#000000"
  48. }
  49. },
  50. {
  51. "featureType": "arterial",
  52. "elementType": "geometry.stroke",
  53. "stylers": {
  54. "color": "#0b3d51"
  55. }
  56. },
  57. {
  58. "featureType": "local",
  59. "elementType": "geometry",
  60. "stylers": {
  61. "color": "#000000"
  62. }
  63. },
  64. {
  65. "featureType": "land",
  66. "elementType": "all",
  67. "stylers": {
  68. "color": "#08304b"
  69. }
  70. },
  71. {
  72. "featureType": "railway",
  73. "elementType": "geometry.fill",
  74. "stylers": {
  75. "color": "#000000"
  76. }
  77. },
  78. {
  79. "featureType": "railway",
  80. "elementType": "geometry.stroke",
  81. "stylers": {
  82. "color": "#08304b"
  83. }
  84. },
  85. {
  86. "featureType": "subway",
  87. "elementType": "geometry",
  88. "stylers": {
  89. "lightness": -70
  90. }
  91. },
  92. {
  93. "featureType": "building",
  94. "elementType": "geometry.fill",
  95. "stylers": {
  96. "color": "#000000"
  97. }
  98. },
  99. {
  100. "featureType": "all",
  101. "elementType": "labels.text.fill",
  102. "stylers": {
  103. "color": "#857f7f"
  104. }
  105. },
  106. {
  107. "featureType": "all",
  108. "elementType": "labels.text.stroke",
  109. "stylers": {
  110. "color": "#000000"
  111. }
  112. },
  113. {
  114. "featureType": "building",
  115. "elementType": "geometry",
  116. "stylers": {
  117. "color": "#022338"
  118. }
  119. },
  120. {
  121. "featureType": "green",
  122. "elementType": "geometry",
  123. "stylers": {
  124. "color": "#062032"
  125. }
  126. },
  127. {
  128. "featureType": "boundary",
  129. "elementType": "all",
  130. "stylers": {
  131. "color": "#1e1c1c"
  132. }
  133. },
  134. {
  135. "featureType": "manmade",
  136. "elementType": "geometry",
  137. "stylers": {
  138. "color": "#022338"
  139. }
  140. },
  141. {
  142. "featureType": "poi",
  143. "elementType": "all",
  144. "stylers": {
  145. "visibility": "off"
  146. }
  147. },
  148. {
  149. "featureType": "all",
  150. "elementType": "labels.icon",
  151. "stylers": {
  152. "visibility": "off"
  153. }
  154. },
  155. {
  156. "featureType": "all",
  157. "elementType": "labels.text.fill",
  158. "stylers": {
  159. "color": "#2da0c6",
  160. "visibility": "on"
  161. }
  162. }
  163. ]

3、数据格式:

shp文件转换成geojson,替换到 data.js 文件中

data.js 相关代码:

  1. var data = {geojson 数据}