Map.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <template>
  2. <div ref="mapRef" class="bottom-map"></div>
  3. <div ref="info" class="area-info"></div>
  4. <div ref="imgInfo" class="img-info" @mouseleave="hideImg"></div>
  5. <el-dialog
  6. class="v-dialog dialog-preview"
  7. v-model="dialogVisibleShow"
  8. width="1024"
  9. :show-close="false"
  10. top="5vh"
  11. @close="handleCloese"
  12. >
  13. <template #header>
  14. <div class="dialog-header">
  15. <div>果树编号:{{ imgObj.treeCode }}</div>
  16. <div class="right">
  17. <div class="switch" @click="handleSwitch">
  18. <el-icon color="#00FFF0" size="15"><Switch /></el-icon>
  19. <span>切换{{ switchValue ? "原图" : "指标图" }}</span>
  20. </div>
  21. <el-icon
  22. @click="handleCloese"
  23. class="close-icon"
  24. color="#00FFF0"
  25. size="20px"
  26. ><CircleCloseFilled
  27. /></el-icon>
  28. </div>
  29. </div>
  30. </template>
  31. <div class="dialog-body">
  32. <img
  33. @click="handleZoom"
  34. class="zoom yse-events"
  35. src="@/assets/img/znxy/zoom_btn.png"
  36. alt=""
  37. />
  38. <DrawBox
  39. v-if="switchValue && imgObj.markText"
  40. width="1002"
  41. :height="imgHeight"
  42. :sourceData="imgObj.markText"
  43. ></DrawBox>
  44. <img
  45. class="image no-events"
  46. :src="imgObj.filename + '?x-oss-process=image/resize,w_2000'"
  47. alt=""
  48. fit="cover"
  49. ref="imageRef"
  50. />
  51. <!-- <img
  52. class="image no-events"
  53. :src="imgObj.resFilename + '?x-oss-process=image/resize,w_2000'"
  54. alt=""
  55. fit="cover"
  56. /> -->
  57. <div class="watermark-style">
  58. <div class="left">
  59. <div class="region">2区</div>
  60. <div class="date">{{ imgObj.uploadDate }}</div>
  61. <div class="whq">
  62. {{ imgObj.bigPeriodName }}<span v-show="imgObj.bigPeriodName&&imgObj.smallPeriodName">-</span>{{ imgObj.smallPeriodName }}
  63. </div>
  64. <div class="code">
  65. <div class="code-txt">生长正常</div>
  66. </div>
  67. <div class="weather">
  68. <div class="temperature">
  69. <img src="@/assets/img/sun_icon.png" alt="" />
  70. <div class="num">
  71. <div>26-32℃</div>
  72. </div>
  73. </div>
  74. <div class="temperature">
  75. <img src="@/assets/img/rain_icon.png" alt="" />
  76. <div class="num">
  77. <div>60% 0.34ml</div>
  78. </div>
  79. </div>
  80. </div>
  81. </div>
  82. <!-- <div class="right">
  83. <div class="block mr">病虫害</div>
  84. <div class="block">二梢杀虫</div>
  85. </div> -->
  86. </div>
  87. </div>
  88. <template #footer>
  89. <div class="dialog-footer">
  90. <Carousel
  91. :items="carouselImageList"
  92. @handleImage="handleImage"
  93. ></Carousel>
  94. </div>
  95. </template>
  96. </el-dialog>
  97. <PicturePreview
  98. v-if="zoomDisplay"
  99. :show="zoomShow"
  100. :switchValue="switchValue"
  101. :imageUrl="imgObj"
  102. ></PicturePreview>
  103. </template>
  104. <script setup>
  105. import { useStore } from "vuex";
  106. import { onMounted, onBeforeUnmount, ref, watch } from "vue";
  107. import { base_img_url2 } from "@/api/config.js";
  108. import ZnxyMap from "./znxy/ZnxyMap";
  109. import { WKT } from "ol/format";
  110. import Carousel from "@/components/carousel.vue";
  111. import DrawBox from "@/components/drawBox.vue";
  112. import { treeItem } from "./znxy/ZnxyMap.js";
  113. import { ElMessage } from "element-plus";
  114. import PicturePreview from "@/components/PicturePreview.vue";
  115. import PlotLayer from "./znxy/znxyLayer/plotLayer";
  116. const props = defineProps({
  117. tabValue:{
  118. type: Object,
  119. default: ()=>{},
  120. }
  121. });
  122. let resize = "?x-oss-process=image/resize,w_200";
  123. let emit = defineEmits(["setHideZnxy"]);
  124. let store = useStore();
  125. const mapRef = ref("mapRef");
  126. const info = ref(null);
  127. const imgInfo = ref(null);
  128. let curGardenId = ref(store.getters.userinfo.curGardenId);
  129. let curArea = ref({});
  130. let znxyMap = new ZnxyMap();
  131. let plotLayer = null;
  132. let curTree = null;
  133. let curDate = new Date();
  134. let curYear = curDate.getFullYear();
  135. let curMonth = curDate.getMonth() + 1;
  136. let curDay = curDate.getDate();
  137. // 在组件或全局监听器中监听自定义事件
  138. function handleStorageUpdate(e) {
  139. curGardenId.value = e.detail;
  140. initData();
  141. }
  142. // 在组件或全局监听器中监听自定义事件
  143. window.addEventListener("storageChanged", handleStorageUpdate);
  144. // 组件销毁前移除监听
  145. onBeforeUnmount(() => {
  146. window.removeEventListener("storageChanged", handleStorageUpdate);
  147. });
  148. const imageRef = ref(null)
  149. const imgHeight = ref('')
  150. const dialogVisibleShow = ref(false);
  151. const handleFeedback = () => {
  152. dialogVisibleShow.value = true;
  153. };
  154. // 缩放
  155. const zoomShow = ref(false);
  156. const zoomDisplay = ref(false);
  157. const handleZoom = () => {
  158. zoomDisplay.value = true
  159. zoomShow.value = !zoomShow.value;
  160. };
  161. const imgObj = ref({ filename: "", resFilename: "" });
  162. const handleImage = (v) => {
  163. imgObj.value = imageList.value.find((item) => item.id == v.id);
  164. curDate = new Date(imgObj.value.uploadDate);
  165. curYear = curDate.getFullYear();
  166. curMonth = curDate.getMonth() + 1;
  167. curDay = curDate.getDate();
  168. imgHeight.value = imageRef.value.offsetHeight
  169. console.log(imgHeight.value);
  170. };
  171. onMounted(() => {
  172. let location = store.getters.userinfo.location;
  173. znxyMap.initMap(location, mapRef.value);
  174. plotLayer = new PlotLayer(znxyMap.kmap);
  175. initGarden();
  176. initData();
  177. });
  178. watch(
  179. () => props.tabValue,
  180. (newValue, oldValue) => {
  181. if (newValue) {
  182. znxyMap.initTree(curGardenId.value,false);
  183. if(newValue.type===1){
  184. plotLayer.switchTreeLegend(curGardenId.value, newValue);
  185. }else if(newValue.type===2){
  186. plotLayer.addGargendImg(curGardenId.value, { key: newValue.key });
  187. }else{
  188. znxyMap.initTree(curGardenId.value,true);
  189. plotLayer.switchTreeLegend(curGardenId.value, newValue);
  190. }
  191. }
  192. }
  193. );
  194. const initGarden = () => {
  195. znxyMap.initGarden();
  196. znxyMap.addGardenClick(async function (f) {
  197. let user = JSON.parse(sessionStorage.getItem("userinfo"));
  198. // 更新果园信息
  199. const res = await VE_API.organ.updateGarden({
  200. gardenId: f.get("organId"),
  201. userId: user.userId,
  202. });
  203. if (res.code === 0) {
  204. const resData = res.data;
  205. user.curGardenId = resData.curGardenId;
  206. user.curGardenName = resData.curGardenName;
  207. user.location = resData.location;
  208. store.commit("app/SET_USER_INFO", JSON.stringify(user));
  209. // 添加自定义事件
  210. window.dispatchEvent(
  211. new CustomEvent("storageChanged", { detail: user.curGardenId })
  212. );
  213. emit("setHideZnxy", true);
  214. }
  215. });
  216. };
  217. const initData = () => {
  218. znxyMap.initArea(curGardenId.value);
  219. znxyMap.initSubArea(curGardenId.value);
  220. znxyMap.initTree(curGardenId.value,true);
  221. znxyMap.addHoverTooltips(info.value, imgInfo.value);
  222. znxyMap.addMapClick();
  223. };
  224. defineExpose({
  225. znxyMap,
  226. });
  227. // 隐藏图片
  228. const hideImg = () => {
  229. imgInfo.value.style.visibility = "hidden";
  230. };
  231. const switchValue = ref(true);
  232. const handleSwitch = () => {
  233. switchValue.value = !switchValue.value;
  234. };
  235. const handleCloese = () => {
  236. treeItem.treeId = 0;
  237. dialogVisibleShow.value = false;
  238. };
  239. const imageList = ref([]);
  240. const carouselImageList = ref([]);
  241. watch(
  242. () => treeItem.treeId,
  243. (newValue, oldValue) => {
  244. if (newValue > 0) {
  245. imageList.value = [];
  246. dialogVisibleShow.value = true;
  247. VE_API.tree_img
  248. .imagesByTreeId({ treeId: newValue, limit: 100 })
  249. .then(({ data }) => {
  250. let arr = new Array();
  251. for (let item of data) {
  252. item.filename = base_img_url2 + item.filename;
  253. arr.push({
  254. id: item.id,
  255. src: item.filename + resize,
  256. date: item.uploadDate,
  257. });
  258. }
  259. if (data.length > 0) {
  260. if (!data[0].resFilename) {
  261. switchValue.value = false;
  262. } else {
  263. switchValue.value = true;
  264. }
  265. }
  266. carouselImageList.value = arr;
  267. imageList.value = data;
  268. if (data.length > 0) {
  269. handleImage(data[0]);
  270. } else {
  271. ElMessage.warning("暂无数据");
  272. }
  273. });
  274. }
  275. }
  276. );
  277. </script>
  278. <style scoped lang="scss">
  279. // 弹窗样式
  280. .v-dialog {
  281. .dialog-header {
  282. .right {
  283. display: flex;
  284. align-items: center;
  285. .switch {
  286. cursor: pointer;
  287. background: url("@/assets/img/tabs_btn3.png") no-repeat center center /
  288. 100% 100%;
  289. width: 120px;
  290. text-align: center;
  291. padding: 5px 0;
  292. margin-right: 24px;
  293. }
  294. }
  295. }
  296. .dialog-body {
  297. padding: 10px;
  298. position: relative;
  299. height: 98%;
  300. box-sizing: border-box;
  301. .zoom {
  302. position: absolute;
  303. top: 15px;
  304. right: 15px;
  305. z-index: 9;
  306. cursor: pointer;
  307. }
  308. .image {
  309. width: 100%;
  310. height: 100%;
  311. }
  312. .watermark-style {
  313. width: 98%;
  314. bottom: 10px;
  315. .region {
  316. width: 38px;
  317. height: 38px;
  318. font-size: 12px;
  319. line-height: 38px;
  320. margin-right: 10px;
  321. }
  322. .date {
  323. font-size: 23px;
  324. }
  325. .whq{
  326. font-size: 18px;
  327. }
  328. .code {
  329. .code-txt {
  330. font-size: 18px;
  331. margin-left: 25px;
  332. &::before {
  333. content: "";
  334. top: 8px;
  335. }
  336. }
  337. }
  338. .weather {
  339. .temperature {
  340. font-size: 17px;
  341. img {
  342. width: 22px;
  343. height: 22px;
  344. }
  345. }
  346. }
  347. .right {
  348. font-size: 14px;
  349. }
  350. }
  351. }
  352. .dialog-footer {
  353. height: auto;
  354. display: flex;
  355. align-items: center;
  356. padding: 8px 10px 4px 10px;
  357. background: rgba(0, 246, 255, 0.14);
  358. }
  359. }
  360. .bottom-map {
  361. position: absolute;
  362. width: 100%;
  363. height: 100%;
  364. z-index: 0;
  365. background-color: #5f5d5d;
  366. overflow: hidden;
  367. }
  368. .area-info {
  369. position: absolute;
  370. display: inline-block;
  371. height: auto;
  372. width: auto;
  373. z-index: 100;
  374. color: #fff;
  375. border-radius: 4px;
  376. padding: 6px 8px;
  377. left: 50%;
  378. transform: translateX(3%);
  379. visibility: hidden;
  380. pointer-events: none;
  381. background: rgba(51, 11, 3, 0.7);
  382. border: 1px solid #f55a5a;
  383. }
  384. .img-info {
  385. position: absolute;
  386. display: inline-block;
  387. z-index: 3;
  388. color: #fff;
  389. visibility: hidden;
  390. pointer-events: none;
  391. background: #ffffff;
  392. border: 3px solid rgba(255, 157, 0, 0.75);
  393. top: 50%;
  394. left: 50%;
  395. transform: translate(-50%, -50%);
  396. width: fit-content;
  397. height: calc(30vh - 6px);
  398. ::v-deep {
  399. img {
  400. width: fit-content;
  401. height: 100%;
  402. object-fit: scale-down;
  403. }
  404. }
  405. }
  406. </style>
  407. <style lang="scss">
  408. .dialog-preview {
  409. height: 89%;
  410. box-sizing: border-box;
  411. .el-dialog__body {
  412. height: 79.5%;
  413. box-sizing: border-box;
  414. }
  415. .el-dialog__footer{
  416. height: 13.5%;
  417. display: flex;
  418. align-items: center;
  419. }
  420. }
  421. </style>