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 @@