From bd13b522f95d4f9429eb0e8bc7df2e1ce3d58554 Mon Sep 17 00:00:00 2001 From: wangjuncheng <1> Date: 星期三, 16 四月 2025 16:41:55 +0800 Subject: [PATCH] change --- src/main.js | 2 + src/views/Home.vue | 35 ++++++++++++----- src/utils/wktUtils.js | 26 +++++++++++++ src/views/left/KGSimOption/HistorySimulation.vue | 2 4 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/main.js b/src/main.js index 6fa2881..7232194 100644 --- a/src/main.js +++ b/src/main.js @@ -8,10 +8,12 @@ import dayjs from "dayjs" import '@/assets/css/global.css' import { createPinia } from 'pinia' // 瀵煎叆 Pinia +import { convertToWKT } from '@/utils/wktUtils'; // 寮曞叆宸ュ叿鍑芥暟 const pinia = createPinia() import "element-plus/theme-chalk/index.css" const app = createApp(App) +app.config.globalProperties.$convertToWKT = convertToWKT; app.config.globalProperties.$dayjs = dayjs app.use(ElementUI, { zhLocale }).use(router).use(pinia).mount("#app") diff --git a/src/utils/wktUtils.js b/src/utils/wktUtils.js new file mode 100644 index 0000000..e1c19b7 --- /dev/null +++ b/src/utils/wktUtils.js @@ -0,0 +1,26 @@ +/** + * 灏嗘櫘閫氱粡绾害鏁扮粍杞崲涓烘爣鍑嗙殑 MULTIPOLYGON WKT 鏍煎紡 + * @param {Array<Array<number>>} coordinates - 缁忕含搴︽暟缁勶紝姣忎釜鍏冪礌鏄竴涓� [缁忓害, 绾害] 鐨勭偣 + * @returns {string} 鏍囧噯鍖栫殑 WKT 鏍煎紡瀛楃涓� + */ +export function convertToWKT(coordinates) { + // 妫�鏌ヨ緭鍏ユ槸鍚︿负闈炵┖鏁扮粍 + if (!Array.isArray(coordinates) || coordinates.length === 0) { + throw new Error("Invalid input: 'coordinates' must be a non-empty array of [longitude, latitude] points."); + } + + // 妫�鏌ユ瘡涓偣鏄惁鏄湁鏁堢殑 [缁忓害, 绾害] 鏁扮粍 + for (const point of coordinates) { + if (!Array.isArray(point) || point.length !== 2 || typeof point[0] !== "number" || typeof point[1] !== "number") { + throw new Error("Invalid input: Each coordinate must be an array of two numbers [longitude, latitude]."); + } + } + + // 灏嗙粡绾害鏁扮粍杞崲涓� WKT 鏍煎紡鐨勫潗鏍囧瓧绗︿覆 + const wktCoordinates = coordinates + .map(([longitude, latitude]) => `${longitude} ${latitude}`) + .join(","); + + // 鏋勫缓鏍囧噯鐨� MULTIPOLYGON WKT 鏍煎紡 + return `MULTIPOLYGON(((${wktCoordinates})))`; +} \ No newline at end of file diff --git a/src/views/Home.vue b/src/views/Home.vue index aae5a90..95b8455 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -8,14 +8,10 @@ <!-- <Left v-if="leftShow" /> <Right v-if="rightShow" /> --> - <Tools - :style=" - rightRiverShow || showDangerAssess - ? { right: '400px' } - : { right: '12px' } - " - class="tools" - /> + <Tools :style="rightRiverShow || showDangerAssess + ? { right: '400px' } + : { right: '12px' } + " class="tools" /> <!-- <Message v-if="messageShow" class="messageTool" /> --> <Announcement v-show="$route.fullPath != '/'" class="announcementTool" /> <!-- <Location v-if="locationShow" class="locationTool" /> --> @@ -31,7 +27,7 @@ </template> <script setup> -import { computed, onMounted } from "vue"; +import { computed, onMounted, ref, getCurrentInstance } from "vue"; import { useRoute } from "vue-router"; import { useSimStore } from "@/store/simulation"; import { storeToRefs } from "pinia"; @@ -60,8 +56,9 @@ import ResultAssess from "@/components/monifangzhen/ResultAssess.vue"; // import DangerAssess from "@/components/monifangzhen/DangerAssess.vue"; import { showDeviceDetail } from "@/store"; -import { setupTokenRefresh } from "@/api/hpApi.js" -import { getData } from "@/api/trApi.js" +import { setupTokenRefresh } from "@/api/hpApi.js" +import { getData } from "@/api/trApi.js" +import { convertToWKT } from '@/utils/wktUtils'; const route = useRoute(); const simStore = useSimStore(); @@ -78,12 +75,28 @@ showDangerAssess, } = storeToRefs(simStore); const { init, startYHGL, startZHJC, startMNFZ, startMNPG } = simStore; +// 妯℃嫙鐨勭粡绾害鏁扮粍 +const coordinates = [ + [120.123456, 30.654321], + [120.234567, 30.765432], + [120.345678, 30.876543], + [120.123456, 30.654321] +]; + // 璁$畻灞炴�� const showDetail = computed(() => showDeviceDetail.value); onMounted(() => { setupTokenRefresh()// 鑾峰彇瀹忓浘token getData() //娴嬭瘯tr鍚庣 + try { + const wktResult = convertToWKT(coordinates); + console.log(wktResult); + // 杈撳嚭: MULTIPOLYGON(((120.123456 30.654321,120.234567 30.765432,120.345678 30.876543,120.123456 30.654321))) + } catch (error) { + console.error(error.message); + + } }); // 鍒濆鍖� init(); diff --git a/src/views/left/KGSimOption/HistorySimulation.vue b/src/views/left/KGSimOption/HistorySimulation.vue index 213a885..3aa57d0 100644 --- a/src/views/left/KGSimOption/HistorySimulation.vue +++ b/src/views/left/KGSimOption/HistorySimulation.vue @@ -76,7 +76,7 @@ // const getRainData = () => { // getRainfallData() // .then((a) => { -// console.log(a, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'); +// console.log(a, '瀹忓浘鑾峰彇闆ㄩ噺鏁版嵁'); // }) // }; -- Gitblit v1.9.3