2023西安数博会CIM演示-【前端】-Web
AdaKing88
2023-08-21 bc03b832caa49bbcd2674fe4cae3701b5059bf95
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
<template>
  <div class="home">
    <div id="eye" style="width: 100%; height: 100%"></div>
  </div>
</template>
<script>
import olcsCamera from "../../../utils/olcs/Camera.js";
import olMap from "ol/Map";
import olView from "ol/View";
import olTileLayer from "ol/layer/Tile";
import olXYZ from "ol/source/XYZ";
import { defaults as defaultControls } from "ol/control";
import * as SmartEarth from "../../../../public/CimSDK/index.js"
let Cesium = SmartEarth.Cesium;
 
function intialOlMap() {
  //普通地图
  const tiandituVecLayer = new olTileLayer({
    title: "generalMap",
    source: new olXYZ({
      url: "http://t3.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=daafafd5b7bb42922f10e3d1c06df824",
      crossOrigin: "anonymous",
    }),
    // zIndex: 1,
    visible: true,
  });
  //普通地图标记
  const tiandituCvaLayer = new olTileLayer({
    title: "generalMapZj",
    source: new olXYZ({
      url: "http://t3.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=daafafd5b7bb42922f10e3d1c06df824",
      crossOrigin: "anonymous",
    }),
    visible: true,
  });
  //影像地图
  const tiandituImgLayer = new olTileLayer({
    title: "generalMapImg",
    source: new olXYZ({
      url: "http://t3.tianditu.com/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=fea556436d51919f4a429933897be3c1",
      crossOrigin: "anonymous",
      minimumLevel: 0, // 最小级别
      maximumLevel: 18, // 最大级别
    }),
    visible: true,
  });
  //影像地图标注
  const tiandituCiaLayer = new olTileLayer({
    title: "generalMapImgZj",
    source: new olXYZ({
      url: "http://t3.tianditu.com/DataServer?T=cia_w&x={x}&y={y}&l={z}&tk=fea556436d51919f4a429933897be3c1",
      crossOrigin: "anonymous",
    }),
    visible: true,
  });
  return new olMap({
    target: "eye",
    layers: [
      tiandituImgLayer,
      tiandituCiaLayer,
      tiandituVecLayer,
      tiandituCvaLayer,
    ],
    view: new olView({
      center: [13410926.774433982, 3715530.4937355495],
      zoom: 5,
    }),
    controls: defaultControls({
      zoom: true,
      rotate: false,
      attribution: false,
    }),
  });
}
export default {
  name: "olCesium01",
  data() {
    return {
      _viewer: undefined,
      scene_: undefined,
      view_: undefined,
      camera_: null,
      targetFrameRate_: Number.POSITIVE_INFINITY,
      lastFrameTime_: 0,
      time_: function () {
        return Cesium.JulianDate.now();
      },
      layer: {
        tiandituVecLayer: "",
        tiandituCvaLayer: "",
        tiandituImgLayer: "",
        tiandituCiaLayer: "",
      },
      map: "",
    };
  },
  components: {},
 
  methods: {
    init() {
      let that = this;
      // this.$refs.refCesium.initMap();
      if (sgworld) {
        let viewer = sgworld.Viewer;
        this._viewer = viewer;
        that.scene_ = viewer.scene;
        //渲染铯场景
        that.render_();
        this.addOlMap();
        this.testOlCs();
      }
    },
    addOlMap() {
      var that = this;
      this.map = intialOlMap();
      this.view_ = this.map.getView();
    },
    testOlCs() {
      this.camera_ = new olcsCamera(this._viewer.scene, this.map);
      this.camera_.checkCameraChange();
    },
    /**
     * Render the Cesium scene
     */
    render_() {
      // if a call to `requestAnimationFrame` is pending, cancel it
      if (this.renderId_ !== undefined) {
        cancelAnimationFrame(this.renderId_);
        this.renderId_ = undefined;
      }
 
      this.renderId_ = requestAnimationFrame(this.onAnimationFrame_.bind(this));
    },
 
    /**
     * Callback for `requestAnimationFrame`.
     * @param {number} frameTime The frame time, from `performance.now()`.
     * @private
     */
    onAnimationFrame_(frameTime) {
      this.renderId_ = undefined;
 
      // check if a frame was rendered within the target frame rate
      const interval = 1000.0 / this.targetFrameRate_;
      const delta = frameTime - this.lastFrameTime_;
      if (delta < interval) {
        // too soon, don't render yet
        this.render_();
        return;
      }
 
      // time to render a frame, save the time
      this.lastFrameTime_ = frameTime;
 
      const julianDate = this.time_();
      this.scene_.initializeFrame();
 
      this.scene_.render(julianDate);
      this.camera_.checkCameraChange();
 
      // request the next render call after this one completes to ensure the browser doesn't get backed up
      this.render_();
    },
  },
  created() { },
  computed: {
    _linkage() {  //  计算属性
      return this.$store.state._linkage; //  Vuex 中定义的属性
    }
  },
  watch: {
    _linkage() {
      this.init();  //   需要调用的方法
    }
  },
};
</script>
 
<style scoped  lang="less" >
.home {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}
 
#eye {
  z-index: 999;
}
</style>