map_0110.html 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>易粮易运数据分析平台</title>
  7. <style>
  8. html,
  9. body,
  10. #map {
  11. width: 100%;
  12. height: 100%;
  13. margin: 0;
  14. padding: 0;
  15. position: relative;
  16. }
  17. .title {
  18. background: black;
  19. color: white;
  20. text-align: center;
  21. font-size: 1.25rem;
  22. padding: 0.625rem;
  23. }
  24. .amap-marker {
  25. opacity: 0;
  26. }
  27. .amap-marker-label {
  28. background: rgba(125, 197, 255, 0.2);
  29. /* background:red; */
  30. z-index: 1158;
  31. border: 0px solid rgba(125, 197, 255, 0.2);
  32. color: #eee;
  33. padding: 40px;
  34. font-size: 12px;
  35. font-weight: 500;
  36. border-radius: 50%;
  37. }
  38. .progressBar {
  39. width: 50%;
  40. height: 25px;
  41. display: block;
  42. top: 0;
  43. left: 0;
  44. bottom: 0;
  45. right: 0;
  46. margin: auto;
  47. padding: 10px 10px 10px 10px;
  48. position: absolute;
  49. z-index: 2001;
  50. background: rgb(102, 102, 102);
  51. color: white;
  52. border-radius: 5px;
  53. }
  54. }
  55. </style>
  56. </head>
  57. <body>
  58. <div id="map"></div>
  59. <div id="progressBar" class="progressBar">地图数据加载中...</div>
  60. <script
  61. src="https://webapi.amap.com/maps?v=2.0&key=211dd6f989e719022aaf47ddb0659c47&plugin=AMap.Scale,AMap.ToolBar,AMap.Geocoder,AMap.Geolocation,Geolocation">
  62. </script>
  63. <script src="https://webapi.amap.com/loca?v=2.0.0&key=211dd6f989e719022aaf47ddb0659c47"></script>
  64. <script src="https://taohaoliang.oss-cn-beijing.aliyuncs.com/app/jquery.min.js"></script>
  65. <script>
  66. var markerList = []
  67. var mapPointData = {}
  68. var mapLineData = {}
  69. var timer = ''
  70. var compId = getUrlParam("id")
  71. var seachMoth = getUrlParam("seachMoth")
  72. $.ajax({
  73. type: "GET",
  74. contentType: "application/json;charset=UTF-8",
  75. url: "https://api2.eliangeyun.com/biInfoController/selectBiInfo?compId=" + compId+ '&seachMoth=' + seachMoth,
  76. success: function(result) {
  77. console.log("result", result);
  78. $("#progressBar").hide();
  79. var listData = result.data[9];
  80. console.log('收到vue的数据:', listData);
  81. let _features1 = []
  82. let _features2 = []
  83. for (let i = 0; i < listData.biViewInfoList.length; i++) {
  84. let _data = listData.biViewInfoList[i]
  85. let _coordinates1 = []
  86. let _coordinates11 = []
  87. let _position1 = _data.endPlace ? _data.endPlace.split(',') : []
  88. _coordinates1.push(Number(_position1[1]))
  89. _coordinates1.push(Number(_position1[0]))
  90. let _obj1 = {
  91. "type": "Feature",
  92. "properties": {
  93. "type": i,
  94. },
  95. "geometry": {
  96. "type": "Point",
  97. "coordinates": _coordinates1
  98. }
  99. }
  100. let _position11 = _data.startPlace ? _data.startPlace.split(',') : []
  101. _coordinates11.push(Number(_position11[1]))
  102. _coordinates11.push(Number(_position11[0]))
  103. let _obj11 = {
  104. "type": "Feature",
  105. "properties": {
  106. "type": i,
  107. },
  108. "geometry": {
  109. "type": "Point",
  110. "coordinates": _coordinates11
  111. }
  112. }
  113. _features1.push(_obj1)
  114. _features1.push(_obj11)
  115. let _coordinates2 = []
  116. let _start = []
  117. let _end = []
  118. let _marker = {}
  119. let _positionStart = _data.startPlace ? _data.startPlace.split(',') : []
  120. _start.push(Number(_positionStart[1]))
  121. _start.push(Number(_positionStart[0]))
  122. let _positionEnd = _data.endPlace ? _data.endPlace.split(',') : []
  123. _end.push(Number(_positionEnd[1]))
  124. _end.push(Number(_positionEnd[0]))
  125. _coordinates2.push(_start)
  126. _coordinates2.push(_end)
  127. _marker.iconSrc = _start
  128. _marker.name = _data.name
  129. markerList.push(_marker)
  130. let _obj2 = {
  131. "type": "Feature",
  132. "properties": {
  133. },
  134. "geometry": {
  135. "type": "LineString",
  136. "coordinates": _coordinates2
  137. }
  138. }
  139. _features2.push(_obj2)
  140. }
  141. mapPointData = {
  142. "type": "FeatureCollection",
  143. "features": _features1
  144. }
  145. mapLineData = {
  146. "type": "FeatureCollection",
  147. "features": _features2
  148. }
  149. console.log("mapPointData", mapPointData)
  150. console.log("mapPointData", mapLineData)
  151. var map = new AMap.Map('map', {
  152. zoom: 3,
  153. showLabel: true,
  154. viewMode: '3D',
  155. pitch: 0, //地圖仰角
  156. center: [101.991, 35.346],
  157. mapStyle: 'amap://styles/c0ed286f357b7f4c7312476637a7ab04',
  158. buildingAnimation: false,
  159. showIndoorMap: false,
  160. });
  161. var loca = new Loca.Container({
  162. map,
  163. });
  164. for (let i = 0; i < markerList.length; i++) {
  165. // 构造点标记
  166. if (markerList[i].iconSrc[0] && markerList[i].iconSrc[1]) {
  167. var marker = new AMap.Marker({
  168. position: markerList[i].iconSrc,
  169. anchor: 'bottom-center',
  170. icon: new AMap.Icon({
  171. image: 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/db5971c17f0930e0d5ee08966e08129.png',
  172. size: new AMap.Size(20, 35), //图标所处区域大小
  173. imageSize: new AMap.Size(20, 35) //图标大小
  174. }),
  175. })
  176. map.add(marker);
  177. marker.setLabel({
  178. offset: new AMap.Pixel(0, 0), //设置文本标注偏移量
  179. // content: "<div class = 'maker-item'>" + markerList[i].name +
  180. // "</div>", //设置文本标注内容
  181. content: "<div class = 'maker-item'></div>", //设置文本标注内容
  182. direction: 'center' //设置文本标注方位
  183. });
  184. }
  185. }
  186. // 定时刷新动画
  187. let _markerDom = document.getElementsByClassName('amap-marker')
  188. let _index = 0
  189. this.timer = setInterval(function() {
  190. _markerDom[_index].style.opacity = 1
  191. _markerDom[_index].style.transition = '2s'
  192. var elseLi = _markerDom;
  193. for (var i = 0; i < elseLi.length; i++) {
  194. if (elseLi[i] !== _markerDom[_index]) { //判断是否是ele节点,是否与触发事件的节点相同
  195. elseLi[i].style.opacity = 0
  196. _markerDom[_index].style.transition = '2s'
  197. }
  198. }
  199. _index++;
  200. if (_index == _markerDom.length) _index = 0
  201. }, 3000)
  202. // 呼吸点
  203. var scatter = new Loca.ScatterLayer({
  204. loca,
  205. zIndex: 10,
  206. opacity: 0.6,
  207. visible: true,
  208. zooms: [2, 22],
  209. });
  210. var pointGeo = new Loca.GeoJSONSource({
  211. // url: 'https://a.amap.com/Loca/static/loca-v2/demos/mock_data/pulselink-china-city-point.json',
  212. data: mapPointData
  213. });
  214. scatter.setSource(pointGeo);
  215. scatter.setStyle({
  216. unit: 'meter',
  217. size: [100000, 100000],
  218. borderWidth: 0,
  219. texture: 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/2399138c9ca1cb72f3e28a187c8914b.png',
  220. duration: 2000,
  221. animate: true,
  222. });
  223. loca.add(scatter);
  224. console.log(Loca)
  225. // 弧线
  226. var pulseLink = new Loca.PulseLinkLayer({
  227. // loca,
  228. zIndex: 10,
  229. opacity: 1,
  230. visible: true,
  231. zooms: [2, 22],
  232. depth: true,
  233. });
  234. var geo = new Loca.GeoJSONSource({
  235. // url: 'https://a.amap.com/Loca/static/loca-v2/demos/mock_data/data-line-out.json',
  236. data: mapLineData
  237. });
  238. pulseLink.setSource(geo);
  239. pulseLink.setStyle({
  240. unit: 'meter',
  241. dash: [40000, 10000, 40000, 10000],
  242. lineWidth: function() {
  243. return [3000, 2000];
  244. },
  245. height: function(index, feat) {
  246. return feat.distance / 3 + 10;
  247. },
  248. // altitude: 1000,
  249. smoothSteps: 30,
  250. speed: function(index, prop) {
  251. return 1000 + Math.random() * 200000;
  252. },
  253. flowLength: 100000,
  254. lineColors: function(index, feat) {
  255. return ['rgba(1, 192, 160, 1)'];
  256. },
  257. maxHeightScale: 0.3, // 弧顶位置比例
  258. headColor: 'rgb(36, 131, 255)',
  259. trailColor: 'rgba(255, 255,0,0)',
  260. });
  261. loca.add(pulseLink);
  262. loca.animate.start();
  263. // 点击事件处理
  264. var clickInfo = new AMap.Marker({
  265. anchor: 'bottom-center',
  266. position: [116.396923, 39.918203, 0],
  267. });
  268. clickInfo.setMap(map);
  269. clickInfo.hide();
  270. map.on("click", function(e) {
  271. var feat = pulseLink.queryFeature(e.pixel.toArray());
  272. if (feat) {
  273. clickInfo.show();
  274. var props = feat.properties;
  275. clickInfo.setPosition(feat.coordinates[1]);
  276. clickInfo.setContent(
  277. '<div style="text-align: center; height: 20px; width: 150px; color:#fff; font-size: 14px;">' +
  278. '速率: ' + feat.properties['ratio'] +
  279. '</div>'
  280. );
  281. } else {
  282. clickInfo.hide();
  283. }
  284. });
  285. },
  286. //请求失败,包含具体的错误信息
  287. error: function(e) {
  288. console.log(e);
  289. console.log(e.status);
  290. console.log(e.responseText);
  291. }
  292. });
  293. function getUrlParam(name) {
  294. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
  295. var r = window.location.search.substr(1).match(reg); //匹配目标参数
  296. if (r != null) return unescape(r[2]);
  297. return null; //返回参数值
  298. }
  299. </script>
  300. </body>
  301. </html>