trail.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. window._AMapSecurityConfig = {
  2. securityJsCode:"14720ba5bb6ba2553facb5fc6b6777c2",
  3. }
  4. //设备图标
  5. const online = 'https://iot3d-oss.baozhida.cn/UpImage/1681698375d21af1db-3fd2-4032-b7cb-8ee8ac5f6cab.png';
  6. const offline = 'https://iot3d-oss.baozhida.cn/UpImage/168169835869ac506d-f228-46a4-8878-9969b95e6424.png';
  7. const danger = 'https://iot3d-oss.baozhida.cn/UpImage/1681698340c67c3a5a-7cf6-4fbf-be29-7ffae9d31ec1.png';
  8. //设备图标
  9. const online_x = 'https://iot3d-oss.baozhida.cn/UpImage/箱子-绿.png';
  10. const offline_x = 'https://iot3d-oss.baozhida.cn/UpImage/箱子-灰.png';
  11. const danger_x = 'https://iot3d-oss.baozhida.cn/UpImage/箱子-红.png';
  12. //地图标注图标
  13. const start = 'https://iot3d-oss.baozhida.cn/UpImage/16816984598b22098e-272f-48f7-a209-8bdc9fb46744.png';
  14. const pass = 'https://iot3d-oss.baozhida.cn/UpImage/16816984821af72d4e-3be8-46c4-8e58-5351b49b5153.png';
  15. const end = 'https://iot3d-oss.baozhida.cn/UpImage/16816984681ddcd8f0-a60d-455d-b455-42ac83535694.png';
  16. const imageUrlMap = new Map();
  17. imageUrlMap.set(0, offline);
  18. imageUrlMap.set(1, online);
  19. imageUrlMap.set(2, danger);
  20. imageUrlMap.set(3, offline_x);
  21. imageUrlMap.set(4, online_x);
  22. imageUrlMap.set(5, danger_x);
  23. $(window).load(function () {
  24. InitMap()
  25. });
  26. var trail_map = null
  27. // 高德地图轨迹
  28. function InitMap() {
  29. if(trail_map != null) return
  30. console.log("执行了初始化")
  31. AMapLoader.load({
  32. key: "51515b72616c71999b6607314e553953", // 申请好的Web端开发者Key,首次调用 load 时必填
  33. version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
  34. }).then((AMap)=>{
  35. trail_map = new AMap.Map("v_trail", {
  36. resizeEnable: true,
  37. // center: [ [{center}] ],
  38. // zoom: [{zoom}],
  39. features: ['bg', 'road', 'building', 'point'], // 设置地图显示要素(Features) 区域面(bg) 道路(road) 建筑物(building) 标注(point)
  40. });
  41. trail_map.setMapStyle("amap://styles/darkblue");
  42. // getCompany_zhi()
  43. //单击地图就清除infoWindow
  44. AMap.Event.addListener(trail_map, 'click', () => {
  45. trail_map.clearInfoWindow();
  46. });
  47. //双击清除所有轨迹
  48. AMap.Event.addListener(trail_map, 'dblclick', () => {
  49. console.log('双击了地图,删除轨迹!');
  50. trail_map.remove(listMarker);
  51. trail_map.remove(polyLine);
  52. });
  53. }).catch((e)=>{
  54. console.error(e); //加载错误提示
  55. });
  56. }
  57. GPS_fruits = new Map()
  58. // 渲染所有点
  59. function f_v_trail() {
  60. // 创建包含4个节点的折线及文字标注
  61. var path_gps = [
  62. // new AMap.LngLat(116.368904,39.913423),
  63. // new AMap.LngLat(116.398258,39.904600)
  64. ];
  65. for (var C_key in C_json.Device.DeviceList) {
  66. Device_r = C_json.Device.DeviceList[C_key]
  67. if (Device_r.T_Site.length > 2){
  68. ps = Device_r.T_Site.split(',');
  69. path_gps.push(new AMap.LngLat(Number.parseFloat(ps[0]),Number.parseFloat(ps[1])))
  70. }
  71. }
  72. AMap.convertFrom(path_gps, 'gps', (status, result) => {
  73. console.log("convertFrom:",result)
  74. if (result.info === 'ok') {
  75. let i_x = 0;
  76. for(let i = 0; i < C_json.Device.DeviceList.length; i++) {
  77. if (C_json.Device.DeviceList[i].T_Site.length > 2) {
  78. console.log("GPS_fruits SET",C_json.Device.DeviceList[i].T_Site, result.locations[i_x])
  79. GPS_fruits.set(C_json.Device.DeviceList[i].T_Site, result.locations[i_x]);
  80. i_x++
  81. }
  82. }
  83. console.log("path_gps",path_gps.length," i_x:",i_x)
  84. for (var C_key in C_json.Device.DeviceList) {
  85. Device_r = C_json.Device.DeviceList[C_key]
  86. if (Device_r.T_Site.length > 2) {
  87. AMapaddPoint(Device_r) // 轨迹加载点
  88. }
  89. }
  90. return;
  91. }
  92. });
  93. }
  94. // -------------
  95. const AMapaddPoint = (sensor) => {
  96. console.log("AMapaddPoint:",sensor)
  97. if(sensor.T_type < 200){
  98. return
  99. }
  100. let state = sensor.T_monitor;
  101. if (state == 1){
  102. if (sensor.T_t > sensor.T_Tupper || sensor.T_rh > sensor.T_RHupper || sensor.T_t < sensor.T_Tlower || sensor.T_rh < sensor.T_RHlower) {
  103. state = 2;
  104. }
  105. }
  106. if(sensor.T_type == 200 ||sensor.T_type == 210 || sensor.T_type == 220 || sensor.T_type == 230){
  107. state+=3
  108. }
  109. //坐标转换 start
  110. const convertPosition = async (position) => {
  111. if(GPS_fruits.has(position)){
  112. console.log("GPS_fruits",position,GPS_fruits.get(position))
  113. return GPS_fruits.get(position)
  114. }
  115. const ps = position.split(',');
  116. return new Promise((resolve, reject) => {
  117. AMap.convertFrom([Number.parseFloat(ps[0]), Number.parseFloat(ps[1])], 'gps', (status, result) => {
  118. console.log("convertFrom:",result.info)
  119. if (result.info === 'ok') {
  120. GPS_fruits.set(k_, result.locations[0]);
  121. resolve(result.locations[0]);
  122. return;
  123. }
  124. });
  125. });
  126. };
  127. //坐标转换, 添加标记点 start
  128. convertPosition(sensor.T_Site).then((v) => {
  129. const marker = mapAddPoint(sensor.T_sn, [v.lng, v.lat], state);
  130. // console.log("marker:",sensor.T_sn,sensor.T_name, marker)
  131. addClickShowTrack(sensor.T_sn,sensor.T_name, marker);
  132. trail_map.add(marker);
  133. trail_map.setFitView(null, false, [50, 50, 600, 600]);
  134. });
  135. //添加坐标en
  136. //坐标转换 end
  137. };
  138. //坐标转换 end
  139. //添加point start
  140. function mapAddPoint(sn, ps, state) {
  141. //@ts-ignore
  142. const option = {
  143. icon: new AMap.Icon({
  144. imageSize: [40, 40],
  145. image: imageUrlMap.get(state) || offline,
  146. size: new AMap.Size(40, 40)
  147. }),
  148. position: ps
  149. };
  150. const marker = new AMap.Marker(option);
  151. return marker;
  152. };
  153. //添加point end
  154. function addClickShowTrack(sn,T_name, marker) {
  155. //@ts-ignore
  156. AMap.Event.addListener(marker, 'click', () => {
  157. getDeviceTaskList(sn).then((resp) => {
  158. const list = resp.Data;
  159. let content = `
  160. <div style="font-size: 15px;padding: 10px; border-radius: 6px;background-color: white; position: relative;">
  161. <div style="position: absolute;left:50%;bottom: 0;background-color:white;padding: 10px;transform: translate(-50%,50%) rotate(-45deg);"></div>`;
  162. content += `<p style="text-align: center;margin: 15px;/*! padding: 6px; */border: solid 1px #f00;border-radius: 6px;margin-top: 0px;color: #f00;border-left-width: 0px;border-right-width: 0px;border-top-width: 0px;border-bottom-width: 2px;padding-bottom: 5px;" >`+T_name+`</p>`;
  163. if (list.length == 0){
  164. content += `<p style="margin: 15px;padding: 6px;border: solid 1px #eeeeee;border-radius: 6px;" >没有找到任务</p>`;
  165. }else {
  166. Array.from(list).forEach(v => {
  167. if (v === "0001-01-01 00:00:00"){
  168. v = "现在"
  169. }
  170. content += `<p style="margin: 15px;padding: 6px;border: solid 1px #eeeeee;border-radius: 6px;" onclick="loadingTrack('${sn}', ['${v.T_Ut_start}','${ v.T_Ut_end}']);">${v.T_Ut_start} ~ ${v.T_Ut_end}</p>`;
  171. });
  172. }
  173. // Array.from(list).forEach(v => {
  174. // content += `<p style="margin: 15px;padding: 6px;border: solid 1px #eeeeee;border-radius: 6px;" onclick="loadingTrack(${sn}, ['${v.T_Ut_start}','${ v.T_Ut_end}']);">${v.T_Ut_start} ~ ${v.T_Ut_end}</p>`;
  175. // });
  176. content += '</div>';
  177. const infoWindow = new AMap.InfoWindow({
  178. isCustom: true,
  179. content: content,
  180. offset: new AMap.Pixel(20, -15)
  181. });
  182. const ps = marker.getPosition();
  183. infoWindow.open(trail_map, [ps.lng, ps.lat]);
  184. console.log(infoWindow,ps, marker);
  185. });
  186. });
  187. };
  188. //# sourceMappingURL=pointHandle.js.map
  189. const listMarker = [];
  190. const listPolyLinePath = [];
  191. let polyLine;
  192. //加载track start
  193. function loadingTrack(sn, timeRange) {
  194. console.log(sn, " 轨迹显示 ",timeRange);
  195. //去除其他显示
  196. if (listMarker.length !== 0)
  197. trail_map.remove(listMarker);
  198. if (polyLine !== undefined)
  199. trail_map.remove(polyLine);
  200. listPolyLinePath.length = 0;
  201. listMarker.length = 0;
  202. console.log('执行到获取数据了')
  203. getDeviceSensorData(sn, timeRange).then((resp) => {
  204. const list = resp.Data;
  205. console.log("响应信息:",list)
  206. if (list == null || list.length === 0) {
  207. alert("数据正在上传...!")
  208. return;
  209. }
  210. //去除开始和结束
  211. Array.from(list.slice(1, list.length - 1)).forEach((v) => {
  212. const d = trackPoint(v, pass, trail_map);
  213. console.log("d:",d)
  214. if(d.lnglat.kT != 0) {
  215. listMarker.unshift(d.marker);
  216. listPolyLinePath.unshift(d.lnglat);
  217. }
  218. });
  219. // //去除开始和结束
  220. // Array.from(list.slice(1, list.length - 1)).forEach((v) => {
  221. // const d = trackPoint(v, pass, trail_map);
  222. // console.log("d:",d)
  223. // if(d.lnglat.kT != 0) {
  224. // listMarker.unshift(d.marker);
  225. // listPolyLinePath.unshift(d.lnglat);
  226. // }
  227. //
  228. // });
  229. //开始和结束
  230. const endData = trackPoint(list[list.length - 1], end, trail_map);
  231. const startData = trackPoint(list[0], start, trail_map);
  232. if(endData.lnglat.kT != 0) {
  233. listMarker.push(endData.marker);
  234. listPolyLinePath.push(endData.lnglat);
  235. }
  236. if(startData.lnglat.kT != 0) {
  237. listMarker.unshift(startData.marker);
  238. // listPolyLinePath.unshift(startData.lnglat);
  239. }
  240. trail_map.add(listMarker);
  241. console.log("listPolyLinePath:",listPolyLinePath)
  242. //添加轨迹
  243. polyLine = new AMap.Polyline({
  244. path: listPolyLinePath,
  245. borderWeight: 1,
  246. strokeColor: 'skyblue',
  247. lineJoin: 'round'
  248. });
  249. trail_map.add(polyLine);
  250. });
  251. console.log('loadingTrack 执行完了')
  252. };
  253. //加载track end
  254. function trackPoint(v, img, map) {
  255. const ps = v.T_site.split(',');
  256. const lnglat = new AMap.LngLat(Number.parseFloat(ps[0]), Number.parseFloat(ps[1]));
  257. const option = {
  258. icon: new AMap.Icon({
  259. imageSize: [40, 40],
  260. image: img,
  261. size: [40, 40],
  262. }),
  263. position: lnglat,
  264. offset: new AMap.Pixel(-20, -30),
  265. };
  266. const marker = new AMap.Marker(option);
  267. //@ts-ignore
  268. AMap.Event.addListener(marker, 'click', () => {
  269. const infoWindow = new AMap.InfoWindow({
  270. isCustom: true,
  271. content: getDeviceSensorDataInfo(v),
  272. offset: new AMap.Pixel(-3, -55),
  273. });
  274. infoWindow.open(map, [lnglat.lng, lnglat.lat]);
  275. });
  276. return {marker: marker, lnglat: lnglat};
  277. };
  278. function getDeviceSensorDataInfo(v) {
  279. let content = `
  280. <div style="font-size: 15px;padding: 10px; border-radius: 6px;background-color: white; position: relative;">
  281. <div style="position: absolute;left:50%;bottom: 0;background-color:white;padding: 10px;transform: translate(-50%,50%) rotate(-45deg);"></div>`;
  282. return content+`
  283. <div class="border rounded shadow bg-white p-2 text-dark">
  284. <p class="m-1">设备名称:${v.T_name} </p>
  285. <p class="m-1">当前温度:${v.T_t} <span class="m-1"></span> 当前湿度: ${v.T_rh}</p>
  286. <p class="m-1">温度上下限:${v.T_Tlower} ~ ${v.T_Tupper} <span class="m-1"></span> 湿度上下限:${v.T_RHlower} ~ ${v.T_RHupper}</p>
  287. <p class="m-1">记录时间:${v.T_time}</p>
  288. </div>
  289. </div>
  290. `;
  291. };
  292. //# sourceMappingURL=tarckHandle.js.map
  293. //获取设备任务列表
  294. function getDeviceTaskList (sn){
  295. return new Promise((resolve, reject) => {
  296. $.ajax({
  297. async:false,
  298. method:"POST",
  299. url: "./DeviceTask_List",
  300. data: {
  301. T_sn: sn,
  302. },
  303. success: function (rlt) {
  304. console.log(rlt)
  305. resolve(rlt)
  306. }
  307. })
  308. })
  309. }
  310. //获取设备探头数据
  311. function getDeviceSensorData(sn,timeRanges) {
  312. return new Promise((resolve, reject)=>{
  313. $.ajax(({
  314. async:false,
  315. method: "POST",
  316. url: "./DeviceData_List",
  317. data:{
  318. Time_start: timeRanges[0],
  319. Time_end: timeRanges[1],
  320. T_sn: sn,
  321. },
  322. success: function (rlt){
  323. console.log(rlt)
  324. resolve(rlt)
  325. }
  326. }))
  327. })
  328. }