北京经济技术开发区经开区虚拟城市项目-【前端】-移动端Web
少年
2024-03-06 a18adf9f3b30a5ff51c163059e4af9ffcd2af536
youhua
已修改5个文件
127 ■■■■ 文件已修改
src/assets/GLOBAL2.vue 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/poplayer/history2.vue 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/viewer2.vue 62 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/map2.js 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/tool.js 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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>
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) {
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) {
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,
            });
        }
    }
}
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,