cesium_dev_kit 1.0.44 → 1.0.46

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,947 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Control = Control;
7
- var dat = _interopRequireWildcard(require("dat.gui"));
8
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
9
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
10
- let Cesium = null;
11
- let currManualFlag = {};
12
- let pickedObject;
13
- let dragEntity;
14
- let mode = 'move';
15
- let _global_viewer = null;
16
- /**
17
- * 控件模块
18
- * @param {*} viewer
19
- */
20
- function Control(viewer, cesiumGlobal) {
21
- if (viewer) {
22
- this._viewer = viewer;
23
- _global_viewer = viewer;
24
- Cesium = cesiumGlobal;
25
- this._installFileDragDropHandler();
26
- }
27
- }
28
- Control.prototype = {
29
- /**
30
- * 拖拽加载
31
- */
32
- _installFileDragDropHandler() {
33
- function FileDragDropHandler(targetDiv, viewer) {
34
- var dragBox = document.createElement('div');
35
- dragBox.id = 'fileDragDrop';
36
- dragBox.classList.add('filedragdrop');
37
- dragBox.innerHTML = '请将Json文件拖拽到此区域';
38
- this._dragBox = dragBox;
39
- this._viewer = viewer;
40
- this._parentDiv = targetDiv;
41
- targetDiv.appendChild(dragBox);
42
- this.fileDragDropCallBack = undefined;
43
- this.callBackParms = undefined;
44
- }
45
- FileDragDropHandler.prototype.startuploadfile = function () {
46
- var _this = this;
47
- var oBox = _this._dragBox;
48
- var timer = null;
49
- document.ondragover = function () {
50
- clearTimeout(timer);
51
- timer = setTimeout(function () {
52
- // oBox.style.display = 'none';
53
- oBox.innerHTML = '请将文件拖拽到此区域';
54
- }, 200);
55
- // oBox.style.display = 'block';
56
- };
57
- //进入子集的时候 会触发ondragover 频繁触发 不给ondrop机会
58
- oBox.ondragenter = function () {
59
- oBox.innerHTML = '请释放鼠标';
60
- };
61
- oBox.ondragover = function () {
62
- return false;
63
- };
64
- oBox.ondragleave = function () {
65
- oBox.innerHTML = '请将文件拖拽到此区域';
66
- };
67
- oBox.ondrop = function (ev) {
68
- ev.preventDefault();
69
- var oFile = ev.dataTransfer.files[0];
70
- var reader = new FileReader();
71
- reader.readAsText(oFile, 'UTF-8');
72
- //读取成功
73
- reader.onload = function () {
74
- var data = JSON.parse(this.result);
75
- if (_this.fileDragDropCallBack) {
76
- //回调函数,callBackParms为回调函数的参数,需要自己传入,data与_this._viewer不需要传入,但是声明的回调函数中要有该参数
77
- _this.fileDragDropCallBack(_this.callBackParms, data, _this._viewer);
78
- }
79
- };
80
- reader.onloadstart = function () {
81
- //alert('读取开始');
82
- };
83
- reader.onloadend = function () {
84
- // alert('读取结束');
85
- };
86
- reader.onabort = function () {
87
- alert('读取数据中断');
88
- };
89
- reader.onerror = function () {
90
- alert('读取数据失败');
91
- };
92
- return false;
93
- };
94
- };
95
- function FileDragDropMixin(viewer) {
96
- var fileDragDropHandler = new FileDragDropHandler(document.querySelector('.cesium-viewer'), viewer);
97
- Object.defineProperties(viewer, {
98
- fileDragDropMixin: {
99
- get: function () {
100
- return fileDragDropHandler;
101
- }
102
- }
103
- });
104
- }
105
- Cesium.Scene.FileDragDropMixin = FileDragDropMixin;
106
- },
107
- /**
108
- * 加载本地数据
109
- * @param {*} param
110
- */
111
- showLoadDataToScenePanel(param) {
112
- param = param || {};
113
- if (param) {
114
- let gui = new dat.GUI();
115
- let viewer = this._viewer;
116
- let geojson = gui.addFolder('加载数据文件');
117
- let commonUpload = callback => {
118
- let inputUpload = document.createElement('input');
119
- inputUpload.type = 'file';
120
- inputUpload.className = 'datgui_upload';
121
- inputUpload.onchange = function () {
122
- if (typeof callback === 'function' && inputUpload.files.length) {
123
- callback(URL.createObjectURL(inputUpload.files[0]));
124
- }
125
- };
126
- document.getElementsByTagName('body') && document.getElementsByTagName('body')[0].appendChild(inputUpload);
127
- inputUpload.click();
128
- };
129
- let geojsonParam = {
130
- 'point': () => {
131
- commonUpload(fileData => {
132
- var promise = Cesium.GeoJsonDataSource.load(fileData);
133
- promise.then(function (dataSource) {
134
- viewer.dataSources.add(dataSource);
135
- var entities = dataSource.entities.values;
136
- for (var o = 0; o < entities.length; o++) {
137
- var r = entities[o];
138
- r.nameID = o;
139
- r.point = {
140
- color: Cesium.Color.BLUE
141
- };
142
- }
143
- viewer.flyTo(dataSource);
144
- });
145
- });
146
- },
147
- 'polyline': () => {
148
- commonUpload(fileData => {
149
- var promise = Cesium.GeoJsonDataSource.load(fileData);
150
- promise.then(function (dataSource) {
151
- viewer.dataSources.add(dataSource);
152
- var entities = dataSource.entities.values;
153
- for (var o = 0; o < entities.length; o++) {
154
- var r = entities[o];
155
- r.nameID = o;
156
- r.polyline.width = 5;
157
- r.polyline.material = new Cesium.PolylineGlowMaterialProperty({
158
- glowPower: .1,
159
- color: Cesium.Color.ORANGERED.withAlpha(.9)
160
- }), 10;
161
- }
162
- viewer.flyTo(dataSource);
163
- });
164
- });
165
- },
166
- 'polygon': () => {
167
- commonUpload(fileData => {
168
- var promise = Cesium.GeoJsonDataSource.load(fileData);
169
- promise.then(function (dataSource) {
170
- viewer.dataSources.add(dataSource);
171
- var entities = dataSource.entities.values;
172
- for (var o = 0; o < entities.length; o++) {
173
- var r = entities[o];
174
- r.nameID = o;
175
- r.polygon.width = 10;
176
- r.polygon.material = Cesium.Color.BLUE.withAlpha(.9);
177
- }
178
- viewer.flyTo(dataSource);
179
- });
180
- });
181
- },
182
- 'model': () => {
183
- commonUpload(fileData => {
184
- viewer.flyTo(d3kit.createModelGraphics({
185
- position: Cesium.Cartesian3.fromDegrees(120.38105869, 31.10115627),
186
- m_url: fileData
187
- }));
188
- });
189
- },
190
- 'czml': () => {
191
- commonUpload(fileData => {
192
- viewer.flyTo(viewer.dataSources.add(Cesium.CzmlDataSource.load(fileData)));
193
- });
194
- },
195
- '3dtilset': () => {
196
- commonUpload(fileData => {
197
- viewer.flyTo(viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
198
- url: fileData
199
- })));
200
- });
201
- }
202
- };
203
- geojson.add(geojsonParam, 'point');
204
- geojson.add(geojsonParam, 'polyline');
205
- geojson.add(geojsonParam, 'polygon');
206
- geojson.add(geojsonParam, 'model');
207
- geojson.add(geojsonParam, 'czml');
208
- geojson.add(geojsonParam, '3dtilset');
209
- geojson.open();
210
- }
211
- },
212
- /**
213
- * 后处理面板
214
- * @param {*} param
215
- */
216
- showPostProcessStagesPanel(param) {
217
- param = param || {};
218
- let Options = function () {
219
- this.blackAndWhiteShow = false;
220
- this.blackAndWhiteGradations = 5.0;
221
- this.brightnessShow = false;
222
- this.brightnessValue = 0.5;
223
- this.nightVisionShow = false;
224
- this.silhouette = false;
225
- };
226
- let gui = null;
227
- let option = new Options();
228
- // 修改gui原本的位置,如果提供绑定的父元素id<elementId>就将gui domEmelemt append到对应的dom
229
- if (param && param.elementId) {
230
- gui = new dat.GUI({
231
- autoPlace: false
232
- });
233
- var customContainer = document.getElementById(param.elementId);
234
- customContainer.appendChild(gui.domElement);
235
- } else {
236
- gui = new dat.GUI();
237
- }
238
- let viewer = this._viewer;
239
- let stages = viewer.scene.postProcessStages;
240
- let silhouette = stages.add(Cesium.PostProcessStageLibrary.createSilhouetteStage());
241
- let blackAndWhite = stages.add(Cesium.PostProcessStageLibrary.createBlackAndWhiteStage());
242
- let brightness = stages.add(Cesium.PostProcessStageLibrary.createBrightnessStage());
243
- let nightVision = stages.add(Cesium.PostProcessStageLibrary.createNightVisionStage());
244
- //config
245
- silhouette.uniforms.color = param.silhouetteColor || Cesium.Color.YELLOW;
246
- silhouette.enabled = false;
247
- blackAndWhite.enabled = false;
248
- blackAndWhite.uniforms.gradations = 5.0;
249
- brightness.enabled = false;
250
- brightness.uniforms.brightness = 0.5;
251
- nightVision.enabled = false;
252
- gui.add(option, 'blackAndWhiteShow').name('blackAndWhiteShow').onChange(function (value) {
253
- blackAndWhite.enabled = value;
254
- });
255
- gui.add(option, 'blackAndWhiteGradations', 0, 10, 0.1).name('blackAndWhiteGradations').onChange(function (value) {
256
- blackAndWhite.uniforms.gradations = value;
257
- });
258
- gui.add(option, 'brightnessShow').name('brightnessShow').onChange(function (value) {
259
- brightness.enabled = value;
260
- });
261
- gui.add(option, 'brightnessValue', 0, 10, 0.1).name('brightnessValue').onChange(function (value) {
262
- brightness.uniforms.brightness = value;
263
- });
264
- gui.add(option, 'nightVisionShow').name('nightVisionShow').onChange(function (value) {
265
- nightVision.enabled = value;
266
- });
267
- gui.add(option, 'silhouette').name('silhouette').onChange(function (value) {
268
- silhouette.enabled = value;
269
- });
270
- },
271
- /**
272
- * 环境控制
273
- * @param {*}
274
- * {
275
- * elementId:绑定的父元素id
276
- * }
277
- */
278
- showSceneBloomPanel(param) {
279
- let Options = function () {
280
- this.contrast = 128;
281
- this.brightness = -0.3;
282
- this.delta = 1;
283
- this.gamma = 3.5;
284
- this.enabled = false;
285
- this.highDynamicRange = false;
286
- this.shadows = false;
287
- this.glowOnly = false;
288
- this.sigma = 1.0;
289
- this.stepSize = 5.0;
290
- };
291
- let gui = null;
292
- let option = new Options();
293
- // 修改gui原本的位置,如果提供绑定的父元素id<elementId>就将gui domEmelemt append到对应的dom
294
- if (param && param.elementId) {
295
- gui = new dat.GUI({
296
- autoPlace: false
297
- });
298
- var customContainer = document.getElementById(param.elementId);
299
- customContainer.appendChild(gui.domElement);
300
- } else {
301
- gui = new dat.GUI();
302
- }
303
- let viewer = this._viewer;
304
- gui.__closeButton.innerHTML = '收缩面板';
305
- let bloom = viewer.scene.postProcessStages.bloom;
306
- gui.add(option, 'enabled').name('bloom').onChange(function (value) {
307
- bloom.enabled = value;
308
- });
309
- gui.add(option, 'glowOnly').name('发光').onChange(function (value) {
310
- bloom.uniforms.glowOnly = value;
311
- });
312
- gui.add(option, 'enabled').name('启用模糊').onChange(function (value) {
313
- bloom.enabled = value;
314
- });
315
- gui.add(option, 'contrast', -255.0, 255.0, 0.01).name('对比度').onChange(function (value) {
316
- bloom.uniforms.contrast = value;
317
- });
318
- gui.add(option, 'brightness', -1.0, 1.0, 0.01).name('光泽亮度').onChange(function (value) {
319
- bloom.uniforms.brightness = value;
320
- });
321
- gui.add(option, 'delta', 1, 5, 0.01).name('因子').onChange(function (value) {
322
- bloom.uniforms.delta = value;
323
- });
324
- gui.add(option, 'sigma', 1, 10, 0.01).name('sigma').onChange(function (value) {
325
- bloom.uniforms.sigma = value;
326
- });
327
- gui.add(option, 'stepSize', 0.1, 10).name('stepSize').onChange(function (value) {
328
- bloom.uniforms.stepSize = value;
329
- });
330
- gui.add(option, 'shadows').name('启用阴影').onChange(function (value) {
331
- viewer.shadows = value;
332
- });
333
- gui.add(option, 'highDynamicRange').name('高动态范围').onChange(function (value) {
334
- viewer.scene.highDynamicRange = value;
335
- });
336
- gui.add(option, 'gamma', 1, 10, 0.01).name('伽马亮度').onChange(function (value) {
337
- viewer.scene.gamma = value;
338
- });
339
- },
340
- /**
341
- * 矩阵调整面板
342
- * @param {*} primitives
343
- */
344
- showPrimitiveMatrixPanel(param) {
345
- let primitive = param.primitives._delegate || param.primitives,
346
- primitives = param.primitives,
347
- // 全局定义
348
- viewer = this._viewer;
349
-
350
- // eslint-disable-next-line no-unused-vars
351
- const update3dtilesMaxtrix = function (currParam) {
352
- //旋转
353
- let mx = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(currParam.rx));
354
- let my = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(currParam.ry));
355
- let mz = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(currParam.rz));
356
- let rotationX = Cesium.Matrix4.fromRotationTranslation(mx);
357
- let rotationY = Cesium.Matrix4.fromRotationTranslation(my);
358
- let rotationZ = Cesium.Matrix4.fromRotationTranslation(mz);
359
- //平移
360
- let position = Cesium.Cartesian3.fromDegrees(currParam.tx, currParam.ty, currParam.tz);
361
- let m = Cesium.Transforms.eastNorthUpToFixedFrame(position);
362
- let scale = Cesium.Matrix4.fromUniformScale(0.85);
363
- // //缩放
364
- Cesium.Matrix4.multiply(m, scale, m);
365
- //旋转、平移矩阵相乘
366
- Cesium.Matrix4.multiply(m, rotationX, m);
367
- Cesium.Matrix4.multiply(m, rotationY, m);
368
- Cesium.Matrix4.multiply(m, rotationZ, m);
369
- //赋值给tileset
370
- return m;
371
- };
372
- let gui = null;
373
- if (param && param.elementId) {
374
- gui = new dat.GUI({
375
- autoPlace: false
376
- });
377
- var customContainer = document.getElementById(param.elementId);
378
- customContainer.appendChild(gui.domElement);
379
- } else {
380
- gui = new dat.GUI();
381
- }
382
- /* Here is the update */
383
- var resetSliders = function (name, val) {
384
- for (var i = 0; i < gui.__controllers.length; i++) {
385
- if (!gui.__controllers.property == name) {
386
- gui.__controllers[i].setValue(val);
387
- }
388
- }
389
- };
390
- //高度
391
- let heightMatrix = {
392
- height: 100
393
- };
394
- let height = gui.addFolder('离地高度');
395
- height.add(heightMatrix, 'height', 0, 1000, 1).onChange(function (value) {
396
- var boundingSphere = primitives.boundingSphere;
397
- var cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center);
398
- var surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
399
- var offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, value);
400
- var translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
401
- primitives.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
402
- });
403
- height.open();
404
- //缩放矩阵
405
- let scale = gui.addFolder('缩放大小');
406
- let scaleParam = {
407
- 'm+Scale': () => {
408
- primitive.readyPromise.then(data => {
409
- let modelMatrix = data.root.transform;
410
- Cesium.Matrix4.multiplyByUniformScale(modelMatrix, 1.2, modelMatrix);
411
- data.root.transform = modelMatrix;
412
- });
413
- },
414
- 'm-Scale': () => {
415
- primitive.readyPromise.then(data => {
416
- let modelMatrix = data.root.transform;
417
- Cesium.Matrix4.multiplyByUniformScale(modelMatrix, 0.8, modelMatrix);
418
- data.root.transform = modelMatrix;
419
- });
420
- }
421
- };
422
- scale.add(scaleParam, 'm+Scale');
423
- scale.add(scaleParam, 'm-Scale');
424
- scale.open();
425
- let translationMatrix = {
426
- x: 0,
427
- y: 0,
428
- z: 0
429
- };
430
- //平移矩阵
431
- let translationParam = {
432
- 'x+Axis': () => {
433
- translationMatrix.x += 1;
434
- const translation = Cesium.Matrix4.fromTranslation(new Cesium.Cartesian3(20, 0, 0));
435
- Cesium.Matrix4.multiply(primitive.modelMatrix, translation, primitive.modelMatrix);
436
- },
437
- 'x-Axis': () => {
438
- translationMatrix.x -= 1;
439
- const translation = Cesium.Matrix4.fromTranslation(new Cesium.Cartesian3(-20, 0, 0));
440
- Cesium.Matrix4.multiply(primitive.modelMatrix, translation, primitive.modelMatrix);
441
- },
442
- 'y+Axis': () => {
443
- translationMatrix.y += 1;
444
- const translation = Cesium.Matrix4.fromTranslation(new Cesium.Cartesian3(0, 20, 0));
445
- Cesium.Matrix4.multiply(primitive.modelMatrix, translation, primitive.modelMatrix);
446
- },
447
- 'y-Axis': () => {
448
- translationMatrix.y -= 1;
449
- const translation = Cesium.Matrix4.fromTranslation(new Cesium.Cartesian3(0, -20, 0));
450
- Cesium.Matrix4.multiply(primitive.modelMatrix, translation, primitive.modelMatrix);
451
- },
452
- 'z+Axis': () => {
453
- translationMatrix.z += 1;
454
- const translation = Cesium.Matrix4.fromTranslation(new Cesium.Cartesian3(0, 0, 20));
455
- Cesium.Matrix4.multiply(primitive.modelMatrix, translation, primitive.modelMatrix);
456
- },
457
- 'z-Axis': () => {
458
- translationMatrix.z -= 1;
459
- const translation = Cesium.Matrix4.fromTranslation(new Cesium.Cartesian3(0, 0, -20));
460
- Cesium.Matrix4.multiply(primitive.modelMatrix, translation, primitive.modelMatrix);
461
- }
462
- };
463
- let translation = gui.addFolder('矩阵平移');
464
- translation.add(translationParam, 'x+Axis');
465
- translation.add(translationParam, 'x-Axis');
466
- translation.add(translationParam, 'y+Axis');
467
- translation.add(translationParam, 'y-Axis');
468
- translation.add(translationParam, 'z+Axis');
469
- translation.add(translationParam, 'z-Axis');
470
- translation.open();
471
-
472
- //旋转矩阵
473
- let rotationMatrix = {
474
- x: 0,
475
- y: 0,
476
- z: 0
477
- };
478
- let rotationParam = {
479
- 'x+Axis': () => {
480
- rotationMatrix.x += 15;
481
- primitive.readyPromise.then(data => {
482
- const angel = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(rotationMatrix.x));
483
- const rotation = Cesium.Matrix4.fromRotationTranslation(angel);
484
- const m = Cesium.Transforms.eastNorthUpToFixedFrame(data.boundingSphere.center);
485
- Cesium.Matrix4.multiply(m, rotation, m);
486
- // const rotationX = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(rotationMatrix.x)))
487
- // const rotationY = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(rotationMatrix.y)))
488
- // const rotationZ = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(rotationMatrix.z)))
489
- // Cesium.Matrix4.multiply(m, rotationX, m);
490
- // Cesium.Matrix4.multiply(m, rotationY, m);
491
- // Cesium.Matrix4.multiply(m, rotationZ, m);
492
-
493
- data._root.transform = m;
494
- });
495
- },
496
- 'x-Axis': () => {
497
- rotationMatrix.x -= 15;
498
- primitive.readyPromise.then(data => {
499
- const angel = Cesium.Matrix3.fromRotationX(Cesium.Math.toRadians(rotationMatrix.x));
500
- const rotation = Cesium.Matrix4.fromRotationTranslation(angel);
501
- const m = Cesium.Transforms.eastNorthUpToFixedFrame(data.boundingSphere.center);
502
- Cesium.Matrix4.multiply(m, rotation, m);
503
- data._root.transform = m;
504
- });
505
- },
506
- 'y+Axis': () => {
507
- rotationMatrix.y += 15;
508
- primitive.readyPromise.then(data => {
509
- const angel = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(rotationMatrix.y));
510
- const rotation = Cesium.Matrix4.fromRotationTranslation(angel);
511
- const m = Cesium.Transforms.eastNorthUpToFixedFrame(data.boundingSphere.center);
512
- Cesium.Matrix4.multiply(m, rotation, m);
513
- data._root.transform = m;
514
- });
515
- },
516
- 'y-Axis': () => {
517
- rotationMatrix.y -= 15;
518
- primitive.readyPromise.then(data => {
519
- const angel = Cesium.Matrix3.fromRotationY(Cesium.Math.toRadians(rotationMatrix.y));
520
- const rotation = Cesium.Matrix4.fromRotationTranslation(angel);
521
- const m = Cesium.Transforms.eastNorthUpToFixedFrame(data.boundingSphere.center);
522
- Cesium.Matrix4.multiply(m, rotation, m);
523
- data._root.transform = m;
524
- });
525
- },
526
- 'z+Axis': () => {
527
- rotationMatrix.z += 15;
528
- primitive.readyPromise.then(data => {
529
- const angel = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(rotationMatrix.z));
530
- const rotation = Cesium.Matrix4.fromRotationTranslation(angel);
531
- const m = Cesium.Transforms.eastNorthUpToFixedFrame(data.boundingSphere.center);
532
- Cesium.Matrix4.multiply(m, rotation, m);
533
- data._root.transform = m;
534
- });
535
- },
536
- 'z-Axis': () => {
537
- rotationMatrix.z -= 15;
538
- primitive.readyPromise.then(data => {
539
- const angel = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(rotationMatrix.z));
540
- const rotation = Cesium.Matrix4.fromRotationTranslation(angel);
541
- const m = Cesium.Transforms.eastNorthUpToFixedFrame(data.boundingSphere.center);
542
- Cesium.Matrix4.multiply(m, rotation, m);
543
- data._root.transform = m;
544
- });
545
- }
546
- };
547
- let rotation = gui.addFolder('旋转矩阵');
548
- rotation.add(rotationParam, 'x+Axis');
549
- rotation.add(rotationParam, 'x-Axis');
550
- rotation.add(rotationParam, 'y+Axis');
551
- rotation.add(rotationParam, 'y-Axis');
552
- rotation.add(rotationParam, 'z+Axis');
553
- rotation.add(rotationParam, 'z-Axis');
554
- rotation.open();
555
- if (param.cb) {
556
- let getModelInfo = gui.addFolder('获取调整后的模型矩阵');
557
- getModelInfo.add({
558
- 'getModelMaterix': () => {
559
- primitive.readyPromise.then(data => {
560
- let modelTransformMatrix = data.root.transform;
561
- param.cb({
562
- modelTransformMatrix,
563
- modelMatrix: primitives.modelMatrix
564
- });
565
- });
566
- }
567
- }, 'getModelMaterix').name('获取模型矩阵');
568
- getModelInfo.open();
569
- }
570
- gui.__closeButton.innerHTML = '收缩面板';
571
- },
572
- /**
573
- * 图层参数调整
574
- * @param {*} options
575
- */
576
- showLayerParamPanel: function (layer, param) {
577
- if (layer) {
578
- let gui = null;
579
- // 修改gui原本的位置,如果提供绑定的父元素id<elementId>就将gui domEmelemt append到对应的dom
580
- if (param && param.elementId) {
581
- gui = new dat.GUI({
582
- autoPlace: false
583
- });
584
- var customContainer = document.getElementById(param.elementId);
585
- customContainer.appendChild(gui.domElement);
586
- } else {
587
- gui = new dat.GUI();
588
- }
589
- var layerObj = new function () {
590
- this.alpha = layer.alpha;
591
- this.brightness = layer.brightness;
592
- this.contrast = layer.contrast;
593
- this.gamma = layer.gamma;
594
- this.hue = layer.hue;
595
- this.dayAlpha = layer.dayAlpha;
596
- this.nightAlpha = layer.nightAlpha;
597
- this.saturation = layer.saturation;
598
- }();
599
- var layerParam = gui.addFolder('图层调整');
600
- layerParam.add(layerObj, 'alpha', 0, 1, 0.05).name('透明度').onChange(function (value) {
601
- layer.alpha = value;
602
- });
603
- layerParam.add(layerObj, 'brightness', 0, 5, 0.05).name('亮度').onChange(function (value) {
604
- layer.brightness = value;
605
- });
606
- layerParam.add(layerObj, 'contrast', 0, 5, 0.05).name('对比').onChange(function (value) {
607
- layer.contrast = value;
608
- });
609
- layerParam.add(layerObj, 'gamma', 0, 5, 0.05).name('伽马').onChange(function (value) {
610
- layer.gamma = value;
611
- });
612
- layerParam.add(layerObj, 'hue', 0, 5, 0.05).name('色调').onChange(function (value) {
613
- layer.hue = value;
614
- });
615
- layerParam.add(layerObj, 'dayAlpha', 0, 1, 0.05).name('白天透明').onChange(function (value) {
616
- layer.dayAlpha = value;
617
- });
618
- layerParam.add(layerObj, 'nightAlpha', 0, 1, 0.05).name('夜晚透明').onChange(function (value) {
619
- layer.nightAlpha = value;
620
- });
621
- layerParam.add(layerObj, 'saturation', 0, 5, 0.05).name('饱和').onChange(function (value) {
622
- layer.saturation = value;
623
- });
624
- layerParam.open();
625
- }
626
- },
627
- /**
628
- * 图层切换
629
- * @param {*} options
630
- */
631
- showLayerSwitchPanel: function (layers, param) {
632
- if (layers && layers.length) {
633
- let gui = null;
634
- // 修改gui原本的位置,如果提供绑定的父元素id<elementId>就将gui domEmelemt append到对应的dom
635
- if (param && param.elementId) {
636
- gui = new dat.GUI({
637
- autoPlace: false
638
- });
639
- var customContainer = document.getElementById(param.elementId);
640
- customContainer.appendChild(gui.domElement);
641
- } else {
642
- gui = new dat.GUI();
643
- }
644
- // 注意使用for in 会读取到原型上所有可枚举属性,容易引起异常
645
- var layerObj = new function () {
646
- // for (let i in layers) {
647
- // this[layers[i].id] = layers[i].show
648
- // }
649
- layers.forEach(item => {
650
- this[item.id] = item.show;
651
- });
652
- }();
653
- var layerSwitch = gui.addFolder('图层切换');
654
- layers.forEach(item => {
655
- layerSwitch.add(layerObj, item.id).name(item.name).onChange(function (value) {
656
- item.show = value;
657
- });
658
- });
659
- // for (let i in layers) {
660
- // layerSwitch.add(layerObj, layers[i].id).name(layers[i].name).onChange(function (value) {
661
- // layers[i].show = value
662
- // })
663
- // }
664
- var layerAlphaObj = new function () {
665
- // for (let i in layers) {
666
- // this[layers[i].id] = layers[i].alpha
667
- // }
668
- layers.forEach(item => {
669
- this[item.id] = item.alpha;
670
- });
671
- }();
672
- var layerAlpha = gui.addFolder('透明度');
673
- // for (let i in layers) {
674
- // layerAlpha.add(layerAlphaObj, layers[i].id, 0, 1, 0.05).name(layers[i].name).onChange(function (value) {
675
- // layers[i].alpha = value
676
- // })
677
- // }
678
-
679
- layers.forEach(item => {
680
- layerAlpha.add(layerAlphaObj, item.id, 0, 1, 0.05).name(item.name).onChange(function (value) {
681
- item.alpha = value;
682
- });
683
- });
684
- layerSwitch.open();
685
- layerAlpha.open();
686
- }
687
- },
688
- /**
689
- * 场景效果调整面板
690
- * @param {*} opt
691
- */
692
- showSceneEffectEditPanel: function (options) {
693
- options = options || {};
694
- if (dat.GUI && this._viewer.scene.colorCorrection) {
695
- var gui = new dat.GUI(),
696
- viewer = this._viewer;
697
-
698
- /**
699
- * 初始化场景
700
- */
701
- //设置环境光
702
- viewer.scene.lightSource.ambientLightColor = options.ambientLightColor || new Cesium.Color(0.3, 0.3, 0.3, 1);
703
- //开启颜色校正
704
- viewer.scene.colorCorrection.show = options.colorCorrection || false;
705
- viewer.scene.colorCorrection.saturation = options.saturation || 3.1;
706
- viewer.scene.colorCorrection.brightness = options.brightness || 1.8;
707
- viewer.scene.colorCorrection.contrast = options.contrast || 1.2;
708
- viewer.scene.colorCorrection.hue = options.hue || 0;
709
-
710
- //开启泛光和HDR
711
- viewer.scene.bloomEffect.show = options.bloomEffect || false;
712
- viewer.scene.hdrEnabled = options.hdrEnabled || true;
713
- viewer.scene.bloomEffect.threshold = options.threshold || 1;
714
- viewer.scene.bloomEffect.bloomIntensity = options.bloomIntensity || 2;
715
-
716
- /**
717
- * 初始化dat
718
- */
719
- var sceneObj = new function () {
720
- //泛光开关
721
- this.bloomEffectShow = options.bloomEffect || false;
722
- //泛光阈值
723
- this.bloomThreshold = options.threshold || 1;
724
- //泛光强度
725
- this.bloomIntensity = options.bloomIntensity || 2;
726
- //环境光
727
- this.ambientLightColor = options.ambientLightColor || 0.3;
728
- //HDR开关
729
- this.hdrEnabled = options.hdrEnabled || true;
730
- //颜色校正
731
- this.colorCorrectionShow = false;
732
- //饱和度
733
- this.colorCorrectionSaturation = options.saturation || 3.1;
734
- //亮度
735
- this.colorCorrectionBrightness = options.brightness || 1.8;
736
- //对比度
737
- this.colorCorrectionContrast = options.contrast || 1.2;
738
- //色调
739
- this.colorCorrectionHue = options.hue || 0;
740
- }();
741
- var sceneEffect = gui.addFolder('场景效果');
742
- console.log('sceneEffect:', sceneObj);
743
- sceneEffect.add(sceneObj, 'bloomEffectShow').name('泛光开关').onChange(function (value) {
744
- viewer.scene.bloomEffect.show = value;
745
- viewer.scene.bloomEffect.threshold = sceneObj.bloomThreshold;
746
- viewer.scene.bloomEffect.bloomIntensity = sceneObj.bloomIntensity;
747
- });
748
- sceneEffect.add(sceneObj, 'bloomThreshold', 0, 1, 0.1).name('泛光阈值').onChange(function (value) {
749
- viewer.scene.bloomEffect.threshold = value;
750
- });
751
- sceneEffect.add(sceneObj, 'bloomIntensity', 0, 10, 0.1).name('泛光强度').onChange(function (value) {
752
- viewer.scene.bloomEffect.bloomIntensity = value;
753
- });
754
- sceneEffect.add(sceneObj, 'hdrEnabled').name('HDR开关').onChange(function (value) {
755
- viewer.scene.hdrEnabled = value;
756
- });
757
- sceneEffect.add(sceneObj, 'colorCorrectionShow').name('颜色校正').onChange(function (value) {
758
- viewer.scene.colorCorrection.show = value;
759
- });
760
- sceneEffect.add(sceneObj, 'colorCorrectionSaturation', 0, 5, 0.1).name('饱和度').onChange(function (value) {
761
- viewer.scene.colorCorrection.saturation = value;
762
- });
763
- sceneEffect.add(sceneObj, 'colorCorrectionBrightness', 0, 5, 0.1).name('亮度').onChange(function (value) {
764
- viewer.scene.colorCorrection.brightness = value;
765
- });
766
- sceneEffect.add(sceneObj, 'colorCorrectionContrast', 0, 5, 0.1).name('对比度').onChange(function (value) {
767
- viewer.scene.colorCorrection.contrast = value;
768
- });
769
- sceneEffect.add(sceneObj, 'colorCorrectionHue', 0, 5, 0.1).name('色调').onChange(function (value) {
770
- viewer.scene.hdrEnabled = value;
771
- });
772
- sceneEffect.add(sceneObj, 'colorCorrectionHue', 0, 1, 0.1).name('环境光').onChange(function (value) {
773
- viewer.scene.lightSource.ambientLightColor = new Cesium.Color(value, value, value, 1);
774
- });
775
- sceneEffect.open();
776
- }
777
- },
778
- /**
779
- * 位置姿态编辑面板啊
780
- * @param {*} Entity
781
- */
782
- showEntityOrientationEditPanel: function (param = {}) {
783
- if (param.entity) {
784
- let Entity = param.entity;
785
- var gui = new dat.GUI();
786
- // 修改gui原本的位置,如果提供绑定的父元素id<elementId>就将gui domEmelemt append到对应的dom
787
- if (param && param.elementId) {
788
- gui = new dat.GUI({
789
- autoPlace: false
790
- });
791
- var customContainer = document.getElementById(param.elementId);
792
- customContainer.appendChild(gui.domElement);
793
- } else {
794
- gui = new dat.GUI();
795
- }
796
- var OrientationObj = new function () {
797
- this.heading = 360;
798
- this.pitch = 1;
799
- this.roll = 1;
800
- }();
801
- var Orientation = gui.addFolder('实体姿态调整'),
802
- $this = this;
803
- Orientation.add(OrientationObj, 'heading', 0, 360, 1).name('角度').onChange(function (value) {
804
- OrientationObj.heading = value;
805
- let changeOrientation = Cesium.Transforms.headingPitchRollQuaternion(Entity.position.getValue($this._viewer.clock.currentTime), new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(OrientationObj.heading), Cesium.Math.toRadians(OrientationObj.pitch), Cesium.Math.toRadians(OrientationObj.roll)));
806
- Entity.orientation = changeOrientation;
807
- param.cb && param.cb({
808
- orientation: changeOrientation
809
- });
810
- });
811
- Orientation.add(OrientationObj, 'pitch', 0, 360, 1).name('航向').onChange(function (value) {
812
- OrientationObj.pitch = value;
813
- let changeOrientation = Cesium.Transforms.headingPitchRollQuaternion(Entity.position.getValue($this._viewer.clock.currentTime), new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(OrientationObj.heading), Cesium.Math.toRadians(OrientationObj.pitch), Cesium.Math.toRadians(OrientationObj.roll)));
814
- Entity.orientation = changeOrientation;
815
- param.cb && param.cb({
816
- orientation: changeOrientation
817
- });
818
- });
819
- Orientation.add(OrientationObj, 'roll', 0, 360, 1).name('翻转').onChange(function (value) {
820
- OrientationObj.roll = value;
821
- let changeOrientation = Cesium.Transforms.headingPitchRollQuaternion(Entity.position.getValue($this._viewer.clock.currentTime), new Cesium.HeadingPitchRoll(Cesium.Math.toRadians(OrientationObj.heading), Cesium.Math.toRadians(OrientationObj.pitch), Cesium.Math.toRadians(OrientationObj.roll)));
822
- Entity.orientation = changeOrientation;
823
- param.cb && param.cb({
824
- orientation: changeOrientation
825
- });
826
- });
827
- Orientation.open();
828
- }
829
- },
830
- /**
831
- * 定义事件
832
- */
833
- definedMouseEvent({
834
- targetEntity,
835
- ctrlFlag
836
- }) {
837
- dragEntity = targetEntity;
838
- currManualFlag = ctrlFlag;
839
- this.bindHandelEvent({
840
- leftDown: this.defLeftDown,
841
- mouseMove: this.defMouseMove,
842
- mouseWheel: this.defMouseWheel,
843
- leftUp: this.defLeftUp
844
- });
845
- },
846
- defMouseMove(movement) {
847
- if (currManualFlag.leftDown && pickedObject) {
848
- //鼠标在场景中移动的位置
849
- let ray = _global_viewer.camera.getPickRay(movement.endPosition);
850
- //鼠标在移动过程中与三维场景中移动的坐标位置
851
- let cartesian = _global_viewer.scene.globe.pick(ray, _global_viewer.scene);
852
- //改变鼠标样式
853
- document.body.style.cursor = 'pointer';
854
- if (pickedObject && pickedObject.id && mode === "move") {
855
- //获取到物体当前的位置
856
- let currentTime = Cesium.JulianDate.fromDate(new Date());
857
- let positionC3 = dragEntity.position.getValue(currentTime);
858
- let catographic = Cesium.Cartographic.fromCartesian(positionC3);
859
- let height = Number(catographic.height.toFixed(3));
860
- //动态回调改变物体的位置
861
- dragEntity.position = new Cesium.CallbackProperty(() => {
862
- let cartographic = _global_viewer.scene.globe.ellipsoid.cartesianToCartographic(cartesian);
863
- let longitude = Cesium.Math.toDegrees(cartographic.longitude);
864
- let latitude = Cesium.Math.toDegrees(cartographic.latitude);
865
- let position = Cesium.Cartesian3.fromDegrees(longitude, latitude, height);
866
- return position;
867
- }, false);
868
- } else if (pickedObject && pickedObject.id && mode === "rotate") {
869
- let currentTime = Cesium.JulianDate.fromDate(new Date());
870
- let center = dragEntity.position.getValue(currentTime);
871
-
872
- //获取鼠标移动起始位置与地球球面求交的开始位置和结束位置
873
- let start = _global_viewer.scene.camera.pickEllipsoid(movement.startPosition);
874
- let end = _global_viewer.scene.camera.pickEllipsoid(movement.endPosition);
875
-
876
- //计算旋转轴
877
- const vector2 = Cesium.Cartesian3.subtract(center, end, new Cesium.Cartesian3());
878
- //归一化
879
- const normal = Cesium.Cartesian3.normalize(vector2, new Cesium.Cartesian3());
880
-
881
- //计算起始点的旋转角度
882
- let startNormal = Cesium.Cartesian3.subtract(start, center, new Cesium.Cartesian3());
883
- let endNormal = Cesium.Cartesian3.subtract(end, center, new Cesium.Cartesian3());
884
- let angleBetween = Cesium.Cartesian3.angleBetween(startNormal, endNormal);
885
- //旋转因子
886
- const rotate = 100;
887
- //计算出朝向
888
- const quaternion = Cesium.Quaternion.fromAxisAngle(normal, angleBetween * rotate);
889
- dragEntity.orientation = quaternion;
890
- }
891
- }
892
- },
893
- defLeftDown(movement) {
894
- //选中物体
895
- pickedObject = _global_viewer.scene.pick(movement.position);
896
- if (Cesium.defined(pickedObject) && mode) {
897
- //选中
898
- currManualFlag.selected = true;
899
- currManualFlag.leftDown = true;
900
- } else {
901
- currManualFlag.selected = false;
902
- }
903
- },
904
- defMouseWheel(movement) {
905
- if (pickedObject && pickedObject.id && mode === "scale") {
906
- //计算出当前盒子的尺寸
907
- let currentTime = Cesium.JulianDate.fromDate(new Date());
908
- let dimensions = dragEntity.box.dimensions.getValue(currentTime);
909
- //计算缩放因子
910
- let scale = movement > 0 ? 2 : 0.5;
911
- dragEntity.box.dimensions = new Cesium.CallbackProperty(() => {
912
- let cartesian3 = Cesium.Cartesian3.multiplyByScalar(dimensions, scale, new Cesium.Cartesian3());
913
- return cartesian3;
914
- }, false);
915
- }
916
- },
917
- defLeftUp(movement) {
918
- currManualFlag.leftDown = false;
919
- document.body.style.cursor = 'default';
920
- },
921
- /**
922
- * 移动模型
923
- * @param {*} mode
924
- */
925
- manualMoveModel: function (modifyMode) {
926
- mode = modifyMode;
927
- this._viewer.scene.screenSpaceCameraController.enableRotate = false;
928
- this._viewer.scene.screenSpaceCameraController.enableZoom = true;
929
- },
930
- /**
931
- * 旋转模型
932
- * @param {*} mode
933
- */
934
- manualRotateModel: function (modifyMode) {
935
- mode = modifyMode;
936
- this._viewer.scene.screenSpaceCameraController.enableRotate = false;
937
- this._viewer.scene.screenSpaceCameraController.enableZoom = true;
938
- },
939
- /**
940
- * 缩放模型
941
- * @param {*} mode
942
- */
943
- manualScaleModel: function (modifyMode) {
944
- mode = modifyMode;
945
- this._viewer.scene.screenSpaceCameraController.enableZoom = false;
946
- }
947
- };