From a18adf9f3b30a5ff51c163059e4af9ffcd2af536 Mon Sep 17 00:00:00 2001 From: 少年 <1392120328@qq.com> Date: 星期三, 06 三月 2024 17:13:26 +0800 Subject: [PATCH] youhua --- src/utils/tool.js | 39 ++++++++++++--------------------------- 1 files changed, 12 insertions(+), 27 deletions(-) diff --git a/src/utils/tool.js b/src/utils/tool.js index 7ffd440..d70071b 100644 --- a/src/utils/tool.js +++ b/src/utils/tool.js @@ -131,41 +131,25 @@ } -//鑾峰彇褰撳墠瀹氫綅 -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.watchPosition((res) => { let lat = res.coords.latitude; let lon = res.coords.longitude; - _marker = createGPSMarker([lon, lat], _rotate); - window.mapapi.addLayer(_marker) + if (_GLOBAL.GPSMarker) { + window.mapapi.removeLayer(_GLOBAL.GPSMarker) + } + _GLOBAL.GPSMarker = createGPSMarker([lon, lat], _GLOBAL.rotate); + window.mapapi.addLayer(_GLOBAL.GPSMarker) + }); } } - +//鍒涘缓褰撳墠瀹氫綅鐐� export function createGPSMarker(position, rotate) { const GPSMarkerLayer = new ol.layer.Vector({ id: 'LocationPoint', @@ -194,17 +178,18 @@ }; +//鐩戝惉瀹氫綅鐐硅窡闅忔棆杞� export function listenDirection() { window.addEventListener('deviceorientation', function (e) { - if (_marker) { - _rotate = e.alpha * (Math.PI / -180); + if (_GLOBAL.GPSMarker) { + _GLOBAL.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, + rotation: _GLOBAL.rotate, anchorXUnits: "fraction", anchorYUnits: "fraction", scale: 0.5, -- Gitblit v1.9.3