From d46ebfb71da0148dcc2724024cf7b053d784f299 Mon Sep 17 00:00:00 2001
From: 少年 <1392120328@qq.com>
Date: 星期二, 05 三月 2024 18:35:10 +0800
Subject: [PATCH] youhua

---
 src/utils/tool.js |   78 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/src/utils/tool.js b/src/utils/tool.js
index 7cea36d..bb7973b 100644
--- a/src/utils/tool.js
+++ b/src/utils/tool.js
@@ -1,6 +1,7 @@
 
 import _GLOBAL from '@/assets/GLOBAL2'
 import gcj02Mecator from '@/utils/transform'
+import { ceil } from 'lodash';
 //娓呴櫎
 export function clearAll() {
     if (_GLOBAL.ImageLayer) {
@@ -128,18 +129,91 @@
 
 
 //鑾峰彇褰撳墠瀹氫綅
+var _rotate = 90;
+var _marker = null;
+var points = [];
+
+export function randomPoint() {
+    let t = 116.505348;
+    let e = 39.795592;
+    t += .01 * Math.random();
+    e += .01 * Math.random();
+    points.push([t, e]);
+}
 
 
 export function getCurrentPosition() {
+    // setInterval(() => {
+    //     randomPoint();
+    // }, 1000)
+
+    // console.log(points, '鐐逛綅娴嬭瘯')
+    // _marker = createGPSMarker(points, _rotate);
+    // window.mapapi.addLayer(_marker)
+    
     if (navigator.geolocation) {
-        navigator.geolocation.getCurrentPosition((res) => {
-            console.log(res);//杩欓噷浼氳繑鍥炵粡绾害锛岀劧鍚庤繕瑕侀�氳繃缁忕含搴﹁浆鎹㈠湴鍖哄悕绉�
+        navigator.geolocation.watchPosition((res) => {
+            let lat = res.coords.latitude;
+            let lon = res.coords.longitude;
+            _marker = createGPSMarker([lon, lat], _rotate);
+            window.mapapi.addLayer(_marker)
         });
     }
 
 }
 
 
+export function createGPSMarker(position, rotate) {
+    const GPSMarkerLayer = new ol.layer.Vector({
+        id: 'LocationPoint',
+        name: '瀹氫綅鐐�',
+        source: new ol.source.Vector({
+            features: [new ol.Feature({
+                geometry: new ol.geom.Point(position),
+            })]
+        }),
+        style: new ol.style.Style({
+            image: new ol.style.Icon({
+                src: require('@/assets/img/collection/mark.png'),
+                anchorOrigin: "top-left",
+                anchorXUnits: "fraction",
+                anchorYUnits: "fraction",
+                offsetOrigin: "bottom-right",
+                scale: 0.6,
+                rotation: rotate,
+                opacity: 1,
+            })
+        }),
+        zIndex: 9999,
+    });
+
+    return GPSMarkerLayer
+};
+
+
+export function listenDirection() {
+    window.addEventListener('deviceorientation', function (e) {
+        if (_marker) {
+            _rotate = e.alpha * (Math.PI / -180);
+            _marker.setStyle(
+                new ol.style.Style({
+                    image: new ol.style.Icon({
+                        anchor: [0.5, 0.5],
+                        anchorOrigin: 'top-left',
+                        src: require('@/assets/img/collection/mark.png'),
+                        rotation: _rotate,
+                        anchorXUnits: "fraction",
+                        anchorYUnits: "fraction",
+                        scale: 0.5,
+                        opacity: 1
+                    })
+                })
+            )
+        }
+    }, false);
+};
+
+
 
 
 

--
Gitblit v1.9.3