From fa05dfcce55b8589d7f76175700a92fe196dcd9b Mon Sep 17 00:00:00 2001 From: lixuliang <lixuliang_hd@126.com> Date: 星期三, 13 三月 2024 17:59:52 +0800 Subject: [PATCH] 图层切换叠压 --- src/utils/tool.js | 91 +++++++++++++++++++++++++++++++++++++++------ 1 files changed, 78 insertions(+), 13 deletions(-) diff --git a/src/utils/tool.js b/src/utils/tool.js index 7cea36d..e4384d4 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) { @@ -29,9 +30,12 @@ _GLOBAL.ImageLayer = new ol.layer.Tile({ source: new ol.source.XYZ({ url: `${'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer'}/tile/{z}/{y}/{x}`, + projection:"EPSG:3857", + tileSize: 512 }), }); - window.mapapi.addLayer(_GLOBAL.ImageLayer); + // window.mapapi.addLayer(_GLOBAL.ImageLayer); + layersArray.insertAt(1, _GLOBAL.ImageLayer); } //鍔犺浇鐧借壊鍦板浘 @@ -42,14 +46,15 @@ url: "https://skyzt.bda.gov.cn/gisserver/wmsserver/shiliangditu_baisexi_wms", //鍥惧眰鍦板潃 params: { VERSION: "1.1.1", - SRS: "EPSG:4326", + SRS: "EPSG:3857", FORMAT: "image/png", TILED: true, LAYERS: "", }, }), }); - window.mapapi.addLayer(_GLOBAL.baseMap) + // window.mapapi.addLayer(_GLOBAL.baseMap) + layersArray.insertAt(1, _GLOBAL.baseMap); } @@ -62,8 +67,8 @@ url: ` https://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}`, }), }); - window.mapapi.addLayer(_GLOBAL.geoMap); - + // window.mapapi.addLayer(_GLOBAL.geoMap); + layersArray.insertAt(1, _GLOBAL.geoMap); } @@ -87,7 +92,7 @@ url: 'https://skyzt.bda.gov.cn/gisserver/wmsserver/YZ_BJ60', params: { 'VERSION': '1.1.1', - 'SRS': 'EPSG:4326', + 'SRS': 'EPSG:3857', 'FORMAT': 'image/png', 'TILED': true, "LAYERS": '' @@ -105,7 +110,7 @@ url: 'https://skyzt.bda.gov.cn/gisserver/wmsserver/YZ_BJ',//鍥惧眰鍦板潃 params: { 'VERSION': '1.1.1', - 'SRS': 'EPSG:4326', + 'SRS': 'EPSG:3857', 'FORMAT': 'image/png', 'TILED': true, "LAYERS": '' @@ -118,27 +123,87 @@ //鍔犺浇鍘嗗彶褰卞儚 export function addHistoryLayer(name) { const layerName = name; + if (_GLOBAL.historyLayer) { + window.mapapi.removeLayer(_GLOBAL.historyLayer) + } _GLOBAL.historyLayer = new ol.layer.Tile({ source: new ol.source.XYZ({ + projection:"EPSG:3857", url: `https://skyzt.bda.gov.cn/yzAdapter/Vector/?request=1&year=${layerName}&type=Sate&level={z}&x={x}&y={y}`, }) }); window.mapapi.addLayer(_GLOBAL.historyLayer); } - -//鑾峰彇褰撳墠瀹氫綅 - - +//瀹炴椂鑾峰彇瀹氫綅 export function getCurrentPosition() { if (navigator.geolocation) { - navigator.geolocation.getCurrentPosition((res) => { - console.log(res);//杩欓噷浼氳繑鍥炵粡绾害锛岀劧鍚庤繕瑕侀�氳繃缁忕含搴﹁浆鎹㈠湴鍖哄悕绉� + navigator.geolocation.watchPosition((res) => { + let lat = res.coords.latitude; + let lon = res.coords.longitude; + 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', + 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 (_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: _GLOBAL.rotate, + anchorXUnits: "fraction", + anchorYUnits: "fraction", + scale: 0.5, + opacity: 1 + }) + }) + ) + } + }, false); +}; + -- Gitblit v1.9.3