13693261870
2023-06-21 cdf12fc9e88b1af69f5c85165eb9fef4e23bf57a
1
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
Vue.use(Vuex)
 
export default new Vuex.Store({
  // state里面就是存放项目中需要多组件共享的状态
  state: {
    count: 0,
    data: null,
    vudideoUrl: '',
    videoName: '',
    videoId: null,
    showVideoFlag: false,
    showVideourl: null,
    billboards: [],
    ShowPanoramicFlag: false,
    flagID: null,
    index: -1,
    poiFlag: null,
    mainUrl: null,
    poiStatus: 1, // 1-显示3DPOI,2-显示2DPOI,3-隐藏所有
    _3ds: [],
    _2ds: [],
    xOffset: -0.0032850793719939,
    yOffset: 0.0278651231623049,
    // 坐标转换
    transform: function (x, y) {
      //console.log(this.xOffset, this.yOffset)
      //return map.transformWGS84ToLocal(x + this.xOffset, y + this.yOffset)
      return map.transformWGS84ToLocal((x - 26.897633220927) * 1.3, (y - 9.16663529527973) * 1.3)
    },
    // 创建3DPOI
    create3DPOI: function (data, startIdx, isHighlight) {
      let points = [];
      for (let i = 0, c = data.length; i < c; i++) {
        let p = this.transform(data[i].longitude, data[i].latitude);
        points.push({
          index: i + startIdx,
          id: data[i].channelId,
          x: p.x,
          y: p.y,
          z: 1500,
          //image: this.mainUrl + (isHighlight ? 'UE/img/1.png' : 'UE/img/2.png'),
          image: (isHighlight ? 'UE/img/1.png' : 'UE/img/2.png'),
          text: '',
          scale: 20,
          clickedScale: 20,
          visibility: true,
          flash: false,
          canClick: true,
          channelId: data[i].channelId
        });
      }
      return map.create3DBillboard(points);
    },
    // 创建2DPOI
    create2DPOI: function (d, idx, isHighlight) {
      let p = this.transform(d.longitude, d.latitude);
      return map.createBillboard({
        index: idx,
        id: d.channelId,
        x: p.x,
        y: p.y,
        z: p.z,
        //image: this.mainUrl + (isHighlight ? 'UE/img/1.png' : 'UE/img/2.png'),
        image: (isHighlight ? 'UE/img/1.png' : 'UE/img/2.png'),
        text: "",
        scale: 0.2,
        channelId: d.channelId,
        clickedScale: 0.2,
        flash: false,
        canClick: true,
        alertWindow: null
      });
    },
    // 获取显示状态
    getVisibleStatus: function () {
      let dis = map.camera.distance;
      if (dis > 500000) return 3;
 
      if (dis > 100000) return 2;
 
      return 1;
    }
  },
  // mutations就是存放更改state里状态的方法
  mutations: {
    // 添加视频点 *
    addVideos (state, data) {
      //debugger
      this.commit('removeBillboards');
      this.commit('pretreat', data);
      this.commit('add3DPOI');
      this.commit('add2DPOI');
      this.commit('setPOIVisible');
      //this.commit('flyToData');
    },
    // 清除
    removeBillboards (state) {
      map.removeCluster();
      map.clearAllCovering();
      state._3ds.length = 0;
      state._2ds.length = 0;
      state.index = -1;
    },
    // 预处理
    pretreat: function (state, data) {
      state.data = [];
      for (let i = 0, c = data.length; i < c; i++) {
        let d = data[i];
        if (!d.longitude || isNaN(d.longitude) || !d.latitude || isNaN(d.latitude) || !d.channelStatus) continue;
 
        d.longitude = parseFloat(d.longitude)
        d.latitude = parseFloat(d.latitude)
        state.data.push(d)
      }
    },
    // 添加三维POI
    add3DPOI (state) {
      for (let i = 0, c = Math.ceil(state.data.length / 10); i < c; i++) {
        let points = state.data.slice(i * 10, (i + 1) * 10);
        let arr = state.create3DPOI(points, i * 10, false);
 
        state._3ds = state._3ds.concat(arr);
      }
    },
    // 添加二维POI
    add2DPOI (state) {
      for (let i = 0, c = state.data.length; i < c; i++) {
        let poi = state.create2DPOI(state.data[i], i, false);
        state._2ds.push(poi);
      }
    },
    // 设置POI显示
    setPOIVisible (state) {
      state.poiStatus = state.getVisibleStatus();
 
      let arr = state.poiStatus === 1 ? state._2ds : state._3ds;
      arr.forEach(function (b) {
        b.show(false);
      });
 
      if (state.poiStatus === 2) map.createCluster({ interval: 500000, size: 10 });
    },
    // 飞向数据
    flyToData (state) {
      /*var minX = 180, minY = 90, maxX = 0, maxY = 0;
      for (var i = 0, c = state.data.length; i < c; i++) {
        let x = state.data[i].longitude, y = state.data[i].latitude;
 
        if (x > maxX) maxX = x;
        if (y > maxY) maxY = y;
        if (x < minX) minX = x;
        if (y < minY) minY = y;
      }
 
      var cx = (minX + maxX) / 2, cy = (minY + maxY) / 2;
      var p = state.transform(cx, cy);
 
      //map.flyTo(p.x, p.y, 0, 0, -42, 0, 50000, null, 3);
      map.focusOn(new TUVector3(p.x, p.y, 0), new TURotator(0, -42, 0));*/
      // setTimeout(function () {
      //   map.focusOn(new TUVector3(p.x, p.y, 0), new TURotator(0, -42, 20));
      // }, 1500);
 
      let x = state.data[0].longitude, y = state.data[0].latitude;
      var p = state.transform(x, y);
      map.focusOn(new TUVector3(p.x, p.y, 0), new TURotator(0, -42, 0));
      //map.setView(p.x, p.y, 0, 0, -42, 0, 6000);
    },
    // 切换视频点 *
    changeVideo (state, index) {
      let status = state.getVisibleStatus();
      if (state.index != -1) {
        this.commit('change3DPOI', { idx: state.index, flag: false, status: status });
        this.commit('change2DPOI', { idx: state.index, flag: false, status: status });
      }
 
      this.commit('change3DPOI', { idx: index, flag: true, status: status });
      this.commit('change2DPOI', { idx: index, flag: true, status: status });
      state.index = index;
    },
    // 切换3DPOI
    change3DPOI (state, rs) {
      let d = state.data[rs.idx];
      let poi = state.create3DPOI([d], rs.idx, rs.flag)[0];
 
      state._3ds[rs.idx].removeFromMap();
      state._3ds.splice(rs.idx, 1, poi);
 
      if (rs.status !== 1) poi.show(false);
    },
    // 切换2DPOI
    change2DPOI (state, rs) {
      let d = state.data[rs.idx];
      let poi = state.create2DPOI(d, rs.idx, rs.flag);
 
      state._2ds[rs.idx].removeFromMap();
      state._2ds.splice(rs.idx, 1, poi);
 
      if (rs.status !== 2) poi.show(false);
    },
    // 切换POI显示状态 *
    changePOIVisible (state, status) {
      state.poiStatus = status;
      if (status !== 2) map.removeCluster();
 
      state._2ds.forEach(function (b) {
        b.show(status === 2);
      });
 
      state._3ds.forEach(function (a) {
        a.show(status === 1);
      });
 
      if (status === 2) map.createCluster({ interval: 500000, size: 10 });
    },
    // 切换图片
    changeImg: function (state, rs) {
      if (state.index != -1) {
        let status = state.getVisibleStatus();
        this.commit('change3DPOI', { idx: state.index, flag: false, status: status });
        this.commit('change2DPOI', { idx: state.index, flag: false, status: status });
        state.index = -1;
      }
    }
  },
  // actions就是mutation的加强版,它可以通过commit mutations中的方法来改变状态,最重要的是它可以进行异步操作。
  //actions不能直接修改state里的值必须通过触发某个mutation才行
  actions: {
    addAsync (context, step) {
      // 异步操作mutations里的方法
      setTimeout(() => {
        context.commit('addN', step)
      }, 1000)
    },
    subAsync (context, step) {
      // 异步操作mutations里的方法
      setTimeout(() => {
        context.commit('subN', step)
      }, 1000)
    }
  },
  //相当于计算属性不会修改state里本身的值
  getters: {
    showNum (state) {
      return `2`
    }
  }
});