editMap.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <div class="edit-map">
  3. <custom-header name="创建农场"></custom-header>
  4. <div class="edit-map-content">
  5. <div class="edit-map-tip">操作提示:拖动圆点,即可调整地块边界</div>
  6. <div class="map-container" ref="mapContainer"></div>
  7. <div class="edit-map-footer">
  8. <div class="footer-back" @click="goBack">
  9. <img class="back-icon" src="@/assets/img/home/go-back.png" alt="" />
  10. </div>
  11. <div class="footer-address-box">
  12. <div class="footer-address">
  13. <div class="address-title">{{ pointName }}</div>
  14. <div class="address-detail">{{ pointAddress }}</div>
  15. </div>
  16. <div class="address-btn" @click="goBack">修改地址</div>
  17. </div>
  18. <div class="edit-map-footer-btn">
  19. <div class="btn-cancel" @click="goBack">取消</div>
  20. <div class="btn-confirm" @click="confirm">确认</div>
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. </template>
  26. <script setup>
  27. import customHeader from "@/components/customHeader.vue";
  28. import { ref, onMounted, onActivated } from "vue";
  29. import EditMap from "./map/editMap.js";
  30. import { useRouter, useRoute } from "vue-router";
  31. import { convertPointToArray } from "@/utils/index";
  32. import { useStore } from "vuex";
  33. const router = useRouter();
  34. const route = useRoute();
  35. const store = useStore();
  36. const mapContainer = ref(null);
  37. const editMap = new EditMap();
  38. const mapData = {
  39. farmCode: "LBY",
  40. farmId: "766",
  41. id: 2,
  42. isGenerateReport: 1,
  43. name: "分区2",
  44. pointCount: 131,
  45. pointWkt: "POINT (113.6142086995688 23.585836479509055)",
  46. regionCode: "LBY-MR-2",
  47. wkt: "MULTIPOLYGON (((113.61348988377155 23.58617369800422, 113.61395837633405 23.58622555407246, 113.61414076654707 23.58622555407246, 113.61436964832843 23.5862774101407, 113.61478628474084 23.586468741036786, 113.61491681896747 23.58652417337007, 113.61512424307672 23.586449071517652, 113.61491503077356 23.585742756367924, 113.61479880177082 23.585596129050916, 113.61473800497858 23.585451289764112, 113.61438931780664 23.585286780835393, 113.61410858003889 23.585299297865365, 113.61385645239149 23.585249229909184, 113.61378135053907 23.585288569029306, 113.61357571446003 23.585283204611276, 113.61347200232355 23.585342213209604, 113.61338080721704 23.585506721974614, 113.61335934954492 23.585665866485304, 113.61342193444922 23.58616296916816, 113.61348988377155 23.58617369800422)))",
  48. };
  49. const pointAddress = ref(null)
  50. const pointName = ref(null)
  51. onMounted(() => {
  52. pointAddress.value = route.query.pointAddress
  53. pointName.value = route.query.pointName
  54. const point = route.query.mapCenter || "POINT (113.6142086995688 23.585836479509055)"
  55. editMap.initMap(point, mapContainer.value);
  56. // editMap.setAreaGeometry([{ featureWkt: mapData.wkt }]);
  57. });
  58. onActivated(() => {
  59. pointAddress.value = route.query.pointAddress
  60. pointName.value = route.query.pointName
  61. const point = route.query.mapCenter || "POINT (113.6142086995688 23.585836479509055)"
  62. editMap.setMapPosition(convertPointToArray(point))
  63. })
  64. const goBack = () => {
  65. editMap.clearLayer()
  66. router.back();
  67. };
  68. const confirm = () => {
  69. // getAreaGeometry
  70. const polygonData = editMap.getAreaGeometry()
  71. store.commit("home/SET_FARM_POLYGON", polygonData);
  72. router.back();
  73. };
  74. </script>
  75. <style lang="scss" scoped>
  76. .edit-map {
  77. width: 100%;
  78. height: 100vh;
  79. overflow: hidden;
  80. .edit-map-content {
  81. width: 100%;
  82. height: 100%;
  83. position: relative;
  84. .edit-map-tip {
  85. position: absolute;
  86. top: 23px;
  87. left: calc(50% - 256px / 2);
  88. z-index: 1;
  89. font-size: 12px;
  90. color: #fff;
  91. padding: 9px 20px;
  92. background: rgba(0, 0, 0, 0.5);
  93. border-radius: 20px;
  94. }
  95. .map-container {
  96. width: 100%;
  97. height: 100%;
  98. }
  99. .edit-map-footer {
  100. position: absolute;
  101. bottom: 80px;
  102. left: 12px;
  103. width: calc(100% - 24px);
  104. display: flex;
  105. flex-direction: column;
  106. align-items: flex-end;
  107. .footer-back {
  108. padding: 6px 7px 9px;
  109. background: #fff;
  110. border-radius: 8px;
  111. .back-icon {
  112. width: 20px;
  113. height: 18px;
  114. }
  115. }
  116. .footer-address-box {
  117. width: 100%;
  118. box-sizing: border-box;
  119. margin: 19px 0 14px 0;
  120. display: flex;
  121. justify-content: space-between;
  122. align-items: center;
  123. background: #fff;
  124. border-radius: 14px;
  125. padding: 14px 12px;
  126. .footer-address {
  127. font-size: 12px;
  128. color: rgba(0, 0, 0, 0.6);
  129. .address-title {
  130. font-weight: 500;
  131. font-size: 16px;
  132. color: #000;
  133. }
  134. }
  135. .address-btn {
  136. color: #2199f8;
  137. border: 1px solid #2199f8;
  138. border-radius: 25px;
  139. padding: 6px 10px;
  140. flex: none;
  141. }
  142. }
  143. .edit-map-footer-btn {
  144. display: flex;
  145. justify-content: center;
  146. align-items: center;
  147. width: 100%;
  148. div {
  149. width: 92px;
  150. text-align: center;
  151. color: #666666;
  152. font-size: 16px;
  153. padding: 8px 0;
  154. border-radius: 25px;
  155. background: #fff;
  156. }
  157. .btn-confirm {
  158. background: #000;
  159. background-image: linear-gradient(180deg, #76c3ff 0%, #2199f8 100%);
  160. margin-left: 16px;
  161. color: #fff;
  162. }
  163. }
  164. }
  165. }
  166. }
  167. </style>