From 822fc341a4a0ed406de4ef94f9fa405b0bcdb9ec Mon Sep 17 00:00:00 2001 From: ailanyin Date: Thu, 9 Mar 2023 11:48:10 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=BA=E6=97=B6=E9=92=88=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 + src/utils/geoUtils.js | 15 +++++ src/views/basic/fence/add.vue | 118 ++++++++++++++++++---------------- 3 files changed, 79 insertions(+), 56 deletions(-) create mode 100644 src/utils/geoUtils.js diff --git a/package.json b/package.json index 4da4fd4..7136068 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,8 @@ "@amap/amap-jsapi-loader": "^1.0.1", "@element-plus/icons-vue": "2.0.10", "@highlightjs/vue-plugin": "^2.1.0", + "@turf/center": "^6.5.0", + "@turf/helpers": "^6.5.0", "@vueuse/core": "9.5.0", "@wangeditor/editor": "^5.1.23", "@wangeditor/editor-for-vue": "^5.1.12", diff --git a/src/utils/geoUtils.js b/src/utils/geoUtils.js new file mode 100644 index 0000000..9317447 --- /dev/null +++ b/src/utils/geoUtils.js @@ -0,0 +1,15 @@ +import {points} from "@turf/helpers"; +import center from "@turf/center"; + +// [[-97.522259, 35.4691], +// [-97.502754, 35.463455], +// [-97.508269, 35.463245]] +export const pointSortClockwise = (coordinates) => { + const centerCoor = center(points(coordinates)).geometry.coordinates; + return coordinates.sort((a, b) => { + // 转换为以 centerCoor 为原点的坐标 + const point_a = [a[0] - centerCoor[0], a[1] - centerCoor[1]] + const point_b = [b[0] - centerCoor[0], b[1] - centerCoor[1]] + return Math.atan2(...point_b.reverse()) - Math.atan2(...point_a.reverse()) + }) +} \ No newline at end of file diff --git a/src/views/basic/fence/add.vue b/src/views/basic/fence/add.vue index 2d50cb1..a0d5686 100644 --- a/src/views/basic/fence/add.vue +++ b/src/views/basic/fence/add.vue @@ -3,82 +3,85 @@
- + @@ -90,8 +93,8 @@