liuyg
2022-01-08 5e47738f99e307bab1c8a5ee9ecd96d8c7f4a968
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
import $store from "../index";
const mobile = {
  state: {
    mviewer: null, // 地图实体类
    mBigPopup: false, // 全屏弹窗
    popupOurOpenData: [], // 全屏弹窗中下拉菜单数据
    popupTableName: [], // 全屏弹窗标签页数据
    mBigPopupAfter: false, /// /全屏弹窗之前的弹窗
    ips: "", // 获取的ip
    iconHide: false, // 右侧伸缩状态
    // DC: '',//DC全局保存
    MobileWindowsHide: true, // 改变点击窗口的显示状态
    MobileWindowChangeData: false, // 改变点击窗口的数据
    popupsDom: "", // mobileDivForms的实体类
    query: {}, // 传输数据
    openmobileGoTo: false, // 测试
    ccDataState: false, // 测试
    openmobilePanorama: false, // 实景显影
    MobileWindowsHideFixed: true, // 改变点击窗口的显示状态--固定窗口
    MobileWindowChangeDataFixed: false, // 改变点击窗口的数据--固定窗口
    // 在每次飞行弹窗中  加入自己的点
    pointLayer: null,
    pointLayerData: {
      flag: false,
      label: "选择点",
      img: "/img/leftnav/way.png",
      normal: "/img/leftnav/way.png",
      checked: "/img/leftnav/way-checked.png",
      layer: "pointLayer",
    },
    // 默认起始点函数
    startPointFn: "",
    dimension: "2.5D", // 维度
    dimensionData: {
      // 维度镜头数据
      heading: 0,
      pitch: -90,
      roll: 0,
    },
    perspectiveControl: "", //视角控制:高度、角度  ()=>{}
    perspectiveControls: "", //视角控制:高度、角度  ()=>{}
 
    tilesetLayer: null, //3d模型
    tileset: null, //3d模型
    tilesetLayer: null, //2.5d模型
    usetowpointfive: null,
    tilesetLayer: null, //瀑布流
 
    vecLayer: null, //3D底图
    cvaLayer: null, //3D底图
 
    audioData: null, //语音
    audioState: false, //语音状态
  },
  mutations: {
    MSET_VIEWER(state, viewer) {
      state.mviewer = viewer;
    },
    MSET_BIGPOPUP(state, viewer) {
      state.mBigPopup = viewer;
      $store.dispatch("closeMobileWindowsDom"); // 关闭弹窗
    },
    MSET_BIGPOPUPAFTER(state, viewer) {
      state.mBigPopupAfter = viewer;
      $store.dispatch("closeMobileWindowsDom"); // 关闭弹窗
    },
    MSET_POPUPOUROPENDATA(state, viewer) {
      state.popupOurOpenData = viewer;
    },
    MSET_ICONHIDE(state, viewer) {
      state.iconHide = viewer;
    },
    MSET_POPUPTABLENAME(state, viewer) {
      state.popupTableName = viewer;
    },
    MSET_MOBILEWINDOWSHIDE(state, viewer) {
      // 随地图移动窗口
      state.MobileWindowChangeData = !state.MobileWindowChangeData;
      state.MobileWindowsHide = viewer;
    },
    MSETCC_SETCC(state, viewer) {
      state.ccDataState = !state.ccDataState; // 专门测试
      state.query = viewer;
    },
    MSET_POPUPDOM(state, viewer) {
      state.popupsDom = viewer;
    },
    MSET_QUERY(state, viewer) {
      state.query = viewer;
    },
    MSET_OPENMOBILEGOTO(state, viewer) {
      state.openmobileGoTo = viewer;
    },
    MSET_OPENMOBILEPANORAMA(state, viewer) {
      state.openmobilePanorama = viewer;
    },
    MSET_MOBILEWINDOWSHIDEFIXED(state, viewer) {
      // 固定窗口
      state.MobileWindowChangeDataFixed = !state.MobileWindowChangeDataFixed;
      state.MobileWindowsHideFixed = viewer;
      console.log(state.MobileWindowChangeDataFixed);
    },
    // 默认位置
    MSET_MORENWEIZHI(state, data) {
      state.startPointFn = data;
    },
    // // 开关飞入点图标
    // MSET_OPENPOINTEL(state, val) {
    //     if (val) {
    //         state.pointLayerData.img = state.pointLayerData.checked
    //         state[state.pointLayerData.layer].show = true
    //     } else {
    //         state.pointLayerData.img = state.pointLayerData.normal
    //         state[state.pointLayerData.layer].show = false
    //     }
    // },
    //切换2D和2.5D
    MSET_DIMENSION(state, data) {
      //关闭弹窗
      //3d,2.5d转换事件
      state.dimension = data;
      if (data == "3D") {
        // 改数据为3d数据
        state.dimensionData = {
          // 维度镜头数据
          heading: 0,
          pitch: -45,
          roll: 0,
        };
        //加载底图
        state.vecLayer = state.mviewer.imageryLayers.addImageryProvider(
          new global.DC.Namespace.Cesium.WebMapTileServiceImageryProvider({
            url: " http://t1.tianditu.gov.cn/vec_w/wmts?tk=9ae78c51a0a28f06444d541148496e36",
            type: "wmts",
            layer: "vec",
            style: "default",
            format: "tiles",
            tileMatrixSetID: "w",
            show: true,
            maximumLevel: 18,
          })
        );
        state.cvaLayer = state.mviewer.imageryLayers.addImageryProvider(
          new global.DC.Namespace.Cesium.WebMapTileServiceImageryProvider({
            url: " http://t1.tianditu.gov.cn/cva_w/wmts?tk=9ae78c51a0a28f06444d541148496e36",
            type: "wmts",
            layer: "cva",
            style: "default",
            format: "tiles",
            tileMatrixSetID: "w",
            show: true,
            maximumLevel: 18,
          })
        );
        // console.log(1321)
        state.wallLayer.show = false; //关闭瀑布   以及2.5d图形贴片
        state.mviewer.imageryLayers.remove(state.newLayer);
        state.newLayer = null;
        // state.silhouetteBlue.selected = []
        // state.tilesetLayer.changesilhouetteBlue(); //清空silhouetteBlue.selected = [];
        // console.log(state.tileset)
        state.tilesetLayer.show = true; //显示3d图形
        state.startPointFn(); //移动默认视角
        // state.mviewer.flyTo(state.tileset);
 
        //3D视角不限制
        state.mviewer.scene.screenSpaceCameraController.minimumZoomDistance = 80;
        // 最大
        state.mviewer.scene.screenSpaceCameraController.maximumZoomDistance = 4000000;
        // 设置相机缩小时的速率
        state.mviewer.scene.screenSpaceCameraController._minimumZoomRate = 10000;
        // 设置相机放大时的速率
        state.mviewer.scene.screenSpaceCameraController._maximumZoomRate = 5906376272000;
        // 视角平移
        state.mviewer.scene.screenSpaceCameraController.enableRotate = true;
        // 视角缩放
        state.mviewer.scene.screenSpaceCameraController.enableZoom = true;
        // 视角旋转
        state.mviewer.scene.screenSpaceCameraController.enableTilt = true;
      } else if (data == "2.5D") {
        state.dimensionData = {
          // 维度镜头数据
          heading: 0,
          pitch: -90,
          roll: 0,
        };
        //取消3D底图
        state.mviewer.imageryLayers.remove(state.vecLayer);
        state.vecLayer = null;
        state.mviewer.imageryLayers.remove(state.cvaLayer);
        state.cvaLayer = null;
        state.tilesetLayer.show = false; //隐藏3d图形
        state.newLayer = state.usetowpointfive(); //添加2.5d图形贴片
        state.wallLayer.show = false; //打开瀑布
        state.startPointFn(); //移动默认视角
 
        //2.5D视角限制
        state.mviewer.scene.screenSpaceCameraController.minimumZoomDistance = 0;
        // 最大
        state.mviewer.scene.screenSpaceCameraController.maximumZoomDistance = 4000;
        // 设置相机缩小时的速率
        // state.mviewer.scene.screenSpaceCameraController._minimumZoomRate = 30000;
        // 设置相机放大时的速率
        state.mviewer.scene.screenSpaceCameraController._maximumZoomRate = 5906376272000;
        // 视角平移
        state.mviewer.scene.screenSpaceCameraController.enableRotate = true;
        // 视角缩放
        state.mviewer.scene.screenSpaceCameraController.enableZoom = true;
        // 视角旋转
        state.mviewer.scene.screenSpaceCameraController.enableTilt = false;
      }
    },
    //切换控制
    MSET_PERSPECTIVECONTROL(state, data) {
      state.perspectiveControl = data;
      state.perspectiveControls = !state.perspectiveControls;
    },
    MSET_MODEOLS(state, data) {
      state.tilesetLayer = data.tilesetLayer;
      state.newLayer = data.newLayer;
      state.wallLayer = data.wallLayer;
      state.tileset = data.tileset;
      state.usetowpointfive = data.usetowpointfive;
    },
  },
  actions: {
    MSET_CREADE({ state, commit, dispatch }) {
      state.pointLayer = new global.DC.VectorLayer("pointLayer"); // 创建图标实体类
      state.mviewer.addLayer(state.pointLayer); // 添加到地图
    },
    setMobileWindows({ state, commit, dispatch }, data) {
      // 打开随地图移动窗口
      let clas, Flys;
      const nowHeight = Math.ceil(
        state.mviewer.camera.positionCartographic.height
      );
      console.log(data);
      if (state.dimension == "3D") {
        Flys = [
          +data.lntLat[0] + 0.01197,
          // +data.lntLat[1] - 0.0001,
          +data.lntLat[1] - 0.0027,
          330,
        ];
        clas = [
          data.from == "PopupOurOnce" ? +data.lntLat[0] : +data.lntLat[0],
          // data.from == 'PopupOurOnce' ? +data.lntLat[1] - 0.00108 : +data.lntLat[1],
          data.from == "PopupOurOnce"
            ? +data.lntLat[1] - 0.00108
            : +data.lntLat[1] - 0.00048,
          data.from == "PopupOurOnce" ? 0 : 30.648862227,
        ];
      } else if (state.dimension == "2.5D") {
        Flys = [
          +data.lntLat[0] + 0.01197,
          +data.lntLat[1] + 0.00048,
          // +data.lntLat[1] - 0.0022,
          // nowHeight,
          360,
        ];
        // console.log(nowHeight);
        clas = [
          data.from == "PopupOurOnce" ? +data.lntLat[0] : +data.lntLat[0],
          data.from == "PopupOurOnce" ? +data.lntLat[1] : +data.lntLat[1],
          // data.from == 'PopupOurOnce' ? +data.lntLat[1] - 0.00108 : +data.lntLat[1] - 0.00048,
          // data.from == 'PopupOurOnce' ? 0 : 90.648862227
          data.from == "PopupOurOnce" ? 0 : 0,
        ];
      }
 
      if (data.useJWD) {
        var ellipsoid = state.mviewer.scene.globe.ellipsoid;
        var cartographic = global.DC.Namespace.Cesium.Cartographic.fromDegrees(
          // data.lntLat[0],
          // data.lntLat[1] - 0.00048,//数值增大是下
          // "90.648862227"
          // clnt, clat, calt
          ...clas
        );
        data.position = ellipsoid.cartographicToCartesian(cartographic);
      }
      // 传递响应数据
      commit("MSET_QUERY", data);
      // 定制化窗体
      const popupsDom = new global.DC.mobileDivForms(state.mviewer, {
        domId: "mobilePopup",
        title: data.query.name || "成教楼  ",
        className: "mobilePopup",
        content: document.getElementById("mobile-map_content_content"),
        position: [data.position],
      });
      // commit("MSET_MOBILEWINDOWSHIDE", false)//显示弹窗
      // dispatch("CHANGETOC3", { // 转换坐标
      //     lnt: data.lntLat[0],
      //     lat: data.lntLat[1]
      // }).then(res => {
      // console.log(res)
 
      // 基于高度基础设置
      // h:1530
      // lnt: + 0.01187 x轴 大是向左
      // Lat: - 0.0108 y轴 减是上
      // h:4000
      // lnt: + 0.01187 x轴
      // Lat: - 0.0308 y轴
      // h:330
      // lnt: + 0.01197 x轴
      // Lat: - 0.0021 y轴
      // console.log(data.query.from, 78)
      // let Flys = [
      //     data.query.from == "地图点击" ? +data.lntLat[0] + 0.01197 : +data.lntLat[0] + 0.01197,
      //     data.query.from == "地图点击" ? +data.lntLat[1] - 0.0021 : +data.lntLat[1] - 0.0021,
      //     data.query.from == "地图点击" ? 330 : 330,
      // ]
 
      const Position = new global.DC.Position( // 转坐标
        // +data.lntLat[0] + 0.01197,
        // +data.lntLat[1] - 0.0021,
        // 330,
        ...Flys,
        0,
        state.dimensionData.pitch
      );
      if (state.dimension != "2.5D") {
        // if (true) {
        dispatch("mapFlyTo", {
          //飞入
          lntLat: [Position.lng, Position.lat, Position.alt],
          heading: Position.heading,
          pitch: Position.pitch,
          roll: Position.roll,
        });
      } else {
        // console.log(17878);
        state.mviewer.camera.setView({
          // Cesium的坐标是以地心为原点,一向指向南美洲,一向指向亚洲,一向指向北极州
          // fromDegrees()方法,将经纬度和高程转换为世界坐标
          destination: new global.DC.Namespace.Cesium.Cartesian3.fromDegrees(
            // 114.0351,
            // 27.6314,
            // 200.0
            Position.lng - 0.012,
            Position.lat,
            Position.alt || 15000.0
          ),
          orientation: {
            heading: global.DC.Namespace.Cesium.Math.toRadians(
              Position.heading
            ),
            pitch: global.DC.Namespace.Cesium.Math.toRadians(Position.pitch),
            // heading: data.heading,
            // pitch: data.pitch,
            roll: Position.roll,
          },
        });
        commit("MSET_MOBILEWINDOWSHIDE", false); // 显示弹窗
      }
      // })
      commit("MSET_POPUPDOM", popupsDom);
    },
    closeMobileWindowsDom({ state, commit, dispatch }) {
      if (!state.MobileWindowsHide && state.popupsDom) {
        state.popupsDom.closeOur();
        commit("MSET_MOBILEWINDOWSHIDE", true);
        if (state.audioData) {
          dispatch("MSET_GETAUDIOBEGIN", "notOpen");
        }
      } //cancel
    },
    CHANGETOC3({ state, commit }, data) {
      // //转换经纬度坐标 成世界坐标cartesian3
      var ellipsoid = state.mviewer.scene.globe.ellipsoid;
      var cartographic = global.DC.Namespace.Cesium.Cartographic.fromDegrees(
        data.lnt,
        data.lat - 0.00006,
        data.alt || "90.648862227"
      );
      var position = ellipsoid.cartographicToCartesian(cartographic);
      return position;
    },
    SET_OPENWIDOWFIXED({ state, commit }, data) {
      // 传递响应数据
      commit("MSET_QUERY", data);
      // 显示窗口
      commit("MSET_MOBILEWINDOWSHIDEFIXED", false);
      // 移动地图位置
      state.mviewer.zoomToPosition(
        new global.DC.Position(
          data.lntLat[0],
          data.lntLat[1] - 0.012,
          1530,
          0,
          -45
        )
      );
    },
    CLOSE_WIDOWFIXED({ state, commit }) {
      // 隐藏窗口
      if (!state.MobileWindowsHideFixed) {
        console.log(state.MobileWindowsHideFixed);
        commit("MSET_MOBILEWINDOWSHIDEFIXED", true);
      }
    },
    // 加入当时的选点
    JOIN_POINT({ state, commit }, data) {},
    // flyTo
    mapFlyTo({ state, commit, dispatch }, data) {
      state.mviewer.camera.flyTo({
        destination: global.DC.Namespace.Cesium.Cartesian3.fromDegrees(
          data.lntLat[0] - 0.012,
          data.lntLat[1],
          data.lntLat[2] || 15000.0
        ),
        // destination: data.res,
        orientation: {
          heading: global.DC.Namespace.Cesium.Math.toRadians(data.heading),
          pitch: global.DC.Namespace.Cesium.Math.toRadians(data.pitch),
          // heading: data.heading,
          // pitch: data.pitch,
          roll: data.roll,
        },
        duration: 1.5, // 定位的时间间隔
        complete: () => {
          // 完成后的回调
          if (data.fn) {
            // 自定义回调
            setTimeout(() => {
              data.fn();
            }, 500);
          }
          if (!data.noOpen) {
            setTimeout(() => {
              // dispatch("MSET_POINTDATA", data.lntLat);//传入标记点
              !state.MobileWindowsHide ||
                commit("MSET_MOBILEWINDOWSHIDE", false); // 显示弹窗
            }, 0);
          }
        },
      });
      // 官网flyto使用方法
      // 1. Fly to a position with a top-down view
      // viewer.camera.flyTo({
      //     destination : Cesium.Cartesian3.fromDegrees(-117.16, 32.71, 15000.0)
      // });
 
      // // 2. Fly to a Rectangle with a top-down view
      // viewer.camera.flyTo({
      //     destination : Cesium.Rectangle.fromDegrees(west, south, east, north)
      // });
 
      // // 3. Fly to a position with an orientation using unit vectors.
      // viewer.camera.flyTo({
      //     destination : Cesium.Cartesian3.fromDegrees(-122.19, 46.25, 5000.0),
      //     orientation : {
      //         direction : new Cesium.Cartesian3(-0.04231243104240401, -0.20123236049443421, -0.97862924300734),
      //         up : new Cesium.Cartesian3(-0.47934589305293746, -0.8553216253114552, 0.1966022179118339)
      //     }
      // });
 
      // // 4. Fly to a position with an orientation using heading, pitch and roll.
      // viewer.camera.flyTo({
      //     destination : Cesium.Cartesian3.fromDegrees(-122.19, 46.25, 5000.0),
      //     orientation : {
      //         heading : Cesium.Math.toRadians(175.0),
      //         pitch : Cesium.Math.toRadians(-35.0),
      //         roll : 0.0
      //     }
      // });
    },
    // 飞入点加入位置
    MSET_POINTDATA({ state, commit, dispatch }, data) {
      // 加入坐标
      const positions = new global.DC.Position(
        data[0] - 0.0119,
        data[1] + 0.0111,
        0
      );
      const billboard = new global.DC.Billboard(
        positions,
        "/img/leftnav/map-panorama.png"
      );
      billboard.size = [16, 16];
      // 订阅事件3
      billboard.on(DC.MouseEventType.CLICK, (e) => {
        // 定制化窗体
        console.log(e);
        const query = { name: "选择点" };
        const intLat = [e.wgs84Position.lng, e.wgs84Position.lat];
        const d = {
          position: null,
          lntLat: intLat,
          query: { ...(query || {}), introduce: null, address: intLat },
          useJWD: true, // 仅使用经纬度
        };
        dispatch("setMobileWindows", d);
      });
      state.pointLayer.addOverlay(billboard); // 实景
      // commit("MSET_OPENPOINTEL", true);
    },
    MSET_LOCKPERSPECTIVEL({ state, commit, dispatch }, val) {
      // 锁定
      state.mviewer.camera.lookAtTransform(
        global.DC.Namespace.Cesium.Matrix4.IDENTITY
      );
      // console.log(global.DC.Namespace.Cesium.Matrix4.IDENTITY)
    },
    MSET_DIMENSIONS({ state, commit, dispatch }, val) {
      //关闭弹窗
      dispatch("closeMobileWindowsDom");
      //3d,2.5d转换事件
      commit("MSET_DIMENSION", val);
      //控制高度
      const height = Math.ceil(
        state.mviewer.camera.positionCartographic.height
      );
      state.mviewer.camera.setView({
        destination: global.DC.Namespace.Cesium.Cartesian3.fromRadians(
          state.mviewer.camera.positionCartographic.longitude,
          state.mviewer.camera.positionCartographic.latitude,
          height
        ),
        orientation: {
          heading: global.DC.Namespace.Cesium.Math.toRadians(
            state.dimensionData.heading
          ), // 方向
          pitch: global.DC.Namespace.Cesium.Math.toRadians(
            state.dimensionData.pitch
          ), // 倾斜角度
          roll: state.dimensionData.roll,
        },
      });
    },
    MSET_GOTOCC({ state, commit, dispatch }, val) {
      //测试移动位置
      // commit("MSET_DIMENSION", val);
      //控制高度
      // const height = Math.ceil(state.mviewer.camera.positionCartographic.height);
      state.mviewer.camera.setView({
        destination: global.DC.Namespace.Cesium.Cartesian3.fromRadians(
          state.mviewer.camera.positionCartographic.longitude,
          state.mviewer.camera.positionCartographic.latitude,
          val.height
        ),
        orientation: {
          heading: global.DC.Namespace.Cesium.Math.toRadians(val.heading), // 方向
          pitch: global.DC.Namespace.Cesium.Math.toRadians(val.pitch), // 倾斜角度
          roll: val.roll,
        },
      });
    },
    MSET_GETAUDIO({ state, commit, dispatch }, val) {
      state.audioData = new window.SpeechSynthesisUtterance();
      state.audioData.text = val;
      state.audioData.onstart = function (e) {
        state.audioState = true;
      };
      state.audioData.onend = function (event) {
        state.audioState = false;
      };
    },
    MSET_GETAUDIOBEGIN({ state, commit, dispatch }, val) {
      if (state.audioState) {
        window.speechSynthesis.cancel();
        state.audioState = false;
      } else {
        if (val != "notOpen") {
          window.speechSynthesis.speak(state.audioData);
        }
      }
    },
  },
};
 
export default mobile;