北京经济技术开发区经开区虚拟城市项目-【前端】-Web
lixuliang
2023-10-20 4509dd489115a499a0f63487ec90adfdc7a5cd56
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
<template>
  <div>
    <div id="sdkContainer"></div>
    <layerTreeTwoScreen v-if="layerTreeTwoScreen" />
    <!-- <div id="bottomInfo" v-html="bottomInfo"></div> -->
    <div
      id="switchImagerLayer"
      :style="{
        transform: `scale(${scale}) translate(${offset},${offset})`,
        '-webkit-transform': `scale(${scale}) translate(${offset},${offset})`,
        '-moz-transform': `scale(${scale}) translate(${offset},${offset})`,
        '-o-transform': `scale(${scale}) translate(${offset},${offset})`,
        '-ms-transform': `scale(${scale}) translate(${offset},${offset})`,
      }"
    >
      <transition
        name="animate__animated animate__bounce"
        @click="switchImagerLayerShowOrHide"
        enter-active-class="animate__backInRight"
        leave-active-class="animate__backOutRight"
        appear
      >
        <switchImagerLayer v-show="switchImagerLayer" />
      </transition>
 
      <img
        class="swichImg"
        @click="switchImagerLayerShowOrHide"
        :src="switchImage"
      />
      <div class="bgbox">
        <img
          class="swichImg"
          @click="switchImagerLayerShowOrHide"
          src="@/assets/img/new/shiliang.png"
        />
        <img
          class="swichImg bgbox"
          @click="switchImagerLayerShowOrHide"
          src="@/assets/img/new/shiliang.png"
        />
      </div>
    </div>
  </div>
</template>
 
<script>
import common from "@/components/common";
import layerTreeTwoScreen from "@/components/left/layerTreeTwoScreen";
import switchImagerLayer from "@/components/right/switchImagerLayer";
import { mapState, mapMutations } from "vuex";
import yingxiang from "@/assets/img/new/yingxiang.png";
import shiliang from "@/assets/img/new/shiliang.png";
import sanwei from "@/assets/img/new/sanwei.png";
import jiejing from "@/assets/img/new/jiejing.png";
import "animate.css";
import Bus from "@tools/Bus";
export default {
  name: "viewer",
  components: {
    switchImagerLayer,
    layerTreeTwoScreen,
  },
  data() {
    return {
      cHeight: "770千米",
      date: "",
      bottomInfo: "",
      hb: "",
      jd: "",
      wd: "",
      switchImage: sanwei,
      switchImagerLayer: false,
      size: "100%",
      scale: "1",
      offset: "0%",
      radio: 3,
    };
  },
  computed: {
    ...mapState(["layerTreeTwoScreen", "cesiumInit"]),
  },
  mounted() {
    this.$nextTick(function () {
      let that = this;
      //*********北京sdk************
      window.sgworld = new SmartEarth.EarthCtrl(
        "sdkContainer",
        {
          StaticFileBaseUrl: "../../../static/CimSDK/",
          // StaticFileBaseUrl: "../../../SW/static/CimSDK/",
        },
        {},
        {},
        () => {
          this.ArcgisImageryLayer();
          //先飞到亦庄行政区
          sgworld.Navigate.flyToPointsInterest({
            destination: Cesium.Cartesian3.fromDegrees(
              116.540659,
              39.744945,
              50000
            ),
            duration: 7, //飞行时间8s
          });
          //再飞到朝林大厦
          setTimeout(() => {
            sgworld.Navigate.flyToPointsInterest({
              destination: Cesium.Cartesian3.fromDegrees(
                116.502368,
                39.791361,
                5000
              ),
              duration: 5, //飞行时间8s
            });
          }, 8000);
          setTimeout(() => {
            sgworld.Navigate.flyToPointsInterest({
              destination: Cesium.Cartesian3.fromDegrees(
                116.502368,
                39.791361,
                225.59
              ),
              orientation: {
                heading: Cesium.Math.toRadians(328.5),
                pitch: Cesium.Math.toRadians(-27.5),
                roll: Cesium.Math.toRadians(0.0),
              },
              duration: 5, //飞行时间8s
            });
          }, 14000);
          that.setCesiumInit(true);
        }
      );
      window.Viewer = sgworld._Viewer;
      window.sgwfs = new SmartEarth.WFSTool(sgworld._Viewer);
      Viewer.shadows = false;
      //深度检测
      sgworld.Analysis.depthTestAgainstTerrain(true);
      //地下模式距离参数
      // Viewer.scene.screenSpaceCameraController.enableCollisionDetection = false;
      Viewer.scene.globe.translucency.frontFaceAlpha = 0.5;
      Viewer.scene.globe.undergroundColor = undefined;
      //开启编辑并启用属性弹窗
      sgworld.Creator.SimpleGraphic.setEdit(true, {
        editProp: true,
        editPropData: {
          offset: "r",
          height: "60%",
        },
        callBack: {
          delete: function (entity) {
            Bus.$emit("removeTreeNode", entity);
          },
          end: function (entity) {
            if (entity) {
              let style = sgworld.Creator.SimpleGraphic.getStyle(entity);
              let data = {
                name: entity.name,
                style: style,
              };
              Bus.$emit("updataTreeNode", entity.id, data);
            }
          },
        },
      });
      //标会编辑
      // sgworld.Creator.SimpleGraphic.setEdit(true, {
      // editProp: true,
      // editPropData: {
      //   offset: ["5%", Viewer.container.offsetWidth - 360 - 200 + "px"],
      //   // offset: ["5%", Viewer.container.offsetWidth - 360 - 110 + "px"],
      // height: 650,
      //   success(layero, index) {
      //     let contentWindow = layero.find("iframe")[0].contentWindow;
      //     let layeroHeight = layero.height();
      //     let titleHeight = layero.find(".layui-layer-title").height();
      //     let htmlHeight =
      //       contentWindow.document.firstElementChild.offsetHeight;
      //     if (layeroHeight > titleHeight + htmlHeight) {
      //       layero.height(titleHeight + htmlHeight);
      //       layero.find("iframe").height(htmlHeight);
      //     }
      //   },
      // },
      // });
      //军标编辑
      sgworld.Creator.MilitaryPlotting.setEdit(true, {
        editProp: true,
        editPropData: {
          offset: ["5%", Viewer.container.offsetWidth - 360 - 110 + "px"],
          height: 650,
          success(layero, index) {
            let contentWindow = layero.find("iframe")[0].contentWindow;
            let layeroHeight = layero.height();
            let titleHeight = layero.find(".layui-layer-title").height();
            let htmlHeight =
              contentWindow.document.firstElementChild.offsetHeight;
            if (layeroHeight >= titleHeight + htmlHeight) {
              layero.height(titleHeight + htmlHeight);
            }
          },
        },
      });
      //初始化弹窗事件
      that.initLayerOpen();
      that.showBottom();
    });
    let size = this.detectZoom();
    this.scale = (100 / size).toFixed(2);
    this.offset = "-" + ((size - 100) / 2).toFixed(2) + "%";
    this.size = size + "%";
  },
  methods: {
    ...mapMutations(["setCesiumInit", "updataTreeNode"]),
    detectZoom() {
      var ratio = 0,
        screen = window.screen,
        ua = navigator.userAgent.toLowerCase();
      if (window.devicePixelRatio !== undefined) {
        ratio = window.devicePixelRatio;
      } else if (~ua.indexOf("msie")) {
        if (screen.deviceXDPI && screen.logicalXDPI) {
          ratio = screen.deviceXDPI / screen.logicalXDPI;
        }
      } else if (
        window.outerWidth !== undefined &&
        window.innerWidth !== undefined
      ) {
        ratio = window.outerWidth / window.innerWidth;
      }
 
      if (ratio) {
        ratio = Math.round(ratio * 100);
      }
      // ratio 就是获取到的百分比
      //console.log(ratio);
      return ratio;
      //this.onresize_height = ratio;
      // return ratio;
    },
    changeImage(val) {
      switch (val) {
        case "1":
          this.switchImage = yingxiang;
          break;
        case "2":
          this.switchImage = shiliang;
          break;
        case "3":
          this.switchImage = sanwei;
          break;
        case "4":
          this.switchImage = jiejing;
          break;
      }
    },
    switchImagerLayerShowOrHide() {
      this.switchImagerLayer = !this.switchImagerLayer;
    },
    ArcgisImageryLayer() {
      var layer = sgworld.factory.createImageryLayer({
        sourceType: "arcgis",
        url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer",
      });
    },
    //初始化弹窗事件
 
    initLayerOpen() {
      window.layerOpen = function (name, options) {
        layuiLayer.close(SmartEarthPopupData.layerProp);
 
        let width = options.width;
        let height = options.height;
        let fn = options.fn || {};
 
        //获取相关回调事件
        let cancelFn = null;
        let successFn = null;
        let endFn = null;
        for (let key in fn) {
          cancelFn = key == "cancel" ? fn[key] : cancelFn;
          successFn = key == "success" ? fn[key] : successFn;
          endFn = key == "end" ? fn[key] : endFn;
        }
 
        SmartEarthPopupData.layerProp = layuiLayer.open({
          title: name,
          skin: "other-class",
          type: 2, //0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层)
          shade: 0,
          shadeClose: true,
          resize: false,
          offset: options.offset || undefined,
          area: [
            typeof width === "number" ? width + "px" : width,
            typeof height === "number" ? height + "px" : height,
          ],
          content: options.url,
          success: function (layero, index) {
            layero.css({
              "border-radius": "8px",
            });
            if (successFn && typeof successFn === "function") {
              successFn(layero, index);
            }
          },
          cancel: function () {
            if (cancelFn && typeof cancelFn === "function") {
              cancelFn();
            }
          },
          end: function () {
            if (endFn && typeof endFn === "function") {
              endFn();
            }
          },
        });
      };
    },
    //地图底部工具栏显示地图坐标信息
    showBottom() {
      this.bottomInfo =
        "<div style='color: #FFFFFF;float: left;height: 28px;line-height: 28px;'></div>";
 
      let handler3D = new Cesium.ScreenSpaceEventHandler(Viewer.scene.canvas);
      handler3D.setInputAction((wheelment) => {
        // 滚动滚轴,得到当前的视点高度
        // 单位换算,当大于1000米的时候显示“千米”,小于1000米的时候显示单位为“米”
        var cHeightM = Viewer.camera.positionCartographic.height;
        var cHeightKm = (cHeightM / 1000).toFixed(0);
        if (cHeightKm > 1) {
          this.cHeight = cHeightKm + "千米";
        } else {
          this.cHeight = cHeightM.toFixed(0) + "米";
        }
        // 当cHeight的值改变时,赋值给window中的sdHeight
        window.sdHeight = this.cHeight;
        this.bottomInfo =
          "<div style='color: #FFFFFF;float: left;height: 28px;line-height: 28px;'></div>" +
          "<span id='cd_label' style='font-size:13px;text-align:center;font-family:微软雅黑;color:#FFFFFF;float: right;height: 28px;line-height: 28px;'>" +
          "<span style='margin-right:40px'>海拔:" +
          this.hb +
          "米</span>" +
          "<span style='margin-right:40px'>经度:" +
          this.jd +
          "</span>" +
          "<span style='margin-right:40px'>纬度:" +
          this.wd +
          "</span>" +
          "<span style='margin-right:40px'>视点高度:" +
          this.cHeight +
          "</span>" +
          "</span>";
        //当滑动的距离小于5km,取消聚合
        // if (window.dataClustering && window.dataClustering.enabled) {
        if (parseFloat(cHeightKm) < 2) {
          window.dataClustering && (window.dataClustering.enabled = false);
        } else {
          window.dataClustering && (window.dataClustering.enabled = true);
        }
        // }
      }, Cesium.ScreenSpaceEventType.WHEEL);
      // handler3D.setInputAction((movement) => {
      //   if (window.sdHeight == "") {
      //     this.cHeight = "862.1千米";
      //   }
      //   let cartesian = Viewer.scene.pickPosition(movement.endPosition);
      //   if (!cartesian) return;
      //   let degrees = sgworld.Core.toDegrees(cartesian);
      //   if (degrees) {
      //     let height = degrees.height;
      //     //地理坐标(弧度)转经纬度坐标
      //     let point = [degrees.lon, degrees.lat];
      //     this.hb = height.toFixed(0);
      //     this.jd = point[0].toFixed(2);
      //     this.wd = point[1].toFixed(2);
      //     this.bottomInfo =
      //       "<div style='color: #FFFFFF;float: left;height: 28px;line-height: 28px;'></div>" +
      //       "<span id='cd_label' style='font-size:13px;text-align:center;font-family:微软雅黑;color:#FFFFFF;float: right;height: 28px;line-height: 28px;'>" +
      //       "<span style='margin-right:40px'>海拔:" +
      //       this.hb +
      //       "米</span>" +
      //       "<span style='margin-right:40px'>经度:" +
      //       this.jd +
      //       "</span>" +
      //       "<span style='margin-right:40px'>纬度:" +
      //       this.wd +
      //       "</span>" +
      //       "<span style='margin-right:40px'>视点高度:" +
      //       this.cHeight +
      //       "</span>" +
      //       "</span>";
      //   }
      // }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
    },
  },
};
</script>
 
<style scoped>
#bottomInfo {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 28px;
  background: rgba(0, 0, 0, 0.27);
}
 
#distanceLegendDiv {
  display: none !important;
}
 
#switchImagerLayer {
  display: block;
  position: absolute;
  /*bottom: 120px;*/
  bottom: 13px;
  right: 46px;
  /* margin-right: -105px; */
  z-index: 9999;
  border-radius: 10px;
  /* box-shadow: 0px 0px 5px 3px #fff; */
}
 
/* #switchImagerLayer:before {
  content: "";
  position: absolute;
  right: 5px;
  bottom: 10px;
  border: 13px solid rgba(0, 0, 0, 0.5);
  border-top-color: transparent;
  border-left-color: transparent;
}
 
#switchImagerLayer:after {
  content: "";
  width: 5px;
  height: 12px;
  position: absolute;
  right: 8px;
  bottom: 10px;
  border: 2px solid #fff;
  border-top-color: transparent;
  border-left-color: transparent;
  transform: rotate(45deg);
} */
 
.swichImg {
  width: 117px;
  height: 80px;
  border-radius: 10px;
  cursor: pointer;
}
.bgbox {
  position: absolute;
  top: 0;
  left: 8px;
  z-index: -1;
}
.mid {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  right: 20%;
}
</style>