alarmLayer.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. // 底图数据
  27. eventBus.on("alarmList:warningLayers", (data) => {
  28. this.warningLayers = data
  29. })
  30. // 预警底图
  31. eventBus.on("alarmList:changeMapLayer", function (layerUrl) {
  32. that.initLayer(layerUrl)
  33. })
  34. // 种植面积,预估产量,底图切换
  35. eventBus.on("warningHome:toggleMapLayer", function (name) {
  36. that.togglePlantLayer(name)
  37. })
  38. // 切换区域广东省or从化区
  39. that.areaId = "3"
  40. eventBus.on("warningHome:toggleArea", (id) => {
  41. that.areaId = id
  42. that.changeDistrict(id)
  43. })
  44. // 时间轴
  45. eventBus.on("weatherTime:changeTime", (index) => {
  46. console.log('vvv',index);
  47. that.toggleSmallLayer(index)
  48. })
  49. }
  50. initLayer(layerUrl) {
  51. this.lizhiLayer && this.kmap.map.removeLayer(this.lizhiLayer.layer)
  52. // 104.3017367175,30.329292136
  53. this.lizhiLayer = this.kmap.addXYZLayer(
  54. layerUrl,
  55. { minZoom: 5, maxZoom: 22 },
  56. 99,
  57. 0.4
  58. );
  59. this.lizhiLayer.layer.setOpacity(0.7)
  60. this.kmap.map.getView().setZoom(18)
  61. this.kmap.map.getView().setCenter([104.3017367175, 30.329292136])
  62. }
  63. togglePlantLayer(name) {
  64. const url = this.warningLayers[name]
  65. // const url = "https://birdseye-img.sysuimars.com/map/szts/{z}/{x}/{y}.png"
  66. // console.log('uu', url);
  67. this.plantLayer && this.kmap.map.removeLayer(this.plantLayer.layer)
  68. // 104.3017367175,30.329292136
  69. this.plantLayer = this.kmap.addXYZLayer(
  70. url,
  71. { minZoom: 6, maxZoom: 22 },
  72. 99,
  73. 0.4
  74. );
  75. this.plantLayer.layer.setOpacity(0.4)
  76. this.kmap.map.getView().setZoom(11)
  77. this.kmap.map.getView().setCenter([113.61702297075017, 23.584863449735067])
  78. // this.kmap.map.getView().setCenter([104.3017367175, 30.329292136])
  79. // this.plantLayer && this.kmap.map.removeLayer(this.plantLayer.layer)
  80. // // 104.3017367175,30.329292136
  81. // this.plantLayer = this.kmap.addXYZLayer(
  82. // url,
  83. // { minZoom: 5, maxZoom: 22 },
  84. // 99,
  85. // 0.4
  86. // );
  87. // this.plantLayer.layer.setOpacity(0.7)
  88. // this.kmap.map.getView().setZoom(18)
  89. // this.kmap.map.getView().setCenter([104.3017367175, 30.329292136])
  90. }
  91. // 切换地图区域
  92. changeDistrict(id) {
  93. VE_API.warning.fetchAreaDistrict({ id }).then(({ data }) => {
  94. if (data.geom) {
  95. let f = new Feature({
  96. geometry: new WKT().readGeometry(data.geom)
  97. })
  98. this.regionLayer.source.addFeature(f)
  99. this.kmap.map.getView().fit(f.getGeometry(), { padding: [180, 150, 100, 150] })
  100. }
  101. if (id === "3") {
  102. this.kmap.map.getView().setZoom(7.2)
  103. // const position = store.getters.userinfo.location
  104. this.kmap.map.getView().setCenter([113.61702297075017, 23.584863449735067])
  105. }
  106. })
  107. }
  108. // 从化区-切换到小范围
  109. toggleSmallLayer(index) {
  110. if (this.areaId === "3") {
  111. // 虚拟果园会播放物候变化
  112. }
  113. if (this.areaId === "3186") {
  114. this.kmap.map.getView().setZoom(12+index)
  115. // const position = store.getters.userinfo.location
  116. this.kmap.map.getView().setCenter([113.61702297075017, 23.584863449735067])
  117. }
  118. }
  119. }
  120. export default AlarmLayer;