alarmLayer.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import eventBus from "@/api/eventBus";
  2. import * as KMap from "@/utils/ol-map/KMap";
  3. import { Vector as VectorSource } from "ol/source.js";
  4. import Style from "ol/style/Style";
  5. import { WKT } from 'ol/format'
  6. import { Fill, Text } from "ol/style";
  7. import { Feature } from "ol";
  8. import store from '@/store'
  9. /**
  10. *
  11. */
  12. class AlarmLayer {
  13. constructor(kmap) {
  14. let that = this;
  15. this.kmap = kmap
  16. let vectorStyle = new KMap.VectorStyle()
  17. this.regionLayer = new KMap.VectorLayer("regionLayer", 3, {
  18. source: new VectorSource({}),
  19. style: function (f) {
  20. let style2 = vectorStyle.getPolygonStyle("#032833" + "30", "#c7cb20", 2)
  21. return [style2]
  22. }
  23. });
  24. this.kmap.addLayer(this.regionLayer.layer)
  25. this.warningLayers = {}
  26. this.plantLayer = null
  27. this.warningLayer = null
  28. this.nameStr = ''
  29. // 底图数据
  30. eventBus.on("alarmList:warningLayers", (data) => {
  31. this.warningLayers = data
  32. })
  33. // 预警底图
  34. eventBus.on("alarmList:changeMapLayer", function ({url, type,name}) {
  35. that.plantLayer && that.kmap.map.removeLayer(that.plantLayer.layer)
  36. that.nameStr = name
  37. console.log('sdadas',url);
  38. that.initWarningLayer(url, type,name)
  39. })
  40. // 种植面积,预估产量,底图切换
  41. eventBus.on("warningHome:toggleMapLayer", function (name) {
  42. that.warningLayer && that.kmap.map.removeLayer(that.warningLayer.layer)
  43. that.togglePlantLayer(name)
  44. })
  45. // 切换区域广东省or从化区
  46. that.areaId = "3"
  47. eventBus.on("warningHome:toggleArea", (id) => {
  48. that.plantLayer && that.kmap.map.removeLayer(that.plantLayer.layer)
  49. that.warningLayer && that.kmap.map.removeLayer(that.warningLayer.layer)
  50. that.areaId = id
  51. that.changeDistrict(id)
  52. })
  53. // 时间轴
  54. eventBus.on("weatherTime:changeTime", ({index}) => {
  55. that.toggleSmallLayer(index)
  56. })
  57. }
  58. initWarningLayer(layerUrl, type,name) {
  59. this.warningLayer && this.kmap.map.removeLayer(this.warningLayer.layer)
  60. // 104.3017367175,30.329292136
  61. let path = null
  62. let text = ''
  63. if(name==='日间温度'){
  64. text = '从化地块日温'
  65. path = this.warningLayers[text]
  66. }else if(name==='夜间温度'){
  67. text = '从化地块夜温'
  68. path = this.warningLayers[text]
  69. }else if(name==='土壤水分'){
  70. text = '从化地块水分'
  71. path = this.warningLayers[text]
  72. }else{
  73. path = layerUrl
  74. }
  75. console.log('path',path);
  76. this.warningLayer = this.kmap.addXYZLayer(
  77. path,
  78. { minZoom: 5, maxZoom: 22 },
  79. 99,
  80. 0.4
  81. );
  82. this.warningLayer.layer.setOpacity(0.67)
  83. if (type === 1) {
  84. this.kmap.map.getView().setZoom(7.6)
  85. // 23.310292140601142,113.10638639232688
  86. this.kmap.map.getView().setCenter([113.609050, 23.30707646])
  87. }
  88. // 23.407672480519803,113.07739330484166
  89. // this.kmap.map.getView().setZoom(18)
  90. // this.kmap.map.getView().setCenter([104.3017367175, 30.329292136])
  91. }
  92. togglePlantLayer(name) {
  93. const url = this.warningLayers[name]
  94. // const url = "https://birdseye-img.sysuimars.com/map/szts/{z}/{x}/{y}.png"
  95. // console.log('uu', url);
  96. this.plantLayer && this.kmap.map.removeLayer(this.plantLayer.layer)
  97. // 104.3017367175,30.329292136
  98. this.plantLayer = this.kmap.addXYZLayer(
  99. url,
  100. { minZoom: 6, maxZoom: 22 },
  101. 99,
  102. 0.4
  103. );
  104. this.plantLayer.layer.setOpacity(0.6)
  105. if (name !== "从化荔枝") {
  106. this.kmap.map.getView().setZoom(7.6)
  107. this.kmap.map.getView().setCenter([113.609050, 23.30707646])
  108. } else {
  109. this.kmap.map.getView().setZoom(11)
  110. this.kmap.map.getView().setCenter([113.679, 23.607])
  111. }
  112. // this.kmap.map.getView().setCenter([113.679, 23.607])
  113. // this.kmap.map.getView().setCenter([104.3017367175, 30.329292136])
  114. // this.plantLayer && this.kmap.map.removeLayer(this.plantLayer.layer)
  115. // // 104.3017367175,30.329292136
  116. // this.plantLayer = this.kmap.addXYZLayer(
  117. // url,
  118. // { minZoom: 5, maxZoom: 22 },
  119. // 99,
  120. // 0.4
  121. // );
  122. // this.plantLayer.layer.setOpacity(0.7)
  123. // this.kmap.map.getView().setZoom(18)
  124. // this.kmap.map.getView().setCenter([104.3017367175, 30.329292136])
  125. }
  126. // 切换地图区域
  127. changeDistrict(id) {
  128. VE_API.warning.fetchAreaDistrict({ id }).then(({ data }) => {
  129. if (data.geom) {
  130. let f = new Feature({
  131. geometry: new WKT().readGeometry(data.geom)
  132. })
  133. this.regionLayer.source.addFeature(f)
  134. this.kmap.map.getView().fit(f.getGeometry(), { padding: [180, 150, 100, 150] })
  135. }
  136. if (id === "3") {
  137. this.kmap.map.getView().setZoom(7.2)
  138. // const position = store.getters.userinfo.location
  139. this.kmap.map.getView().setCenter([113.679, 23.607])
  140. }
  141. })
  142. }
  143. // 从化区-切换到小范围
  144. toggleSmallLayer(index) {
  145. if (this.areaId === "3") {
  146. // 虚拟果园会播放物候变化
  147. }
  148. if (this.areaId === "3186") {
  149. let text = '荔博园地块日温'
  150. if(this.nameStr === '夜间温度'){
  151. text = '荔博园地块夜温'
  152. }
  153. let path = this.warningLayers[text + index]
  154. if(this.nameStr === '土壤水分'){
  155. text = '荔博园地块水分0'
  156. path = this.warningLayers[text]
  157. }
  158. let url = path
  159. // if (index === 0) {
  160. // url = "https://birdseye-img.sysuimars.com/map/risk/lby_ghqs/{z}/{x}/{y}.png"
  161. // } else if (index === 1) {
  162. // url = "https://birdseye-img.sysuimars.com/map/risk/lby_dwdh/{z}/{x}/{y}.png"
  163. // }
  164. this.warningLayer && this.kmap.map.removeLayer(this.warningLayer.layer)
  165. // 104.3017367175,30.329292136
  166. this.warningLayer = this.kmap.addXYZLayer(
  167. url,
  168. { minZoom: 5, maxZoom: 22 },
  169. 99,
  170. 0.4
  171. );
  172. this.warningLayer.layer.setOpacity(0.6)
  173. // this.kmap.map.getView().setZoom(12+index)
  174. // const position = store.getters.userinfo.location
  175. this.kmap.map.getView().setZoom(16.6)
  176. // 23.60747406160339,113.6805952006568
  177. this.kmap.map.getView().setCenter([113.6805952006568, 23.60747406160339])
  178. }
  179. }
  180. }
  181. export default AlarmLayer;