wangjuncheng
2025-04-16 bd13b522f95d4f9429eb0e8bc7df2e1ce3d58554
change
已添加1个文件
已修改3个文件
57 ■■■■ 文件已修改
src/main.js 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/wktUtils.js 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/Home.vue 27 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/left/KGSimOption/HistorySimulation.vue 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
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")
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})))`;
}
src/views/Home.vue
@@ -8,14 +8,10 @@
  <!-- <Left v-if="leftShow" />
        <Right v-if="rightShow" /> -->
  <Tools
    :style="
      rightRiverShow || showDangerAssess
  <Tools :style="rightRiverShow || showDangerAssess
        ? { right: '400px' }
        : { right: '12px' }
    "
    class="tools"
  />
    " 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";
@@ -62,6 +58,7 @@
import { showDeviceDetail } from "@/store";
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();
src/views/left/KGSimOption/HistorySimulation.vue
@@ -76,7 +76,7 @@
// const getRainData = () => {
//   getRainfallData()
//     .then((a) => {
//       console.log(a, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
//       console.log(a, '宏图获取雨量数据');
//     })
// };