echartsAnimatorCar.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="UTF-8">
  8. <title data-i18n="resources.title_animatorCar"></title>
  9. <script type="text/javascript" include="jquery" src="../js/include-web.js"></script>
  10. <script type="text/javascript" include="echarts,ol3-echarts" src="../../dist/ol/include-ol.js"></script>
  11. </head>
  12. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  13. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  14. <script type="text/javascript">
  15. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  16. var map, echartslayer, url = host + "/iserver/services/map-changchun/rest/maps/长春市区图";
  17. var extent = [48.4, -7668.25, 8958.85, -55.58];
  18. var projection = new ol.proj.Projection({
  19. code:'',
  20. extent: extent,
  21. units: 'm'
  22. });
  23. new ol.supermap.MapService(url).getMapInfo(function (serviceResult) {
  24. var mapJSONObj = serviceResult.result;
  25. map = new ol.Map({
  26. target: 'map',
  27. controls: ol.control.defaults({attributionOptions: {collapsed: false}})
  28. .extend([new ol.supermap.control.Logo()]),
  29. view: new ol.View({
  30. center: [4700, -3900],
  31. zoom: 3,
  32. projection: projection,
  33. origin: [48.4, -55.58],
  34. multiWorld: true
  35. })
  36. });
  37. var layer = new ol.layer.Tile({
  38. source: new ol.source.TileSuperMapRest(ol.source.TileSuperMapRest.optionsFromMapJSON(url, mapJSONObj))
  39. });
  40. map.addLayer(layer);
  41. echartslayer = new ol3Echarts(null, {
  42. hideOnMoving: true,
  43. hideOnZooming: true,
  44. //平面无投影坐标系不进行转换,绘制是不可转为其他投影坐标故设置此参数
  45. source: projection,
  46. destination: projection
  47. });
  48. echartslayer.appendTo(map);
  49. queryData();
  50. });
  51. function queryData() {
  52. var param = new SuperMap.QueryBySQLParameters({
  53. queryParams: {
  54. name: "BusLine@Changchun#1",
  55. attributeFilter: "SmID > 0"
  56. }
  57. });
  58. new ol.supermap.QueryService(url).queryBySQL(param, function (serviceResult) {
  59. addlayers(processData(serviceResult.result.recordsets[0].features.features));
  60. });
  61. function processData(features) {
  62. var busLines = [].concat.apply([], features.map(function (busLine) {
  63. var points = busLine.geometry.coordinates;
  64. return {
  65. coords: points,
  66. effect: {
  67. constantSpeed: 60,
  68. show: true,
  69. trailLength: 0,
  70. symbolSize: 30,
  71. symbol: function () {
  72. if ((Math.round(Math.random() * 2) % 2)) {
  73. return 'image://../classic/images/blueCar.png'
  74. } else {
  75. return 'image://../classic/images/redCar.png'
  76. }
  77. }()
  78. },
  79. };
  80. }));
  81. return busLines;
  82. }
  83. }
  84. function addlayers(busLines) {
  85. var option = {
  86. series: [{
  87. type: 'lines',
  88. polyline: true,
  89. data: busLines,
  90. silent: true,
  91. lineStyle: {
  92. normal: {
  93. opacity: 1,
  94. width: 1,
  95. color: '#000'
  96. }
  97. },
  98. progressiveThreshold: 500,
  99. progressive: 200,
  100. zlevel: 2
  101. },
  102. {
  103. type: 'lines',
  104. polyline: true,
  105. data: busLines,
  106. lineStyle: {
  107. normal: {
  108. width: 0
  109. }
  110. },
  111. effect: {
  112. constantSpeed: 60,
  113. show: true,
  114. trailLength: 0,
  115. symbolSize: 30,
  116. },
  117. zlevel: 1
  118. }]
  119. };
  120. echartslayer.setChartOptions(option);
  121. }
  122. </script>
  123. </body>
  124. </html>