cesium_dev_kit 1.0.50 → 1.0.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,751 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Plugin = Plugin;
7
- let Cesium = null;
8
- /**
9
- * 外部插件模块
10
- * @param {*} viewer
11
- */
12
- function Plugin(viewer, cesiumGlobal) {
13
- if (viewer) {
14
- this._viewer = viewer;
15
- Cesium = cesiumGlobal;
16
- this._pluginLayer = new Cesium.CustomDataSource('pluginLayer');
17
- viewer && viewer.dataSources.add(this._pluginLayer);
18
- this._installPlugin();
19
- }
20
- }
21
- Plugin.prototype = {
22
- // 安装插件
23
- _installPlugin: function () {
24
- this._installCss3Renderer();
25
- this._installGroundSkyBox();
26
- this._installTerrainClipPlan();
27
- },
28
- /**
29
- * 地形裁剪
30
- */
31
- _installTerrainClipPlan: function () {
32
- function TerrainClipPlan(t, i) {
33
- this.viewer = t, this.options = i || {}, this._positions = i.positions, this._height = this.options.height || 0, this.bottomImg = i.bottomImg, this.wallImg = i.wallImg, this.splitNum = Cesium.defaultValue(i.splitNum, 50), this._positions && this._positions.length > 0 && this.updateData(this._positions);
34
- }
35
- Object.defineProperties(TerrainClipPlan.prototype, {
36
- show: {
37
- get: function () {
38
- return this._show;
39
- },
40
- set: function (e) {
41
- this._show = e, this.viewer.scene.globe.clippingPlanes && (this.viewer.scene.globe.clippingPlanes.enabled = e), this._switchExcavate(e);
42
- }
43
- },
44
- height: {
45
- get: function () {
46
- return this._height;
47
- },
48
- set: function (e) {
49
- this._height = e, this._updateExcavateDepth(e);
50
- }
51
- }
52
- });
53
- TerrainClipPlan.prototype.updateData = function (e) {
54
- // this.clear()
55
- var t = [],
56
- i = e.length - 1,
57
- a = new Cesium.Cartesian3(),
58
- n = Cesium.Cartesian3.subtract(e[0], e[1], a);
59
- n = n.x > 0, this.excavateMinHeight = 9999;
60
- for (var r = 0; r < i; r++) {
61
- var s = (r + 1) % i,
62
- l = Cesium.Cartesian3.midpoint(e[r], e[s], new Cesium.Cartesian3()),
63
- u = Cesium.Cartographic.fromCartesian(e[r]),
64
- c = this.viewer.scene.globe.getHeight(u) || u.height;
65
- c < this.excavateMinHeight && (this.excavateMinHeight = c);
66
- var d,
67
- h = Cesium.Cartesian3.normalize(l, new Cesium.Cartesian3());
68
- d = n ? Cesium.Cartesian3.subtract(e[r], l, new Cesium.Cartesian3()) : Cesium.Cartesian3.subtract(e[s], l, new Cesium.Cartesian3()), d = Cesium.Cartesian3.normalize(d, d);
69
- var f = Cesium.Cartesian3.cross(d, h, new Cesium.Cartesian3());
70
- f = Cesium.Cartesian3.normalize(f, f);
71
- var p = new Cesium.Plane(f, 0),
72
- m = Cesium.Plane.getPointDistance(p, l);
73
- t.push(new Cesium.ClippingPlane(f, m));
74
- }
75
- this.viewer.scene.globe.clippingPlanes = new Cesium.ClippingPlaneCollection({
76
- planes: t,
77
- edgeWidth: 1,
78
- edgeColor: Cesium.Color.WHITE,
79
- enabled: !0
80
- }), this._prepareWell(e), this._createWell(this.wellData);
81
- };
82
- TerrainClipPlan.prototype.clear = function () {
83
- this.viewer.scene.globe.clippingPlanes && (this.viewer.scene.globe.clippingPlanes.enabled = !1, this.viewer.scene.globe.clippingPlanes.removeAll(), this.viewer.scene.globe.clippingPlanes.isDestroyed() || this.viewer.scene.globe.clippingPlanes.destroy()), this.viewer.scene.globe.clippingPlanes = void 0, this.bottomSurface && this.viewer.scene.primitives.remove(this.bottomSurface), this.wellWall && this.viewer.scene.primitives.remove(this.wellWall), delete this.bottomSurface, delete this.wellWall, this.viewer.scene.render();
84
- };
85
- TerrainClipPlan.prototype._prepareWell = function (e) {
86
- var t = this.splitNum,
87
- i = e.length;
88
- if (0 != i) {
89
- for (var a = this.excavateMinHeight - this.height, n = [], r = [], s = [], l = 0; l < i; l++) {
90
- var u = l == i - 1 ? 0 : l + 1,
91
- c = Cesium.Cartographic.fromCartesian(e[l]),
92
- d = Cesium.Cartographic.fromCartesian(e[u]),
93
- h = [c.longitude, c.latitude],
94
- f = [d.longitude, d.latitude];
95
- 0 == l && (s.push(new Cesium.Cartographic(h[0], h[1])), r.push(Cesium.Cartesian3.fromRadians(h[0], h[1], a)), n.push(Cesium.Cartesian3.fromRadians(h[0], h[1], 0)));
96
- for (var p = 1; p <= t; p++) {
97
- var m = Cesium.Math.lerp(h[0], f[0], p / t),
98
- g = Cesium.Math.lerp(h[1], f[1], p / t);
99
- l == i - 1 && p == t || (s.push(new Cesium.Cartographic(m, g)), r.push(Cesium.Cartesian3.fromRadians(m, g, a)), n.push(Cesium.Cartesian3.fromRadians(m, g, 0)));
100
- }
101
- }
102
- this.wellData = {
103
- lerp_pos: s,
104
- bottom_pos: r,
105
- no_height_top: n
106
- };
107
- }
108
- };
109
- TerrainClipPlan.prototype._createWell = function (e) {
110
- if (this.viewer.terrainProvider._layers) {
111
- var t = this;
112
- this._createBottomSurface(e.bottom_pos);
113
- var i = Cesium.sampleTerrainMostDetailed(this.viewer.terrainProvider, e.lerp_pos);
114
- Cesium.when(i, function (i) {
115
- for (var a = i.length, n = [], r = 0; r < a; r++) {
116
- var s = Cesium.Cartesian3.fromRadians(i[r].longitude, i[r].latitude, i[r].height);
117
- n.push(s);
118
- }
119
- t._createWellWall(e.bottom_pos, n);
120
- });
121
- } else {
122
- this._createBottomSurface(e.bottom_pos);
123
- this._createWellWall(e.bottom_pos, e.no_height_top);
124
- }
125
- };
126
- TerrainClipPlan.prototype._getMinHeight = function (e) {
127
- let minHeight = 5000000;
128
- let minPoint = null;
129
- for (let i = 0; i < e.length; i++) {
130
- let height = e[i]['z'];
131
- if (height < minHeight) {
132
- minHeight = height;
133
- minPoint = this._ellipsoidToLonLat(e[i]);
134
- }
135
- }
136
- return minPoint.altitude;
137
- };
138
- TerrainClipPlan.prototype._ellipsoidToLonLat = function (c) {
139
- let ellipsoid = this.viewer.scene.globe.ellipsoid;
140
- let cartesian3 = new Cesium.Cartesian3(c.x, c.y, c.z);
141
- let cartographic = ellipsoid.cartesianToCartographic(cartesian3);
142
- let lat = Cesium.Math.toDegrees(cartographic.latitude);
143
- let lng = Cesium.Math.toDegrees(cartographic.longitude);
144
- let alt = cartographic.height;
145
- return {
146
- longitude: lng,
147
- latitude: lat,
148
- altitude: alt
149
- };
150
- };
151
- TerrainClipPlan.prototype._createBottomSurface = function (e) {
152
- if (e.length) {
153
- let minHeight = this._getMinHeight(e);
154
- let positions = [];
155
- for (let i = 0; i < e.length; i++) {
156
- let p = this._ellipsoidToLonLat(e[i]);
157
- positions.push(p.longitude);
158
- positions.push(p.latitude);
159
- positions.push(minHeight);
160
- }
161
- let polygon = new Cesium.PolygonGeometry({
162
- polygonHierarchy: new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights(positions)),
163
- perPositionHeight: true
164
- });
165
- let geometry = Cesium.PolygonGeometry.createGeometry(polygon);
166
- var i = new Cesium.Material({
167
- fabric: {
168
- type: 'Image',
169
- uniforms: {
170
- image: this.bottomImg
171
- }
172
- }
173
- }),
174
- a = new Cesium.MaterialAppearance({
175
- translucent: !1,
176
- flat: !0,
177
- material: i
178
- });
179
- this.bottomSurface = new Cesium.Primitive({
180
- geometryInstances: new Cesium.GeometryInstance({
181
- geometry: geometry
182
- }),
183
- appearance: a,
184
- asynchronous: !1
185
- }), this.viewer.scene.primitives.add(this.bottomSurface);
186
- }
187
- };
188
- TerrainClipPlan.prototype._createWellWall = function (e, t) {
189
- let minHeight = this._getMinHeight(e);
190
- let maxHeights = [];
191
- let minHeights = [];
192
- for (let i = 0; i < t.length; i++) {
193
- maxHeights.push(this._ellipsoidToLonLat(t[i]).altitude);
194
- minHeights.push(minHeight);
195
- }
196
- let wall = new Cesium.WallGeometry({
197
- positions: t,
198
- maximumHeights: maxHeights,
199
- minimumHeights: minHeights
200
- });
201
- let geometry = Cesium.WallGeometry.createGeometry(wall);
202
- var a = new Cesium.Material({
203
- fabric: {
204
- type: 'Image',
205
- uniforms: {
206
- image: this.wallImg
207
- }
208
- }
209
- }),
210
- n = new Cesium.MaterialAppearance({
211
- translucent: !1,
212
- flat: !0,
213
- material: a
214
- });
215
- this.wellWall = new Cesium.Primitive({
216
- geometryInstances: new Cesium.GeometryInstance({
217
- geometry: geometry,
218
- attributes: {
219
- color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.GREY)
220
- },
221
- id: 'PitWall'
222
- }),
223
- appearance: n,
224
- asynchronous: !1
225
- }), this.viewer.scene.primitives.add(this.wellWall);
226
- };
227
- TerrainClipPlan.prototype._switchExcavate = function (e) {
228
- e ? (this.viewer.scene.globe.material = Cesium.Material.fromType('WaJue'), this.wellWall.show = !0, this.bottomSurface.show = !0) : (this.viewer.scene.globe.material = null, this.wellWall.show = !1, this.bottomSurface.show = !1);
229
- };
230
- TerrainClipPlan.prototype._updateExcavateDepth = function (e) {
231
- this.bottomSurface && this.viewer.scene.primitives.remove(this.bottomSurface), this.wellWall && this.viewer.scene.primitives.remove(this.wellWall);
232
- for (var t = this.wellData.lerp_pos, i = [], a = t.length, n = 0; n < a; n++) i.push(Cesium.Cartesian3.fromRadians(t[n].longitude, t[n].latitude, this.excavateMinHeight - e));
233
- this.wellData.bottom_pos = i, this._createWell(this.wellData), this.viewer.scene.primitives.add(this.bottomSurface), this.viewer.scene.primitives.add(this.wellWall);
234
- };
235
- Cesium.Scene.TerrainClipPlan = TerrainClipPlan;
236
- },
237
- // 灯光扫描插件
238
- buildLightScanGraphics: function (data) {
239
- if (this._viewer && data) {
240
- var $this = this;
241
- //生成 entityCList面--形成圆锥
242
- var createLightScan_entityCList = function (point, data) {
243
- var lon = data.observer[0],
244
- lat = data.observer[1],
245
- h = data.observer[2];
246
- var entityCList = [];
247
- //创建 面
248
- for (var i = 0; i < point.length; i++) {
249
- var hierarchy;
250
- if (i === point.length - 1) {
251
- hierarchy = new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights([lon, lat, h, point[i].x, point[i].y, 0, point[0].x, point[0].y, 0]));
252
- } else {
253
- hierarchy = new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights([lon, lat, h, point[i].x, point[i].y, 0, point[i + 1].x, point[i + 1].y, 0]));
254
- }
255
- var entityC = $this._pluginLayer.entities.add({
256
- name: '三角形',
257
- polygon: {
258
- hierarchy: hierarchy,
259
- outline: false,
260
- perPositionHeight: true,
261
- //允许三角形使用点的高度
262
- material: data.material
263
- }
264
- });
265
- entityCList.push(entityC);
266
- }
267
- return entityCList;
268
- };
269
- /**
270
- * 改变每个面的位置
271
- * @param {*} data
272
- * @param {*} entity
273
- * @param {*} arr
274
- */
275
- var createLightScan_changeOnePosition = function (data, entity, arr) {
276
- var positionList = data.positionList;
277
- var x,
278
- y,
279
- x0,
280
- y0,
281
- X0,
282
- Y0,
283
- n = 0,
284
- a = 0; //x代表差值 x0代表差值等分后的值,X0表示每次回调改变的值。a表示回调的循环窜次数,n表示扫描的坐标个数
285
- function f(i) {
286
- x = positionList[i + 1][0] - positionList[i][0]; //差值
287
- y = positionList[i + 1][1] - positionList[i][1]; //差值
288
- x0 = x / data.number; //将差值等分500份
289
- y0 = y / data.number;
290
- a = 0;
291
- }
292
- f(n);
293
- entity.polygon.hierarchy = new Cesium.CallbackProperty(function () {
294
- //回调函数
295
- if (Math.abs(X0) >= Math.abs(x) && Math.abs(Y0) >= Math.abs(y)) {
296
- //当等分差值大于等于差值的时候 就重新计算差值和等分差值 Math.abs
297
- n = n + 1;
298
- if (n === positionList.length - 1) {
299
- n = 0;
300
- }
301
- arr[0] = arr[0] + X0;
302
- arr[1] = arr[1] + Y0;
303
- arr[2] = arr[2] + X0;
304
- arr[3] = arr[3] + Y0;
305
- f(n); //重新赋值 x y x0 y0
306
- }
307
-
308
- X0 = a * x0; //将差值的等份逐渐递增。直到大于差值 会有精度丢失,所以扩大再加 x0=x0+0.0001
309
- Y0 = a * y0; //将差值的等份逐渐递增。直到大于差值 会有精度丢失,所以扩大再加
310
- a++;
311
- return new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArrayHeights([data.observer[0], data.observer[1], data.observer[2], arr[0] + X0, arr[1] + Y0, 0, arr[2] + X0, arr[3] + Y0, 0]));
312
- }, false);
313
- };
314
-
315
- //生成分割点
316
- var point = $this._getCirclePoints(data.circle[0], data.circle[1], data.circle[2], data.circle[3]); //生成分割点
317
- //生成 entityCList 圆锥
318
- var entityCList = createLightScan_entityCList(point, data); //生成 entityCList 圆锥
319
-
320
- for (var i = 0; i < entityCList.length; i++) {
321
- if (i !== entityCList.length - 1) {
322
- createLightScan_changeOnePosition(data, entityCList[i], [point[i].x, point[i].y, point[i + 1].x, point[i + 1].y]); //中间arr 代表的是点的坐标
323
- } else {
324
- createLightScan_changeOnePosition(data, entityCList[i], [point[i].x, point[i].y, point[0].x, point[0].y]);
325
- }
326
- }
327
- return entityCList;
328
- }
329
- },
330
- // 路径漫游
331
- buildPathRoaming: function (options) {
332
- if (this._viewer && options && options.paths) {
333
- var _paths = options.paths,
334
- _property = new Cesium.SampledPositionProperty(),
335
- _rEntity = this.createGraphics(),
336
- _startTime = new Cesium.JulianDate(),
337
- _stopTime = Cesium.JulianDate.addSeconds(_startTime, _paths[_paths.length - 1].time, new Cesium.JulianDate());
338
- var startTime = options.startTime || _startTime;
339
- var stopTime = options.stopTime || _stopTime;
340
- this._viewer.clock.startTime = startTime.clone(); // 设置始时钟始时间
341
- this._viewer.clock.currentTime = startTime.clone(); // 设置时钟当前时间
342
- this._viewer.clock.stopTime = stopTime.clone(); // 设置始终停止时间
343
- this._viewer.clock.multiplier = options.multiplier || 10; // 时间速率,数字越大时间过的越快
344
- this._viewer.clock.clockRange = options.clockRange || Cesium.ClockRange.CLAMPED; // 循环执行
345
- for (var i = 0; i < _paths.length; i++) {
346
- var cartesian = Cesium.Cartesian3.fromDegrees(_paths[i].lon, _paths[i].lat, _paths[i].alt);
347
- var time = Cesium.JulianDate.addSeconds(startTime, _paths[i].time, new Cesium.JulianDate());
348
- _property.addSample(time, cartesian); // 添加位置,和时间对应
349
- }
350
-
351
- _rEntity.name = options.name || '路径漫游';
352
- _rEntity.availability = new Cesium.TimeIntervalCollection([new Cesium.TimeInterval({
353
- start: startTime,
354
- stop: stopTime
355
- })]); // 和时间轴关联
356
-
357
- _rEntity.position = _property;
358
- _rEntity.orientation = new Cesium.VelocityOrientationProperty(_property); //基于位置移动自动计算方向
359
-
360
- // 添加图形
361
- var polyline = [];
362
- if (options.polyline) {
363
- _rEntity.polyline = {
364
- positions: new Cesium.CallbackProperty(function () {
365
- return polyline;
366
- }, false),
367
- width: 10,
368
- material: new Cesium.PolylineGlowMaterialProperty({
369
- glowPower: 1,
370
- color: Cesium.Color.RED
371
- }),
372
- clampToGround: true
373
- };
374
- }
375
- if (options.model) {
376
- _rEntity.model = this.getModelGraphics(options);
377
- }
378
- if (options.label) {
379
- _rEntity.label = this.getLabelGraphics(options);
380
- }
381
- if (options.billboard) {
382
- _rEntity.billboard = this.getBillboardGraphics(options);
383
- }
384
- return this._viewer.entities.add(_rEntity);
385
- }
386
- },
387
- /**
388
- * 拓展css3的动画 html元素
389
- */
390
- _installCss3Renderer: function () {
391
- /**
392
- * 添加css3 html元素
393
- * @param app
394
- * @param elements
395
- * @param isBackHide
396
- * @constructor
397
- */
398
- if (this._viewer) {
399
- var viewer = this._viewer;
400
- function Css3Renderer(elements, isBackHide) {
401
- this._scratch = new Cesium.Cartesian2();
402
- this._viewer = viewer;
403
- this._scene = viewer.scene, this._camera = viewer.camera;
404
- this._container = null;
405
- this._elements = elements;
406
- this._isBackHide = isBackHide;
407
- this.init();
408
- }
409
- Css3Renderer.prototype.init = function () {
410
- var container = document.createElement('div');
411
- container.className = `ys-css3-container`;
412
- // document.body.appendChild(container)
413
- document.getElementById('info-warp').appendChild(container);
414
- this._container = container;
415
- this._elements.forEach(function (e) {
416
- container.insertAdjacentHTML('beforeend', e.element);
417
- });
418
- var $this = this;
419
- this._scene.preRender.addEventListener(function () {
420
- //
421
- for (var i = 0; i < container.children.length; i++) {
422
- var p = Cesium.Cartesian3.fromDegrees($this._elements[i].position[0], $this._elements[i].position[1], $this._elements[i].position[2] || 0);
423
- var canvasPosition = $this._scene.cartesianToCanvasCoordinates(p, $this._scratch);
424
- if (Cesium.defined(canvasPosition)) {
425
- container.children[i].style.left = parseFloat(canvasPosition.x) + parseFloat($this._elements[i].offset[0]) + 'px';
426
- container.children[i].style.top = parseFloat(canvasPosition.y) + parseFloat($this._elements[i].offset[1]) + 'px';
427
- if ($this._isBackHide) {
428
- var j = $this._camera.position,
429
- n = $this._scene.globe.ellipsoid.cartesianToCartographic(j).height;
430
- if (!(n += 1 * $this._scene.globe.ellipsoid.maximumRadius, Cesium.Cartesian3.distance(j, p) > n)) {
431
- container.children[i].style.display = 'block';
432
- } else {
433
- container.children[i].style.display = 'none';
434
- }
435
- }
436
- }
437
- }
438
- });
439
- };
440
- Css3Renderer.prototype.remove = function (id) {
441
- this._elements = this._elements.filter(function (e) {
442
- e.id !== id;
443
- });
444
- this._container.removeChild(document.getElementById(id));
445
- };
446
- Css3Renderer.prototype.append = function (object) {
447
- this._elements.push(object);
448
- this._container.insertAdjacentHTML('beforeend', object.element);
449
- };
450
- Css3Renderer.prototype.removeEntityLayer = function (id) {
451
- this._viewer.entities.removeById(id + "_1");
452
- this._viewer.entities.removeById(id + "_2");
453
- this._viewer.entities.removeById(id + "_3");
454
- this.remove(id);
455
- };
456
- Css3Renderer.prototype.addEntityLayer = function (object) {
457
- var lon = object.position[0],
458
- lat = object.position[1],
459
- sStartFlog = false,
460
- $this = this,
461
- s1 = 0.001,
462
- s2 = s1,
463
- s3 = s1,
464
- s4 = s1;
465
- setTimeout(function (sStartFlog) {
466
- sStartFlog = true;
467
- }, 300);
468
- var rotation = Cesium.Math.toRadians(30);
469
- var rotation2 = Cesium.Math.toRadians(30);
470
-
471
- //构建entity
472
- var height = object.boxHeight || 300,
473
- heightMax = object.boxHeightMax || 400,
474
- heightDif = object.boxHeightDif || 10;
475
- var goflog = true;
476
- //添加正方体
477
- if (object.boxShow) {
478
- this._viewer.entities.add({
479
- id: object.id + "_1",
480
- name: "立方体盒子",
481
- position: new Cesium.CallbackProperty(function () {
482
- height = height + heightDif;
483
- if (height >= heightMax) {
484
- height = heightMax;
485
- }
486
- return Cesium.Cartesian3.fromDegrees(lon, lat, height / 2);
487
- }, false),
488
- box: {
489
- dimensions: new Cesium.CallbackProperty(function () {
490
- height = height + heightDif;
491
- if (height >= heightMax) {
492
- height = heightMax;
493
- if (goflog) {
494
- //需要增加判断 不然它会一直执行; 导致对div的dom操作 会一直重复
495
- goflog = false;
496
- $this.append(object, true);
497
- }
498
- }
499
- return new Cesium.Cartesian3(object.boxSide || 100, object.boxSide || 100, height);
500
- }, false),
501
- material: object.boxMaterial || Cesium.Color.DEEPSKYBLUE.withAlpha(0.5)
502
- }
503
- });
504
- } else {
505
- // 只要弹出框
506
- setTimeout(function () {
507
- $this.append(object, true);
508
- }, 100);
509
- }
510
- if (object.circleShow) {
511
- object.circleSize = object.circleSize || 120;
512
- //添加底座 一 外环
513
- this._viewer.entities.add({
514
- id: object.id + "_2",
515
- name: "椭圆",
516
- position: Cesium.Cartesian3.fromDegrees(lon, lat),
517
- ellipse: {
518
- // semiMinorAxis : object.circleSize, //直接这个大小 会有一个闪白的材质 因为cesium材质默认是白色 所以我们先将大小设置为0
519
- // semiMajorAxis : object.circleSize,
520
- semiMinorAxis: new Cesium.CallbackProperty(function () {
521
- if (sStartFlog) {
522
- s1 = s1 + object.circleSize / 20;
523
- if (s1 >= object.circleSize) {
524
- s1 = object.circleSize;
525
- }
526
- }
527
- return s1;
528
- }, false),
529
- semiMajorAxis: new Cesium.CallbackProperty(function () {
530
- if (sStartFlog) {
531
- s2 = s2 + object.circleSize / 20;
532
- if (s2 >= object.circleSize) {
533
- s2 = object.circleSize;
534
- }
535
- }
536
- return s2;
537
- }, false),
538
- material: "static/data/images/Textures/circle2.png",
539
- rotation: new Cesium.CallbackProperty(function () {
540
- rotation += 0.05;
541
- return rotation;
542
- }, false),
543
- stRotation: new Cesium.CallbackProperty(function () {
544
- rotation += 0.05;
545
- return rotation;
546
- }, false),
547
- zIndex: 2
548
- }
549
- });
550
- //添加底座二 内环
551
- this._viewer.entities.add({
552
- id: object.id + "_3",
553
- name: "椭圆",
554
- position: Cesium.Cartesian3.fromDegrees(lon, lat),
555
- ellipse: {
556
- semiMinorAxis: new Cesium.CallbackProperty(function () {
557
- if (sStartFlog) {
558
- s3 = s3 + object.circleSize / 20;
559
- if (s3 >= object.circleSize / 2) {
560
- s3 = object.circleSize / 2;
561
- }
562
- }
563
- return s3;
564
- }, false),
565
- semiMajorAxis: new Cesium.CallbackProperty(function () {
566
- if (sStartFlog) {
567
- s4 = s4 + object.circleSize / 20;
568
- if (s4 >= object.circleSize / 2) {
569
- s4 = object.circleSize / 2;
570
- }
571
- }
572
- return s4;
573
- }, false),
574
- material: "static/data/images/Textures/circle1.png",
575
- rotation: new Cesium.CallbackProperty(function () {
576
- rotation2 -= 0.03;
577
- return rotation2;
578
- }, false),
579
- stRotation: new Cesium.CallbackProperty(function () {
580
- rotation2 -= 0.03;
581
- return rotation2;
582
- }, false),
583
- zIndex: 3
584
- }
585
- });
586
- }
587
- };
588
- Cesium.Scene.Css3Renderer = Css3Renderer;
589
- }
590
- },
591
- // 拓展近景天空盒
592
- _installGroundSkyBox: function () {
593
- var BoxGeometry = Cesium.BoxGeometry,
594
- Cartesian3 = Cesium.Cartesian3,
595
- defaultValue = Cesium.defaultValue,
596
- defined = Cesium.defined,
597
- destroyObject = Cesium.destroyObject,
598
- DeveloperError = Cesium.DeveloperError,
599
- GeometryPipeline = Cesium.GeometryPipeline,
600
- Matrix3 = Cesium.Matrix3,
601
- Matrix4 = Cesium.Matrix4,
602
- Transforms = Cesium.Transforms,
603
- VertexFormat = Cesium.VertexFormat,
604
- BufferUsage = Cesium.BufferUsage,
605
- CubeMap = Cesium.CubeMap,
606
- DrawCommand = Cesium.DrawCommand,
607
- loadCubeMap = Cesium.loadCubeMap,
608
- RenderState = Cesium.RenderState,
609
- VertexArray = Cesium.VertexArray,
610
- BlendingState = Cesium.BlendingState,
611
- SceneMode = Cesium.SceneMode,
612
- ShaderProgram = Cesium.ShaderProgram,
613
- ShaderSource = Cesium.ShaderSource;
614
- //片元着色器,直接从源码复制
615
- var SkyBoxFS = 'uniform samplerCube u_cubeMap;\n\
616
- varying vec3 v_texCoord;\n\
617
- void main()\n\
618
- {\n\
619
- vec4 color = textureCube(u_cubeMap, normalize(v_texCoord));\n\
620
- gl_FragColor = vec4(czm_gammaCorrect(color).rgb, czm_morphTime);\n\
621
- }\n\
622
- ';
623
-
624
- //顶点着色器有修改,主要是乘了一个旋转矩阵
625
- var SkyBoxVS = 'attribute vec3 position;\n\
626
- varying vec3 v_texCoord;\n\
627
- uniform mat3 u_rotateMatrix;\n\
628
- void main()\n\
629
- {\n\
630
- vec3 p = czm_viewRotation * u_rotateMatrix * (czm_temeToPseudoFixed * (czm_entireFrustum.y * position));\n\
631
- gl_Position = czm_projection * vec4(p, 1.0);\n\
632
- v_texCoord = position.xyz;\n\
633
- }\n\
634
- ';
635
- /**
636
- * 为了兼容高版本的Cesium,因为新版cesium中getRotation被移除
637
- */
638
- if (!defined(Matrix4.getRotation)) {
639
- Matrix4.getRotation = Matrix4.getMatrix3;
640
- }
641
- function SkyBoxOnGround(options) {
642
- this.sources = options.sources;
643
- this._sources = undefined;
644
- /**
645
- * Determines if the sky box will be shown.
646
- *
647
- * @type {Boolean}
648
- * @default true
649
- */
650
- this.show = defaultValue(options.show, true);
651
- this._command = new DrawCommand({
652
- modelMatrix: Matrix4.clone(Matrix4.IDENTITY),
653
- owner: this
654
- });
655
- this._cubeMap = undefined;
656
- this._attributeLocations = undefined;
657
- this._useHdr = undefined;
658
- }
659
- var skyboxMatrix3 = new Matrix3();
660
- SkyBoxOnGround.prototype.update = function (frameState, useHdr) {
661
- var that = this;
662
- if (!this.show) {
663
- return undefined;
664
- }
665
- if (frameState.mode !== SceneMode.SCENE3D && frameState.mode !== SceneMode.MORPHING) {
666
- return undefined;
667
- }
668
- if (!frameState.passes.render) {
669
- return undefined;
670
- }
671
- var context = frameState.context;
672
- if (this._sources !== this.sources) {
673
- this._sources = this.sources;
674
- var sources = this.sources;
675
- if (!defined(sources.positiveX) || !defined(sources.negativeX) || !defined(sources.positiveY) || !defined(sources.negativeY) || !defined(sources.positiveZ) || !defined(sources.negativeZ)) {
676
- throw new DeveloperError('this.sources is required and must have positiveX, negativeX, positiveY, negativeY, positiveZ, and negativeZ properties.');
677
- }
678
- if (typeof sources.positiveX !== typeof sources.negativeX || typeof sources.positiveX !== typeof sources.positiveY || typeof sources.positiveX !== typeof sources.negativeY || typeof sources.positiveX !== typeof sources.positiveZ || typeof sources.positiveX !== typeof sources.negativeZ) {
679
- throw new DeveloperError('this.sources properties must all be the same type.');
680
- }
681
- if (typeof sources.positiveX === 'string') {
682
- // Given urls for cube-map images. Load them.
683
- loadCubeMap(context, this._sources).then(function (cubeMap) {
684
- that._cubeMap = that._cubeMap && that._cubeMap.destroy();
685
- that._cubeMap = cubeMap;
686
- });
687
- } else {
688
- this._cubeMap = this._cubeMap && this._cubeMap.destroy();
689
- this._cubeMap = new CubeMap({
690
- context: context,
691
- source: sources
692
- });
693
- }
694
- }
695
- var command = this._command;
696
- command.modelMatrix = Transforms.eastNorthUpToFixedFrame(frameState.camera._positionWC);
697
- if (!defined(command.vertexArray)) {
698
- command.uniformMap = {
699
- u_cubeMap: function () {
700
- return that._cubeMap;
701
- },
702
- u_rotateMatrix: function () {
703
- return Matrix4.getRotation(command.modelMatrix, skyboxMatrix3);
704
- }
705
- };
706
- var geometry = BoxGeometry.createGeometry(BoxGeometry.fromDimensions({
707
- dimensions: new Cartesian3(2.0, 2.0, 2.0),
708
- vertexFormat: VertexFormat.POSITION_ONLY
709
- }));
710
- var attributeLocations = this._attributeLocations = GeometryPipeline.createAttributeLocations(geometry);
711
- command.vertexArray = VertexArray.fromGeometry({
712
- context: context,
713
- geometry: geometry,
714
- attributeLocations: attributeLocations,
715
- bufferUsage: BufferUsage._DRAW
716
- });
717
- command.renderState = RenderState.fromCache({
718
- blending: BlendingState.ALPHA_BLEND
719
- });
720
- }
721
- if (!defined(command.shaderProgram) || this._useHdr !== useHdr) {
722
- var fs = new ShaderSource({
723
- defines: [useHdr ? 'HDR' : ''],
724
- sources: [SkyBoxFS]
725
- });
726
- command.shaderProgram = ShaderProgram.fromCache({
727
- context: context,
728
- vertexShaderSource: SkyBoxVS,
729
- fragmentShaderSource: fs,
730
- attributeLocations: this._attributeLocations
731
- });
732
- this._useHdr = useHdr;
733
- }
734
- if (!defined(this._cubeMap)) {
735
- return undefined;
736
- }
737
- return command;
738
- };
739
- SkyBoxOnGround.prototype.isDestroyed = function () {
740
- return false;
741
- };
742
- SkyBoxOnGround.prototype.destroy = function () {
743
- var command = this._command;
744
- command.vertexArray = command.vertexArray && command.vertexArray.destroy();
745
- command.shaderProgram = command.shaderProgram && command.shaderProgram.destroy();
746
- this._cubeMap = this._cubeMap && this._cubeMap.destroy();
747
- return destroyObject(this);
748
- };
749
- Cesium.Scene.GroundSkyBox = SkyBoxOnGround;
750
- }
751
- };