| | |
| | | |
| | | import _GLOBAL from '@/assets/GLOBAL2' |
| | | import gcj02Mecator from '@/utils/transform' |
| | | import { ceil } from 'lodash'; |
| | | //清除 |
| | | export function clearAll() { |
| | | if (_GLOBAL.ImageLayer) { |
| | |
| | | |
| | | |
| | | //获取当前定位 |
| | | 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); |
| | | }; |
| | | |
| | | |
| | | |
| | | |
| | | |