From 1a624e005e65046b1bb1ff3e10f060fb32984b24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=BE=E8=82=83?= <15833576927@163.com> Date: Fri, 17 May 2024 13:51:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=B0=E5=9B=BE=E7=BD=91=E6=A0=BC=E7=BA=BF?= =?UTF-8?q?=EF=BC=8C=E6=96=B0=E5=A2=9E=E5=9C=B0=E5=9D=97=EF=BC=8C=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E6=A0=87=E7=AD=BE=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/utils/ruoyi.js | 61 +++++++ src/views/system/base/baseRightControl.vue | 32 ++-- src/views/system/base/massifMap.vue | 184 +++++++++++++++++++-- 4 files changed, 249 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index a47bb3f..594c613 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "dependencies": { "@element-plus/icons-vue": "2.3.1", "@icon-park/vue-next": "^1.4.2", + "@turf/turf": "^6.5.0", "@vuemap/vue-amap": "^2.1.1", "@vueup/vue-quill": "1.2.0", "@vueuse/core": "10.9.0", diff --git a/src/utils/ruoyi.js b/src/utils/ruoyi.js index ca00711..2e84caf 100644 --- a/src/utils/ruoyi.js +++ b/src/utils/ruoyi.js @@ -321,4 +321,65 @@ export function areaConversion(value, from = '平方米', arrive = '亩') { //执行换算,注意fRate的取值,得到上一次的单位节点,再取当前单位的换算率 var rst = (v * fRate[from][arrive]).toFixed(4);//保留4位小数 return parseFloat(rst) +} + +/** + * 计算中心点 + * @param lnglatarr + * @returns {AMap.LngLat} + */ +export function calculateCenter(lnglatarr) { + var total = lnglatarr.length; + var X = 0, + Y = 0, + Z = 0; + lnglatarr.map((item) => { + var lng = (item[0] * Math.PI) / 180; + var lat = (item[1] * Math.PI) / 180; + var x, y, z; + x = Math.cos(lat) * Math.cos(lng); + y = Math.cos(lat) * Math.sin(lng); + z = Math.sin(lat); + X += x; + Y += y; + Z += z; + }); + X = X / total; + Y = Y / total; + Z = Z / total; + var Lng = Math.atan2(Y, X); + var Hyp = Math.sqrt(X * X + Y * Y); + var Lat = Math.atan2(Z, Hyp); + return new AMap.LngLat((Lng * 180) / Math.PI, (Lat * 180) / Math.PI); +} + +/** + * 计算多边形边界并返回网格线路径 + * @param polygon 多边形数据 + * @param grid 网格大小 默认10m + * @returns {*[]} + */ +export function drawGridLines(polygon, grid = 10) { + let gridSize = 0.00001 * grid + let minLng = Infinity; + let maxLng = -Infinity; + let minLat = Infinity; + let maxLat = -Infinity; + // 计算边界 + polygon.forEach(point => { + if (point[0] < minLng) minLng = point[0]; + if (point[0] > maxLng) maxLng = point[0]; + if (point[1] < minLat) minLat = point[1]; + if (point[1] > maxLat) maxLat = point[1]; + }); + // 通过边界和网格大小计算网格线 + var gridLines = []; + for (var lat = minLat; lat <= maxLat; lat += gridSize) { // 约等于10m + for (var lng = minLng; lng <= maxLng; lng += gridSize) { // 同上 + // 创建水平和垂直两条线 + gridLines.push([[lng, lat], [lng + gridSize, lat]]); + gridLines.push([[lng, lat], [lng, lat + gridSize]]); + } + } + return gridLines } \ No newline at end of file diff --git a/src/views/system/base/baseRightControl.vue b/src/views/system/base/baseRightControl.vue index e66bbcc..e37148d 100644 --- a/src/views/system/base/baseRightControl.vue +++ b/src/views/system/base/baseRightControl.vue @@ -10,21 +10,23 @@ const router = useRouter() const toBaseTable = () => { router.push('/system/base/baseTable') } -const control = reactive({ - // 地图类型 - dataType:1, - // 显示地块标签 - massifLabel:false, - // 显示网格地块 - massifGrid:false, - // 显示垄 - showRidge:false, - // 显示垄标签 - ridgeLabel:false, - // 显示植株 - showPlant:false, - // 显示植株标签 - plantLabel:false, +const control = defineModel({ + default: { + // 地图类型 + dataType: 1, + // 显示地块标签 + massifLabel: false, + // 显示网格地块 + massifGrid: false, + // 显示垄 + showRidge: false, + // 显示垄标签 + ridgeLabel: false, + // 显示植株 + showPlant: false, + // 显示植株标签 + plantLabel: false, + } }) diff --git a/src/views/system/base/massifMap.vue b/src/views/system/base/massifMap.vue index 1763fbb..3d52481 100644 --- a/src/views/system/base/massifMap.vue +++ b/src/views/system/base/massifMap.vue @@ -2,23 +2,100 @@