map.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <div class="map-ditu">
  3. <!-- 分析事件中 风场信息展示地图组件 -->
  4. <Tmap
  5. ref="map"
  6. :windEngineGroupByFieldCodeDetail="windEngineGroupByFieldCodeDetail"
  7. >
  8. </Tmap>
  9. </div>
  10. </template>
  11. <script>
  12. import {
  13. getWindEngineGroupByFieldCode,
  14. getWindEngineGroupRatedListByFieldCodePage,
  15. } from "@/api/ledger.js";
  16. import Tmap from "@/components/map";
  17. export default {
  18. name: "Index",
  19. components: {
  20. Tmap,
  21. },
  22. data() {
  23. return {
  24. fieldCode: "",
  25. batchCode: "",
  26. windEngineGroupByFieldCodeDetail: {},
  27. };
  28. },
  29. mounted() {
  30. this.fieldCode = this.$route.query.fieldEngineCode;
  31. this.batchCode = this.$route.query.batchCode;
  32. // this.addMarkersAndZoom();
  33. },
  34. watch: {
  35. fieldCode(newVal) {
  36. if (newVal) {
  37. this.GETfengji();
  38. }
  39. },
  40. },
  41. methods: {
  42. GETfengji() {
  43. let dataArr = {
  44. fieldCode: this.fieldCode,
  45. batchCode: this.batchCode,
  46. };
  47. getWindEngineGroupByFieldCode(dataArr).then((res) => {
  48. const result = res.data;
  49. this.windEngineGroupByFieldCodeDetail = result;
  50. if (result !== null && result.anemometerTowerList) {
  51. this.addMarkersAndZoom(result.anemometerTowerList, "5");
  52. }
  53. if (this.$route.query.fieldEngineCode) {
  54. getWindEngineGroupRatedListByFieldCodePage({
  55. fieldCode: this.$route.query.fieldEngineCode,
  56. pageSize: 9999999,
  57. }).then((windRes) => {
  58. if (windRes.data && windRes.data.list) {
  59. // 定义两个数组来存放不同errorState的元素
  60. const errorStateFalse = [];
  61. const errorStateTrue = [];
  62. // 遍历数组并根据errorState的值将元素放入不同的数组中
  63. windRes.data.list.forEach((item) => {
  64. errorStateFalse.push({
  65. ...item,
  66. longitudeAndLatitudeString: `${item.longitude}00,${item.latitude}00`,
  67. });
  68. });
  69. // 调用this.addMarkersAndZoom方法
  70. if (errorStateFalse.length > 0) {
  71. this.addMarkersAndZoom(errorStateFalse, "4");
  72. }
  73. if (errorStateTrue.length > 0) {
  74. this.addMarkersAndZoom(errorStateTrue, "6");
  75. }
  76. }
  77. });
  78. }
  79. });
  80. },
  81. parseCoordinates(input) {
  82. if (input && typeof input === "string") {
  83. return input.split(",").map(Number);
  84. }
  85. return [];
  86. },
  87. addMarkersAndZoom(data, type) {
  88. const dataMapList = data;
  89. dataMapList.forEach((element) => {
  90. if (
  91. this.parseCoordinates(element.longitudeAndLatitudeString).length > 0
  92. ) {
  93. this.$refs.map.addMarker({
  94. point: this.parseCoordinates(element.longitudeAndLatitudeString),
  95. val: type,
  96. ...element,
  97. });
  98. // this.$refs.map.moveAndZoom({
  99. // point: this.parseCoordinates(element.longitudeAndLatitudeString),
  100. // zoom: 15,
  101. // });
  102. return;
  103. }
  104. this.$refs.map.clearMarkers();
  105. });
  106. // const points = [
  107. // { point: [120.2, 30.35], val: "4" },
  108. // { point: [120.21, 30.35], val: "5" },
  109. // ];
  110. // // Add markers to the map
  111. // points.forEach((point) => {
  112. // this.$refs.map.addMarker(point);
  113. // });
  114. // // Zoom to a specific point
  115. const zoomPoint = {
  116. point: this.parseCoordinates(
  117. this.windEngineGroupByFieldCodeDetail.windEngineGroupVoList[0]
  118. .longitudeAndLatitudeString
  119. ),
  120. zoom: 15,
  121. };
  122. this.$refs.map.moveAndZoom(zoomPoint);
  123. },
  124. },
  125. };
  126. </script>
  127. <style lang="scss" scoped>
  128. .map-ditu {
  129. height: 93vh;
  130. position: relative;
  131. }
  132. </style>