Blame view

src/components/system/ViewMap.vue 3.03 KB
b25b036d   wuxw   v1.9 优化日期
1
  <template>
a42b3256   wuxw   HC小区管理系统前段vue版正在开发中
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
      <div id="viewMap" :style="{ visibility: viewMapInfo.showMap }">
        <div class="map-container">
          <div id="qqmapcontainer" style="width: 1200px; height: 400px; background-color: antiquewhite;"></div>
          <i class="el-icon-close close-icon" @click="closeMap" />
        </div>
      </div>
    </template>
    
    <script>
    export default {
      name: 'ViewMap',
      data() {
        return {
          viewMapInfo: {
            lat: '',
            lng: '',
            showMap: 'hidden',
            map: null
          }
        }
      },
      methods: {
        open(param) {
          const lngLat = this.wgs84togcj02(param.lng, param.lat)
          this.viewMapInfo.lat = lngLat.lat
          this.viewMapInfo.lng = lngLat.lon
          this.viewMapInfo.showMap = 'visible'
          this.launchIntoMapFullscreen()
          this.$nextTick(() => this.initMap())
        },
        initMap() {
          const center = new window.TMap.LatLng(this.viewMapInfo.lat, this.viewMapInfo.lng)
          const container = document.getElementById('qqmapcontainer')
          this.viewMapInfo.map = new window.TMap.Map(container, {
            center,
            zoom: 17.2,
            viewMode: '2D'
          })
          new window.TMap.MultiMarker({
            id: 'marker-layer',
            map: this.viewMapInfo.map,
            styles: {
              marker: new window.TMap.MarkerStyle({
                width: 25,
                height: 35,
                anchor: { x: 16, y: 32 },
                src: 'https://mapapi.qq.com/web/lbs/javascriptGL/demo/img/markerDefault.png'
              })
            },
            geometries: [{
              id: 'demo',
              styleId: 'marker',
              position: new window.TMap.LatLng(this.viewMapInfo.lat, this.viewMapInfo.lng),
              properties: { title: 'marker' }
            }]
          })
        },
        closeMap() {
          this.exitMapFullscreen()
          this.viewMapInfo.showMap = 'hidden'
          this.viewMapInfo.map.destroy()
        },
        launchIntoMapFullscreen() {
          const full = document.getElementById('viewMap')
          if (full.requestFullscreen) full.requestFullscreen()
          else if (full.mozRequestFullScreen) full.mozRequestFullScreen()
          else if (full.webkitRequestFullscreen) full.webkitRequestFullscreen()
          else if (full.msRequestFullscreen) full.msRequestFullscreen()
        },
        exitMapFullscreen() {
          if (document.exitFullscreen) document.exitFullscreen()
          else if (document.mozCancelFullScreen) document.mozCancelFullScreen()
          else if (document.webkitExitFullscreen) document.webkitExitFullscreen()
        },
        wgs84togcj02(lng, lat) {
          // Placeholder for coordinate conversion
          return { lon: lng, lat }
        }
      }
    }
    </script>
    
    <style lang="scss" scoped>
    #viewMap {
      .map-container {
        position: fixed;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        background-color: #fff;
      }
      .close-icon {
        position: absolute;
        right: 20px;
        top: 20px;
        font-size: 20px;
        color: red;
        cursor: pointer;
      }
    }
    </style>