From 799a69b8b0a03e44ed124e63509b2650599057b9 Mon Sep 17 00:00:00 2001
From: shuishen <1109946754@qq.com>
Date: Thu, 07 Dec 2023 18:34:38 +0800
Subject: [PATCH] 实时定位,位置处理; 不同校区,显示位置做处理; 切换校区显示内容做处理;
---
src/store/modules/mobilePosition.js | 142 +++++++++++++++++++++++++++++++++--------------
1 files changed, 99 insertions(+), 43 deletions(-)
diff --git a/src/store/modules/mobilePosition.js b/src/store/modules/mobilePosition.js
index c13d0cd..acd5552 100644
--- a/src/store/modules/mobilePosition.js
+++ b/src/store/modules/mobilePosition.js
@@ -2,60 +2,116 @@
* @Author: shuishen 1109946754@qq.com
* @Date: 2022-09-09 17:54:08
* @LastEditors: shuishen 1109946754@qq.com
- * @LastEditTime: 2022-09-14 16:05:41
- * @FilePath: \smart-campus\src\store\modules\mobilePosition.js
+ * @LastEditTime: 2023-12-07 18:11:59
+ * @FilePath: \sd-jg-school-web-ksd\src\store\modules\mobilePosition.js
* @Description:
*
* Copyright (c) 2022 by shuishen 1109946754@qq.com, All Rights Reserved.
*/
+let extent = [
+ {
+ key: 1,
+ xMin: 112.51303616638316,
+ yMin: -0.103420786429659,
+ xMax: 112.67880038471827,
+ yMax: 0.000004508906477476281,
+
+ x: (x, y) => {
+ return -250.6503 + 2.0389 * x + 4.4338 * y;
+ },
+
+ x: (x, y) => {
+ return 228.1454 - 2.321 * x + 1.4165 * y;
+ },
+ },
+
+ {
+ key: 2,
+ xMin: 112.51302551881798,
+ yMin: -0.16235359398493399,
+ xMax: 112.72742295590702,
+ yMax: 0.000004509195932360471,
+
+ x: (x, y) => {
+ return -789.1274 + 6.0609 * x + 6.9479 * y;
+ },
+
+ x: (x, y) => {
+ return 298.9294 - 3.5295 * x + 3.8211 * y;
+ },
+ },
+];
+
+import { GCJ02ToWGS84 } from "@/utils/CoordTransform";
+
const mobilePosition = {
- state: {
- getSPosition: null
- },
- mutations: {
- GET_NOWPOSITION (state, val) {
- var outData =
- val ||
- function (res) {
- console.log(res)
- }
+ state: {
+ getSPosition: null,
+ currentCampus: 1,
+ },
+ mutations: {
+ GET_NOWPOSITION(state, val) {
+ var outData =
+ val ||
+ function (res) {
+ console.log(res);
+ };
- console.log(state, 222)
+ let cur = extent.find((item) => item.key == state.currentCampus);
- global.Geolocation.getLocation(function success (result) {
- const position = global.DC.CoordTransform.GCJ02ToWGS84(result.lng, result.lat)
+ global.Geolocation.getLocation(
+ function success(result) {
+ let positionWgs = GCJ02ToWGS84(result.lng, result.lat);
- if (position[0] > 115.78815057 && position[0] < 115.80346610 && position[1] > 28.63771847 && position[1] < 28.64981682) {
- outData([position[0], position[1]])
- } else {
- Message({
- message: '您当前位置超出学校范围',
- type: 'warning',
- duration: 2000
- })
+ let position = {
+ lng: cur.x(positionWgs[0], positionWgs[1]),
+ lat: cur.y(positionWgs[0], positionWgs[1]),
+ };
- outData(['失败'])
- }
- }, function error (result) {
- if (result.code == 1) {
- confirm('您拒绝了定位功能')
- } else if (result.code == 3 || result.code == 5) {
- confirm('请求超时')
- }
- }, {
- timeout: 8000, // 默认值为10s;
- failTipFlag: true
- })
+ if (
+ position.lng > cur.xMin &&
+ position.lng < cur.xMax &&
+ position.lat > cur.yMin &&
+ position.lat < cur.yMax
+ ) {
+ outData([position.lng, position.lat]);
+ } else {
+ Message({
+ message: "您当前位置超出学校范围",
+ type: "warning",
+ duration: 2000,
+ });
+
+ outData(["失败"]);
+ }
},
- CLOSE_NOWPOSITION (state) {
- // if (state.getSPosition && navigator.geolocation) {
- // navigator.geolocation.clearWatch(state.getSPosition);
- // state.getSPosition = null;
- // }
+ function error(result) {
+ if (result.code == 1) {
+ confirm("您拒绝了定位功能");
+ } else if (result.code == 3 || result.code == 5) {
+ confirm("请求超时");
+ }
+ },
+ {
+ timeout: 8000, // 默认值为10s;
+ failTipFlag: true,
}
+ );
},
- actions: {}
-}
-export default mobilePosition
+ CLOSE_NOWPOSITION(state) {
+ // if (state.getSPosition && navigator.geolocation) {
+ // navigator.geolocation.clearWatch(state.getSPosition);
+ // state.getSPosition = null;
+ // }
+ },
+
+ SET_CURRENTCAMPUS(state, val) {
+ state.currentCampus = val;
+ },
+ },
+ actions: {},
+};
+
+export default mobilePosition;
--
Gitblit v1.9.3