fire.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. import { Entity, NearFarScalar, PolylineDashMaterialProperty, DistanceDisplayCondition, Cartesian3, Color, PropertyBag } from "cesium";
  2. import { getTagList } from "@/API/fire";
  3. import { flyToByViewer, addNewDatasource, flyToPerspective } from "@/utils/mapUtil";
  4. import { _locate } from '@/utils'
  5. import { getViewer } from "@/store/map/mapService";
  6. import { mapGetters } from 'vuex'
  7. export default {
  8. data() {
  9. return {
  10. fireTagsData: [],
  11. fireAlarmIds: [],
  12. cloneFireTagsData: [],
  13. };
  14. },
  15. computed: {
  16. ...mapGetters(['buildId', 'buildInfo', 'mapMode', 'switchConfig']),
  17. fireTagsShow() {
  18. if (this.mapMode.value === '3d') {
  19. return this.switchConfig.find(e => e?.type && e.type === 'fire')?.show
  20. } else {
  21. return false
  22. }
  23. },
  24. },
  25. watch: {
  26. buildId: {
  27. handler(val) {
  28. if (!val) return
  29. setTimeout(() => {
  30. // console.log('火灾图层建筑变化', val)
  31. this.getFireTagsData()
  32. // this.animationFire({})
  33. }, 1000)
  34. },
  35. immediate: true,
  36. },
  37. },
  38. mounted() {
  39. setTimeout(() => {
  40. this.initFire()
  41. }, 1000)
  42. },
  43. methods: {
  44. initFire() {
  45. this.$store.dispatch("globalConfig/pushSwitchConfig", {
  46. type: "fire",
  47. label: "火灾监测",
  48. name: "火灾监测",
  49. show: false,
  50. selected: false,
  51. elements: this.fireTagsData,
  52. });
  53. },
  54. async getFireTagsData() {
  55. try {
  56. let p = { buildId: this.buildInfo.positioningBuildId }
  57. // console.log('火灾数据获取参数:', p)
  58. let res = await getTagList(p);
  59. this.fireTagsData = res.data.content || [];
  60. // console.log("火灾信息", this.fireTagsData);
  61. this.$store.dispatch("globalConfig/updateSwitchConfig", {
  62. type: "fire",
  63. label: "火灾监测",
  64. name: "火灾监测",
  65. show: this.fireTagsShow,
  66. selected: false,
  67. elements: this.fireTagsData,
  68. });
  69. this.addFireTags();
  70. } catch (err) {
  71. console.log(err);
  72. }
  73. },
  74. addFireTags() {
  75. let dataSource = addNewDatasource("layer_fire");
  76. this.fireTagsData.forEach((data, index) => {
  77. const gpsPoint = this.transPosition([{ x: data.location.x, y: data.location.y, z: data.height }])
  78. dataSource.entities.add(
  79. new Entity({
  80. id: data.id,
  81. position: Cartesian3.fromDegrees(...gpsPoint[0]),
  82. show: this.fireTagsShow,
  83. billboard: {
  84. image: BASE_URL + data.iconPath,
  85. scale: 0.5, //固定值
  86. scaleByDistance: new NearFarScalar(10, 1, 10000, 1),
  87. },
  88. polyline: {
  89. positions: Cartesian3.fromDegreesArrayHeights([
  90. gpsPoint[0][0],
  91. gpsPoint[0][1],
  92. gpsPoint[0][2],
  93. gpsPoint[0][0],
  94. gpsPoint[0][1],
  95. 0,
  96. ]),
  97. width: 2,
  98. material: new PolylineDashMaterialProperty({
  99. color: Color.CYAN,
  100. }),
  101. },
  102. properties: new PropertyBag({
  103. type: "layer_fire",
  104. details: data,
  105. }),
  106. })
  107. );
  108. });
  109. },
  110. async pushFireStatus(data) {
  111. if (data.id) {
  112. this.fireAlarmIds = [data.id]
  113. } else {
  114. data.id = this.fireAlarmIds.length ? this.fireAlarmIds[0] : ''
  115. }
  116. if (data.alarmType > 0) {
  117. // console.log('火灾报警数据:', data)
  118. //模型判断与切换
  119. if (data?.buildId === this.buildInfo?.positioningBuildId) {
  120. // console.log("聚焦报警");
  121. this.animationFire(data)
  122. } else {
  123. const curStation = GY_STATIONS.find(e => e.positioningBuildId === data.buildId)
  124. // console.log('报警站点信息:', curStation)
  125. if (!curStation) return
  126. this.$store.dispatch('globalConfig/setMapMode', {
  127. value: '3d',
  128. })
  129. await this.$store.dispatch('model/setBuildInfoByBuildId', curStation.buildId)
  130. setTimeout(() => {
  131. this.animationFire(data)
  132. }, 3000)
  133. }
  134. } else {
  135. this.animationFire(data)
  136. }
  137. },
  138. animationFire(data) {
  139. const viewer = getViewer()
  140. const dataSource = viewer.dataSources.getByName('layer_fire')
  141. if (dataSource.length > 0) {
  142. let item = dataSource[0].entities.getById(data.id)
  143. // console.log(item, "地图实体数据", item.properties.details._value, '接收参数', data);
  144. if (!!item) {
  145. const { longitude, latitude } = this.buildInfo.gpsCoordinate0
  146. const gpsAlarmPoint = _locate(item.properties.details._value.location.x, item.properties.details._value.location.y, { x: longitude, y: latitude })
  147. if (data.alarmType > 0 && data.alarmType !== 4) {
  148. //报警声音
  149. this.$store.dispatch("globalConfig/setAlarmAudio", {
  150. show: true,
  151. alarmType: data.alarmType,
  152. data: data
  153. });
  154. //报警光效
  155. this.$store.dispatch("globalConfig/setAnimationEnable", {
  156. show: true,
  157. dialogMsg: {
  158. level: data.alarmType,
  159. },
  160. type: "All",
  161. });
  162. //报警点标记
  163. if (data.alarmPoint) {
  164. //地图元素
  165. item.show = true
  166. setTimeout(() => {
  167. item.billboard = {
  168. image: BASE_URL + item.properties.details._value.alarmIconPath,
  169. width: 50,
  170. height: 50,
  171. // verticalOrigin: VerticalOrigin.BOTTOM,
  172. distanceDisplayCondition: new DistanceDisplayCondition(0, 700.0),
  173. }
  174. item.position = Cartesian3.fromDegrees(gpsAlarmPoint.x, gpsAlarmPoint.y, item.properties.details._value.height)
  175. //视角漂移
  176. // flyToByViewer(item)
  177. flyToPerspective({
  178. destination: Cartesian3.fromDegrees(gpsAlarmPoint.x + 0.00026, gpsAlarmPoint.y - 0.0011, 100),
  179. orientation: {
  180. pitch: -0.549380381243696,
  181. heading: 6.181746598877237,
  182. roll: 0.0000025332551629730915, //倾斜视角坐标需要加偏移量
  183. },
  184. duration: 1.5,
  185. })
  186. //增加属性
  187. item.properties.details._value.alarmId = data.alarmId
  188. item.properties.details._value.alarmPoint = data.alarmPoint
  189. item.properties.details._value.alarmType = data.alarmType
  190. item.properties.details._value.camera = data.camera
  191. item.properties.details._value.alarmState = 1
  192. item.properties.details._value.alarmStatus = true
  193. item.properties.details._value.alarmPosition = [gpsAlarmPoint.x, gpsAlarmPoint.y, item.properties.details._value.height]
  194. // console.log(item.properties.details._value, "66666666666666666666666666666");
  195. //数据
  196. this.$store.dispatch('globalConfig/updateAlarmDataObj', {
  197. fire: [item.properties.details._value],
  198. })
  199. //视频弹窗
  200. if (!!data?.camera?.id) {
  201. this.$store.dispatch('dialog/openVideoDialog', data.camera.id)
  202. }
  203. }, 1000)
  204. } else {
  205. item.show = true
  206. setTimeout(() => {
  207. item.billboard = {
  208. image: BASE_URL + item.properties.details._value.iconPath,
  209. width: 50,
  210. height: 50,
  211. distanceDisplayCondition: new DistanceDisplayCondition(0, 700.0),
  212. }
  213. item.position = Cartesian3.fromDegrees(gpsAlarmPoint.x, gpsAlarmPoint.y, item.properties.details._value.height)
  214. }, 200)
  215. }
  216. } else {
  217. //报警声音
  218. this.$store.dispatch("globalConfig/setAlarmAudio", {
  219. show: false,
  220. alarmType: data.alarmType,
  221. });
  222. //报警光效
  223. this.$store.dispatch("globalConfig/setAnimationEnable", {
  224. show: false,
  225. dialogMsg: {
  226. level: data.alarmType,
  227. },
  228. type: "All",
  229. });
  230. item.show = true
  231. setTimeout(() => {
  232. item.billboard = {
  233. image: BASE_URL + item.properties.details._value.iconPath,
  234. width: 50,
  235. height: 50,
  236. distanceDisplayCondition: new DistanceDisplayCondition(0, 700.0),
  237. }
  238. item.position = Cartesian3.fromDegrees(gpsAlarmPoint.x, gpsAlarmPoint.y, item.properties.details._value.height)
  239. }, 200)
  240. //增加属性
  241. item.properties.details._value.alarmId = 0
  242. item.properties.details._value.alarmPoint = data.alarmPoint
  243. item.properties.details._value.alarmType = data.alarmType
  244. item.properties.details._value.camera = data.camera
  245. item.properties.details._value.alarmState = 0
  246. item.properties.details._value.alarmStatus = false
  247. item.properties.details._value.alarmPosition = [gpsAlarmPoint.x, gpsAlarmPoint.y, item.properties.details._value.height]
  248. this.$store.dispatch('globalConfig/updateAlarmDataObj', {
  249. fire: [item.properties.details._value],
  250. })
  251. // console.log('火灾信息测试', gpsAlarmPoint, item.properties.details._value, this.fireTagsData);
  252. }
  253. }
  254. }
  255. },
  256. transPosition(pointList = []) {
  257. const { longitude, latitude } = this.buildInfo.gpsCoordinate0
  258. return pointList.reduce((pre, cur) => {
  259. const { x, y } = _locate(cur.x, cur.y, { x: longitude, y: latitude })
  260. pre.push([x, y, +cur.z])
  261. return pre
  262. }, [])
  263. },
  264. },
  265. };