Boat.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /**
  2. * 船舶地图组件功能,通过调用封装好的基础地图组件实现特定业务功能
  3. */
  4. import { fullExtent, clearMap, calculation, changeMap, setCamera,
  5. layerControl, layerQuery, addGraphic, draw, getDrawGeometry,
  6. addBoats, setBoatHistory, playBoatHistory, clearBoatHistory,
  7. getMapScale
  8. } from '@/utils/map/ArcgisUtil'
  9. import {GetHpjShip,GetBoatAISHistoryByMMSI} from "@/apis/ship";
  10. import {nextTick} from "vue";
  11. import bus from "@/utils/bus";
  12. let boatInterval;
  13. let showBoat = false;
  14. // 船舶定位
  15. export function locationBoat(mmsi,isShow){
  16. if(isShow){
  17. GetHpjShip().then(res=>{
  18. let data = res.Result.data
  19. let boats = {
  20. "scale": 2000,
  21. "goto": true,
  22. "data": []
  23. }
  24. for(let i=0;i<data.length;i++){
  25. if(data[i].DEVICEID == mmsi){
  26. let boat = {
  27. "mmsi": data[i].DEVICEID,
  28. "shipNameCn": data[i].BOATNAME,
  29. "shipTypeName": data[i].SHIPTYPENAME,
  30. "direction": data[i].DIRECTION,
  31. "velocity": data[i].VELOCITY,
  32. "shipBreadth": data[i].SHIPBREADTH,
  33. "shipLength": data[i].SHIPLENGTH,
  34. "mapx": data[i].MAPX,
  35. "mapy": data[i].MAPY
  36. }
  37. boats.data.push(boat)
  38. }
  39. }
  40. // console.log('定位:'+JSON.stringify(boats))
  41. addBoats(boats)
  42. })
  43. }else{
  44. if (!showBoat){
  45. clearMap({is_draw: false, is_search:false, layers: ['boatLayer']})
  46. }
  47. }
  48. }
  49. // 船舶撒点
  50. export function setBoat(isShow){
  51. if(isShow) {
  52. if (!showBoat){
  53. showBoat = true
  54. }else{
  55. return
  56. }
  57. onLocationBoat()
  58. if (boatInterval != null) {
  59. clearInterval(boatInterval)
  60. }
  61. boatInterval = setInterval(onLocationBoat, 10000)
  62. }else{
  63. if (showBoat){
  64. showBoat = false
  65. }
  66. if (boatInterval != null) {
  67. clearInterval(boatInterval)
  68. }
  69. clearMap({is_draw: false, is_search:true, layers: ['boatLayer','boatPathLayer']})
  70. }
  71. }
  72. // 加载船舶
  73. function onLocationBoat(){
  74. GetHpjShip().then(res=>{
  75. let data = res.Result.data
  76. let boats = {
  77. "scale": getMapScale(),
  78. "goto": false,
  79. "data": []
  80. }
  81. for(let i=0;i<data.length;i++){
  82. let boat = {
  83. "mmsi": data[i].DEVICEID,
  84. "shipNameCn": data[i].BOATNAME,
  85. "shipTypeName": data[i].SHIPTYPENAME,
  86. "direction": data[i].DIRECTION,
  87. "velocity": data[i].VELOCITY,
  88. "shipBreadth": data[i].SHIPBREADTH,
  89. "shipLength": data[i].SHIPLENGTH,
  90. "mapx": data[i].MAPX,
  91. "mapy": data[i].MAPY
  92. }
  93. boats.data.push(boat)
  94. }
  95. addBoats(boats)
  96. })
  97. }
  98. bus.on('playBoatPath', (params) => {
  99. nextTick(() => {
  100. setBoatPath(params)
  101. },{immediate: true});
  102. })
  103. // 设置船舶历史轨迹
  104. export function setBoatPath(data){
  105. GetBoatAISHistoryByMMSI({
  106. deviceId:data.mmsi,
  107. startTime:data.startTime,
  108. endTime:data.endTime
  109. }).then(res=>{
  110. let data = res.Result.data
  111. let historyPoints=[]
  112. for(let i=0;i<data.length;i++){
  113. let boat = {
  114. "gpsTime": data[i].GPSTIME,
  115. "mapx": data[i].MAPX,
  116. "mapy": data[i].MAPY
  117. }
  118. historyPoints.push(boat)
  119. }
  120. setBoatHistory(historyPoints)
  121. // setTimeout(function() {
  122. // playBoatHistory('start')
  123. // }, 5000);
  124. })
  125. }
  126. /**
  127. * 船舶轨迹播放
  128. * 开始:start,
  129. * 暂停:pause,
  130. * 继续:resume,
  131. * 停止:stop
  132. * @param type
  133. */
  134. bus.on('playBoatHistoryPath', (type) => {
  135. playBoatHistory(type)
  136. })
  137. /**
  138. * 清除船舶轨迹
  139. */
  140. export function clearBoatHistoryPath(){
  141. console.log('清除船舶')
  142. clearBoatHistory()
  143. }