From 7c4546cc6f84adf52a4aaa61244635615041c178 Mon Sep 17 00:00:00 2001 From: lixuliang <lixuliang_hd@126.com> Date: 星期三, 06 三月 2024 18:10:51 +0800 Subject: [PATCH] Merge branch 'master' of http://103.135.160.14:9034/r/PM20221203225_MobileWeb --- src/components/viewer2.vue | 62 ++++++++++---------- src/assets/GLOBAL2.vue | 6 + src/components/poplayer/history2.vue | 3 + src/utils/tool.js | 42 +++++--------- src/utils/map2.js | 17 +++++ 5 files changed, 69 insertions(+), 61 deletions(-) diff --git a/src/assets/GLOBAL2.vue b/src/assets/GLOBAL2.vue index 7c4fb01..3053acc 100644 --- a/src/assets/GLOBAL2.vue +++ b/src/assets/GLOBAL2.vue @@ -8,7 +8,8 @@ const hexin = null; const yzxcgh = null; const historyLayer = null; -const rotate = null; +const rotate = 90; +const GPSMarker = null; export default { layers, //鏀堕泦鍣� @@ -20,6 +21,7 @@ hexin, yzxcgh, historyLayer, - rotate + rotate, + GPSMarker }; </script> \ No newline at end of file diff --git a/src/components/poplayer/history2.vue b/src/components/poplayer/history2.vue index 584f496..fd2a20a 100644 --- a/src/components/poplayer/history2.vue +++ b/src/components/poplayer/history2.vue @@ -38,6 +38,9 @@ store.setMapToolShow(false); window.mapapi.getView().setCenter([4.606512, 2.621472]); addHistoryLayer(this.currentValue); + if (_GLOBAL.GPSMarker) { + window.mapapi.removeLayer(_GLOBAL.GPSMarker); + } }, methods: { changeLeftMap(item) { diff --git a/src/components/viewer2.vue b/src/components/viewer2.vue index 36f3865..01f4e22 100644 --- a/src/components/viewer2.vue +++ b/src/components/viewer2.vue @@ -57,7 +57,7 @@ </template> <script> import store from "@/utils/store2.js"; -import { setClick, leftClick } from "@/utils/map2.js"; +import { setClick, leftClick,touchClick } from "@/utils/map2.js"; import _GLOBAL from "@/assets/GLOBAL2"; // import { leftClick, loadLayer } from "@/utils/map.js"; import leftBottom from "@/components/leftMenu/bottom2.vue"; @@ -266,18 +266,16 @@ }); window.mapapi = map; - addImageLayer(); addAnnotationLayer(); addHxLayer(); addYzLayer(); setClick(true); + touchClick(); getCurrentPosition(); listenDirection(); - - // leftClick() window.layerOpen = function (name, options) { @@ -336,34 +334,34 @@ }, methods: { clicktoclose() { - clearTimeout(this.timer); - this.timer = setTimeout(() => { - this.count++; - if (this.count == 2) { - // console.log("鍗曞嚮浜嬩欢"); - // 鍏抽棴鎵�鏈夊脊绐� - //this.$refs.menu.closeall(); - // 娓呴櫎瀹氫綅涓殑浣嶇疆鏍囪 - //this.$refs.menu.clearFlyPoint(); - } else { - // 鎵ц鏀惧ぇ鎿嶄綔 - // console.log("鍙屽嚮"); - // Viewer.camera.zoomIn(); - // console.log(window.clickPOI); - // let p = sgworld.Navigate.getDegrees(); - // console.log(p); - // Viewer.camera.flyTo({ - // destination: Cesium.Cartesian3.fromDegrees( - // window.clickPOI.lon, - // window.clickPOI.lat, - // p.height / 1.8 - // ), - // duration: 1.0, - // }); - } - this.count = 0; - }, 300); - this.count++; + // clearTimeout(this.timer); + // this.timer = setTimeout(() => { + // this.count++; + // if (this.count == 2) { + // // console.log("鍗曞嚮浜嬩欢"); + // // 鍏抽棴鎵�鏈夊脊绐� + // //this.$refs.menu.closeall(); + // // 娓呴櫎瀹氫綅涓殑浣嶇疆鏍囪 + // //this.$refs.menu.clearFlyPoint(); + // } else { + // // 鎵ц鏀惧ぇ鎿嶄綔 + // // console.log("鍙屽嚮"); + // // Viewer.camera.zoomIn(); + // // console.log(window.clickPOI); + // // let p = sgworld.Navigate.getDegrees(); + // // console.log(p); + // // Viewer.camera.flyTo({ + // // destination: Cesium.Cartesian3.fromDegrees( + // // window.clickPOI.lon, + // // window.clickPOI.lat, + // // p.height / 1.8 + // // ), + // // duration: 1.0, + // // }); + // } + // this.count = 0; + // }, 300); + // this.count++; }, datafromchild(data) { for (var i in data) { diff --git a/src/utils/map2.js b/src/utils/map2.js index a5e99db..30f1293 100644 --- a/src/utils/map2.js +++ b/src/utils/map2.js @@ -2483,5 +2483,22 @@ }) } +//鐩戝惉鍦板浘鍙屽嚮浜嬩欢 + +export function touchClick() { + let dom = document.getElementById('openlayerContainer'); + dom.addEventListener('touchstart', onTouchStart); + function onTouchStart(e) { + let len = e.touches.length; + if (len === 2) { + window.mapapi.getView().animate({ + center: window.mapapi.getView().getCenter(), + zoom: window.mapapi.getView().getZoom() - 1, + duration: 1000, + }); + } + } +} + diff --git a/src/utils/tool.js b/src/utils/tool.js index bb7973b..d70071b 100644 --- a/src/utils/tool.js +++ b/src/utils/tool.js @@ -119,6 +119,9 @@ //鍔犺浇鍘嗗彶褰卞儚 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({ url: `https://skyzt.bda.gov.cn/yzAdapter/Vector/?request=1&year=${layerName}&type=Sate&level={z}&x={x}&y={y}`, @@ -128,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', @@ -191,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