cesium_dev_kit 1.0.50 → 1.0.52

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,779 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Analysis = Analysis;
7
- var _echarts = _interopRequireDefault(require("echarts"));
8
- var _Math3d = require("./Math3d");
9
- var _Graphics = require("./Graphics");
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- let Cesium = null;
12
- /**
13
- * @description D3Kit 拓展包
14
- *
15
- * 分析模块
16
- * @param {*} viewer
17
- */
18
- function Analysis(viewer, cesiumGlobal) {
19
- if (viewer) {
20
- Cesium = cesiumGlobal;
21
- this._analysisLayer = new Cesium.CustomDataSource('analysisLayer');
22
- this.$math3d = new _Math3d.Math3d(viewer, cesiumGlobal);
23
- this.$graphics = new _Graphics.Graphics(viewer, cesiumGlobal);
24
- viewer && viewer.dataSources.add(this._analysisLayer);
25
- }
26
- }
27
- Analysis.prototype = {
28
- /**
29
- * 创建通视分析
30
- * @param {*} options
31
- */
32
- createVisibilityAnalysis: function (options) {
33
- options = options || {};
34
- var $this = this;
35
- $this.drawLineGraphics({
36
- type: 'straightLine',
37
- clampToGround: false,
38
- callback: function (line, lineObj) {
39
- var _visibilityAnalysis = new VisibilityAnalysis({
40
- positions: line,
41
- that: $this
42
- });
43
- if ($this._graphicsLayer) $this._graphicsLayer.entities.remove(lineObj);
44
- if (typeof options.callback === 'function') {
45
- options.callback(_visibilityAnalysis);
46
- }
47
- }
48
- });
49
- },
50
- /**
51
- * 创建环视分析
52
- * @param {*} options
53
- */
54
- createLookAroundAnalysis: function (options) {
55
- options = options || {};
56
- if (this._viewer && options) {
57
- var $this = this;
58
- $this.drawCircleGraphics({
59
- callback: function (result, obj) {
60
- $this._drawLayer.entities.remove(obj);
61
- let _lookAroundAnalysis = new LookAroundAnalysis({
62
- that: $this,
63
- radius: result.radius,
64
- center: result.center
65
- });
66
- if (typeof options.callback === 'function') {
67
- options.callback(_lookAroundAnalysis);
68
- }
69
- }
70
- });
71
- }
72
- },
73
- /**
74
- * 创建可视域分析
75
- * @param {*} options
76
- */
77
- createVisualFieldAnalysis: function (options) {
78
- options = options || {};
79
- if (this._viewer && options) {
80
- var $this = this,
81
- _shadowPrimitive = null;
82
- $this.bindHandelEvent({
83
- leftClick: function click(event, _handlers) {
84
- var position = $this._viewer.scene.pickPosition(event.position);
85
- if (!position) return false;
86
- if (!Cesium.defined(_shadowPrimitive)) {
87
- // 创建shadowPrimitve
88
- _shadowPrimitive = new Cesium.Scene.ShadowPrimitive({
89
- scene: $this._viewer.scene,
90
- viewerPosition: position
91
- });
92
- $this._analysisLayer._primitives.add(_shadowPrimitive);
93
- } else {
94
- _handlers.destroy();
95
- _handlers = null;
96
- }
97
- },
98
- mouseMove: function move(event) {
99
- var position = $this._viewer.scene.pickPosition(event.endPosition);
100
- if (!position) return false;
101
- if (_shadowPrimitive) _shadowPrimitive.setPoseByTargetPoint(position);
102
- }
103
- });
104
- }
105
- },
106
- /**
107
- * 地形开挖分析
108
- * @param {*} options
109
- */
110
- createClipPlanAnalysis: function (options) {
111
- options = options || {};
112
- if (this._viewer && options) {
113
- var $this = this;
114
- var _height = options.height || 30,
115
- _splitNum = options.splitNum || 50,
116
- _wallImg = options.wallImg || 'static/data/images/file/excavate_side_min.jpg',
117
- _bottomImg = options.bottomImg || 'static/data/images/file/excavate_bottom_min.jpg';
118
- $this.drawPolygonGraphics({
119
- callback: function (polygon, polygonObj) {
120
- $this._drawLayer.entities.remove(polygonObj);
121
- let terrainClipPlan = new Cesium.Scene.TerrainClipPlan($this._viewer, {
122
- height: _height,
123
- splitNum: _splitNum,
124
- wallImg: _wallImg,
125
- bottomImg: _bottomImg
126
- });
127
- const cartesian3Coor = $this.transformWGS84ArrayToCartesianArray(polygon);
128
- terrainClipPlan.updateData(cartesian3Coor);
129
- if (typeof options.callback === 'function') {
130
- options.callback(terrainClipPlan);
131
- }
132
- }
133
- });
134
- }
135
- },
136
- /**
137
- * 创建淹没分析
138
- * @param {*} options
139
- */
140
- createSubmergedAnalysis: function (options) {
141
- options = options || {};
142
- if (this._viewer && options) {
143
- var $this = this,
144
- _maxH = options.maxH || 15,
145
- _speed = options.speed || 1,
146
- _interval = options.interval || 10;
147
- $this.drawPolygonGraphics({
148
- height: 1,
149
- callback: function (polygon, polygonObj) {
150
- if (!$this._viewer.scene.globe.depthTestAgainstTerrain) {
151
- alert('请开启深度检测');
152
- return false;
153
- }
154
- if (polygonObj) {
155
- setTimeout(() => {
156
- polygonObj.polygon.heightReference = 'CLAMP_TO_GROUND';
157
- polygonObj.polygon.material = 'static/data/images/file/water.png';
158
- var h = 0.0;
159
- polygonObj.polygon.extrudedHeight = h;
160
- var st = setInterval(function () {
161
- h = h + _speed;
162
- if (h >= _maxH) {
163
- h = _maxH;
164
- clearTimeout(st);
165
- }
166
- polygonObj.polygon.extrudedHeight = h;
167
- }, _interval);
168
- }, 2000);
169
- }
170
- }
171
- });
172
- }
173
- },
174
- /**
175
- * 创建坡度分析
176
- * @param {*} options
177
- */
178
- createSlopeAnalysis: function (options) {
179
- options = options || {};
180
- if (!_echarts.default) {
181
- alert('需要引入echarts库');
182
- return false;
183
- }
184
- var $this = this;
185
- if (this._viewer && options) {
186
- $this.drawLineGraphics({
187
- type: 'straightLine',
188
- clampToGround: false,
189
- callback: function (line, lineObj) {
190
- var _slopeAnalysis = new SlopeAnalysis({
191
- positions: line,
192
- that: $this
193
- });
194
- if ($this._graphicsLayer) $this._graphicsLayer.entities.remove(lineObj);
195
- if (typeof options.callback === 'function') {
196
- options.callback(_slopeAnalysis);
197
- }
198
- }
199
- });
200
- }
201
- },
202
- /**
203
- * 方量分析
204
- * @param {*} options
205
- */
206
- createCutVolumeAnalysis: function (options) {
207
- options = options || {};
208
- if (this._viewer && options) {
209
- var $this = this;
210
- $this.drawWallGraphics({
211
- callback: function (wall) {
212
- var _cutVolumeAnalysis = new CutVolumeAnalysis({
213
- positions: $this.transformWGS84ArrayToCartesianArray(wall, 100),
214
- that: $this
215
- });
216
- if (typeof options.callback === 'function') {
217
- options.callback(_cutVolumeAnalysis);
218
- }
219
- }
220
- });
221
- }
222
- }
223
- };
224
-
225
- /**
226
- * 通视分析
227
- * @param {*} params
228
- */
229
- function VisibilityAnalysis(params) {
230
- if (params && params.positions) {
231
- var positions = params.positions,
232
- that = params.that,
233
- points = [],
234
- lines = [],
235
- pickedObjs = [],
236
- position1 = that.transformWGS84ToCartesian(positions[0]),
237
- position2 = that.transformWGS84ToCartesian(positions[1]);
238
- points = that.$graphics.createPointsGraphics({
239
- point: true,
240
- positions: [position1, position2]
241
- });
242
- var results = that.$math3d.getIntersectObj(position1, position2, points, true); //碰撞检测
243
-
244
- if (results.length === 0) {
245
- alert("没有取到相交点 , 请检查是否开启深度检测。");
246
- return false;
247
- }
248
- //显示相交对象 高亮
249
- function showIntersections() {
250
- for (let i = 0; i < results.length; ++i) {
251
- var object = results[i].object;
252
- if (object) {
253
- if (object instanceof Cesium.Cesium3DTileFeature) {
254
- pickedObjs.push(object);
255
- object.oldColor = object.color.clone();
256
- object.color = Cesium.Color.fromAlpha(Cesium.Color.YELLOW, object.color.alpha);
257
- } else if (object.id instanceof Cesium.Entity) {
258
- var entity = object.id,
259
- checkEntity = entity.polygon || entity.polyline;
260
- ;
261
- pickedObjs.push(entity);
262
- var color = checkEntity.material.color.getValue();
263
- checkEntity.oldColor = color.clone();
264
- checkEntity.material = Cesium.Color.fromAlpha(Cesium.Color.YELLOW, color.alpha);
265
- }
266
- }
267
- //相交点
268
- points.push(that._analysisLayer.entities.add({
269
- position: results[i].position,
270
- ellipsoid: {
271
- radii: new Cesium.Cartesian3(0.8, 0.8, 0.8),
272
- material: Cesium.Color.RED
273
- }
274
- }));
275
- }
276
- }
277
- // 计算分析结果
278
- function computesResult() {
279
- //分析一下是否都有position
280
- for (let index = results.length - 1; index >= 0; index--) {
281
- const element = results[index];
282
- if (!Cesium.defined(element.position)) {
283
- results.splice(index, 1);
284
- }
285
- }
286
- if (!Cesium.defined(results[0].position)) {
287
- throw new Cesium.DeveloperError("position is undefined");
288
- }
289
- var pickPos1 = results[0].position;
290
- var dis = Cesium.Cartesian3.distance(pickPos1, position2);
291
- var bVisibility = dis < 5 ? true : false; //
292
- var arrowPositions = [position1, results[0].position];
293
- //通视线
294
- var greenLine = that._analysisLayer.entities.add({
295
- polyline: {
296
- positions: arrowPositions,
297
- width: 10,
298
- arcType: Cesium.ArcType.NONE,
299
- material: new Cesium.PolylineArrowMaterialProperty(Cesium.Color.GREEN)
300
- }
301
- });
302
- lines.push(greenLine);
303
- //不通视
304
- if (!bVisibility) {
305
- var unArrowPositions = [results[0].position, position2];
306
- var redLine = that._analysisLayer.entities.add({
307
- polyline: {
308
- positions: unArrowPositions,
309
- width: 10,
310
- arcType: Cesium.ArcType.NONE,
311
- material: new Cesium.PolylineArrowMaterialProperty(Cesium.Color.RED)
312
- }
313
- });
314
- lines.push(redLine);
315
- }
316
- showIntersections();
317
- var rad1 = Cesium.Cartographic.fromCartesian(position1);
318
- var rad2 = Cesium.Cartographic.fromCartesian(position2);
319
- var degree1 = {
320
- longitude: rad1.longitude / Math.PI * 180,
321
- latitude: rad1.latitude / Math.PI * 180,
322
- height: rad1.height
323
- };
324
- var degree2 = {
325
- longitude: rad2.longitude / Math.PI * 180,
326
- latitude: rad2.latitude / Math.PI * 180,
327
- height: rad2.height
328
- };
329
- var length_ping = Math.sqrt(Math.pow(position1.x - position2.x, 2) + Math.pow(position1.y - position2.y, 2) + Math.pow(position1.z - position2.z, 2));
330
- var length_h = Math.abs(degree2.height - degree1.height);
331
- var length = Math.sqrt(Math.pow(length_ping, 2) + Math.pow(length_h, 2));
332
- var visTxt = bVisibility ? '是' : '否';
333
- var text = '起点坐标: ' + (' (' + degree1.longitude.toFixed(6)) + '\u00B0' + ',' + degree1.latitude.toFixed(6) + '\u00B0' + ',' + degree1.height.toFixed(2) + ')' + '\n终点坐标: ' + (' (' + degree2.longitude.toFixed(6)) + '\u00B0' + ',' + degree2.latitude.toFixed(6) + '\u00B0' + ',' + degree2.height.toFixed(2) + ')' + '\n垂直距离: ' + ' ' + length_h.toFixed(2) + 'm' + '\n水平距离: ' + ' ' + length_ping.toFixed(2) + 'm' + '\n空间距离: ' + ' ' + length.toFixed(2) + 'm' + '\n是否可视: ' + ' ' + visTxt;
334
- if (points && points[0]) {
335
- points[0].label = {
336
- text: text,
337
- showBackground: true,
338
- font: '14px monospace',
339
- fillColor: Cesium.Color.YELLOW,
340
- pixelOffset: {
341
- x: 0,
342
- y: -20
343
- },
344
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
345
- horizontalOrigin: Cesium.HorizontalOrigin.LEFT
346
- };
347
- }
348
- }
349
- computesResult(); // 计算相交结果
350
- }
351
-
352
- VisibilityAnalysis.prototype.remove = function () {};
353
- }
354
-
355
- /**
356
- * 环视分析
357
- * @param {*} params
358
- */
359
- function LookAroundAnalysis(params) {
360
- if (!params && !params.center && !params.radius && params.that) {
361
- alert('没有获取到分析参数');
362
- return false;
363
- }
364
- var that = params.that,
365
- $this = this;
366
- if (!that._viewer.scene.globe.depthTestAgainstTerrain) {
367
- alert('请开启深度检测');
368
- return false;
369
- }
370
- var viewHeight = params.viewHeight || 10;
371
- var cartographicCenter = Cesium.Cartographic.fromCartesian(params.center);
372
- // 分析
373
- try {
374
- var ab = params.radius;
375
- var eopt = {};
376
- eopt.semiMinorAxis = ab;
377
- eopt.semiMajorAxis = ab;
378
- eopt.rotation = 0;
379
- eopt.center = params.center;
380
- eopt.granularity = Math.PI / 45.0; //间隔
381
- let ellipse = that.computeEllipseEdgePositions(eopt); //范围当前椭圆位置的数组
382
- for (let i = 0; i < ellipse.outerPositions.length; i += 3) {
383
- //逐条计算可视域
384
- let cartesian = new Cesium.Cartesian3(ellipse.outerPositions[i], ellipse.outerPositions[i + 1], ellipse.outerPositions[i + 2]);
385
- let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
386
- let deltaRadian = 0.00005 * Math.PI / 180.0; //Cesium.Math.RADIANS_PER_DEGREE
387
- let cartographicArr = that.computeInterpolateLineCartographic(cartographicCenter, cartographic, deltaRadian);
388
- that.computeCartographicPointsTerrainData(cartographicArr, function (terrainData) {
389
- if (terrainData.length > 0) {
390
- let preVisible = true;
391
- let cartesiansLine = [];
392
- let colors = [];
393
- for (let j = 1; j < terrainData.length; j++) {
394
- //逐点计算可见性
395
- let visible = true; //该点可见性
396
- if (j > 1) {
397
- let cartographicCenterHV = new Cesium.Cartographic(terrainData[0].longitude, terrainData[0].latitude, terrainData[0].height + viewHeight);
398
- if (preVisible) {
399
- //
400
- let curPoint = that.computeInterpolateIndexLineHeightCartographic(cartographicCenterHV, terrainData[j], j, j - 1);
401
- if (curPoint.height >= terrainData[j - 1].height) {
402
- preVisible = true;
403
- visible = true;
404
- } else {
405
- preVisible = false;
406
- visible = false;
407
- }
408
- } else {
409
- //插值到当前
410
- let curPointArr = that.computeInterpolateIndexLineHeightCartographic(cartographicCenterHV, terrainData[j], j, j - 1);
411
- for (let k = 0; k < curPointArr.length; k++) {
412
- if (curPointArr[k].height >= terrainData[k].height) {
413
- preVisible = true;
414
- visible = true;
415
- } else {
416
- preVisible = false;
417
- visible = false;
418
- break;
419
- }
420
- }
421
- }
422
- }
423
- let cartesianTemp = Cesium.Cartesian3.fromRadians(terrainData[j].longitude, terrainData[j].latitude, terrainData[j].height + 1);
424
- cartesiansLine.push(cartesianTemp);
425
- //绘制点
426
- if (visible) {
427
- colors.push(0);
428
- colors.push(0);
429
- colors.push(1);
430
- colors.push(1);
431
- } else {
432
- colors.push(1);
433
- colors.push(0);
434
- colors.push(0);
435
- colors.push(1);
436
- }
437
- }
438
- //绘制结果
439
- $this._pointsKSYResult = new Cesium.Scene.PointsPrimitive({
440
- 'viewer': that._viewer,
441
- 'Cartesians': cartesiansLine,
442
- 'Colors': colors
443
- });
444
- } else {
445
- alert("高程异常!");
446
- }
447
- });
448
- }
449
- } catch (error) {
450
- console.log(error);
451
- }
452
- LookAroundAnalysis.prototype.remove = function () {};
453
- }
454
-
455
- /**
456
- * 坡度分析
457
- * @param {*} params
458
- */
459
- function SlopeAnalysis(params) {
460
- if (params && params.positions) {
461
- var positions = params.positions,
462
- that = params.that,
463
- position1 = that.transformWGS84ToCartesian(positions[0]),
464
- position2 = that.transformWGS84ToCartesian(positions[1]);
465
- //显示结果
466
- function showResult(startPoint, endPoint) {
467
- //起止点相关信息
468
- var scartographic = Cesium.Cartographic.fromCartesian(startPoint);
469
- var samplePoint = [scartographic];
470
- var pointSum = 10; //取样点个数
471
- var tempCartesians = new Cesium.Cartesian3();
472
- var slopePercent = [0];
473
- var disL = [0];
474
- var angle = 0;
475
- for (var i = 1; i <= pointSum; i++) {
476
- Cesium.Cartesian3.lerp(startPoint, endPoint, i / pointSum, tempCartesians);
477
- var tempCartographic = Cesium.Cartographic.fromCartesian(tempCartesians);
478
- var surfaceHeight = that._viewer.scene.globe.getHeight(tempCartographic);
479
- tempCartographic.height = surfaceHeight;
480
- samplePoint.push(tempCartographic);
481
- var lastCarto = samplePoint[i - 1];
482
- var dis = Cesium.Cartesian3.distance(Cesium.Cartographic.toCartesian(lastCarto), Cesium.Cartographic.toCartesian(tempCartographic));
483
- disL.push(disL[i - 1] + dis);
484
- angle = Math.asin((tempCartographic.height - lastCarto.height) / dis);
485
- slopePercent.push(Math.tan(angle) * 100);
486
- }
487
- var echartContainer = document.createElement('div');
488
- echartContainer.className = 'echart-viewer';
489
- that._viewer.container.appendChild(echartContainer, 'dark', {
490
- renderer: 'canvas',
491
- width: 640,
492
- height: 480
493
- });
494
- echartContainer.style.position = "absolute";
495
- echartContainer.style.left = '20px';
496
- echartContainer.style.bottom = '20px';
497
- echartContainer.style.height = '300px';
498
- echartContainer.style.width = '640px';
499
- echartContainer.style.overflow = "hidden";
500
- echartContainer.style.zIndex = "9999";
501
- echartContainer.style.opacity = 0.9;
502
- var myChart = _echarts.default.init(echartContainer);
503
- var option = {
504
- title: {
505
- text: '剖面示意图',
506
- left: 'center',
507
- subtext: '',
508
- textStyle: {
509
- color: 'white',
510
- fontSize: 15
511
- }
512
- },
513
- tooltip: {
514
- trigger: 'axis'
515
- },
516
- legend: {
517
- data: ['']
518
- },
519
- //右上角工具条
520
- toolbox: {
521
- show: false,
522
- feature: {
523
- mark: {
524
- show: true
525
- },
526
- dataView: {
527
- show: true,
528
- readOnly: false
529
- },
530
- magicType: {
531
- show: true,
532
- type: ['line', 'bar']
533
- },
534
- restore: {
535
- show: true
536
- },
537
- saveAsImage: {
538
- show: true
539
- }
540
- }
541
- },
542
- calculable: true,
543
- xAxis: [{
544
- type: 'category',
545
- name: "长度(米)",
546
- boundaryGap: false,
547
- data: disL,
548
- axisLabel: {
549
- textStyle: {
550
- color: 'white'
551
- }
552
- },
553
- axisLine: {
554
- lineStyle: {
555
- color: "white"
556
- }
557
- }
558
- }],
559
- yAxis: [{
560
- type: 'value',
561
- name: "坡度(%)",
562
- axisLabel: {
563
- formatter: function (data) {
564
- return data.toFixed(2) + "%";
565
- },
566
- // formatter: '{value} 米',
567
- textStyle: {
568
- color: 'white'
569
- }
570
- },
571
- axisLine: {
572
- lineStyle: {
573
- color: "white"
574
- }
575
- }
576
- }],
577
- series: [{
578
- name: '坡度',
579
- type: 'line',
580
- areaStyle: {},
581
- smooth: true,
582
- data: slopePercent,
583
- markPoint: {
584
- data: [{
585
- type: 'max',
586
- name: '最大值'
587
- }, {
588
- type: 'min',
589
- name: '最小值'
590
- }]
591
- },
592
- markLine: {
593
- data: [{
594
- type: 'average',
595
- name: '平均值'
596
- }]
597
- }
598
- }]
599
- };
600
-
601
- // 为echarts对象加载数据
602
- myChart.setOption(option);
603
- return myChart;
604
- }
605
- showResult(position1, position2);
606
- }
607
- }
608
-
609
- /**
610
- * 方量分析
611
- * @param {*} params
612
- */
613
- function CutVolumeAnalysis(params) {
614
- if (params && params.positions && params.that) {
615
- var that = params.that,
616
- positions = params.positions,
617
- _debugShowSubTriangles = true,
618
- $this = this;
619
- computeCutVolume();
620
- }
621
- /**
622
- * 计算多边形的重心点
623
- * @param {*} positions
624
- */
625
- function computeCentroidOfPolygon(positions) {
626
- var x = [];
627
- var y = [];
628
- for (var i = 0; i < positions.length; i++) {
629
- var cartographic = Cesium.Cartographic.fromCartesian(positions[i]);
630
- x.push(cartographic.longitude);
631
- y.push(cartographic.latitude);
632
- }
633
- var x0 = 0.0,
634
- y0 = 0.0,
635
- x1 = 0.0,
636
- y1 = 0.0;
637
- var signedArea = 0.0;
638
- var a = 0.0;
639
- var centroidx = 0.0,
640
- centroidy = 0.0;
641
- for (i = 0; i < positions.length; i++) {
642
- x0 = x[i];
643
- y0 = y[i];
644
- if (i == positions.length - 1) {
645
- x1 = x[0];
646
- y1 = y[0];
647
- } else {
648
- x1 = x[i + 1];
649
- y1 = y[i + 1];
650
- }
651
- a = x0 * y1 - x1 * y0;
652
- signedArea += a;
653
- centroidx += (x0 + x1) * a;
654
- centroidy += (y0 + y1) * a;
655
- }
656
- signedArea *= 0.5;
657
- centroidx /= 6.0 * signedArea;
658
- centroidy /= 6.0 * signedArea;
659
- return new Cesium.Cartographic(centroidx, centroidy);
660
- }
661
-
662
- /**
663
- * 计算三角形的面积
664
- * @param {*} pos1
665
- * @param {*} pos2
666
- * @param {*} pos3
667
- */
668
- function computeAreaOfTriangle(pos1, pos2, pos3) {
669
- var a = Cesium.Cartesian3.distance(pos1, pos2);
670
- var b = Cesium.Cartesian3.distance(pos2, pos3);
671
- var c = Cesium.Cartesian3.distance(pos3, pos1);
672
- var S = (a + b + c) / 2;
673
- return Math.sqrt(S * (S - a) * (S - b) * (S - c));
674
- }
675
- /**
676
- * 计算方量
677
- */
678
- function computeCutVolume() {
679
- var tileAvailability = that._viewer.terrainProvider.availability;
680
- if (!tileAvailability) {
681
- alert("未获取到地形");
682
- return false;
683
- }
684
- var maxLevel = 0;
685
- var minHeight = 15000;
686
- // 计算差值点
687
- for (var i = 0; i < positions.length; i++) {
688
- var cartographic = Cesium.Cartographic.fromCartesian(positions[i]);
689
- var height = that._viewer.scene.globe.getHeight(cartographic);
690
- if (minHeight > height) minHeight = height;
691
- var level = tileAvailability.computeMaximumLevelAtPosition(cartographic);
692
- if (maxLevel < level) maxLevel = level;
693
- }
694
- var granularity = Math.PI / Math.pow(2, 11);
695
- granularity = granularity / 64;
696
- var polygonGeometry = new Cesium.PolygonGeometry.fromPositions({
697
- positions: positions,
698
- vertexFormat: Cesium.PerInstanceColorAppearance.FLAT_VERTEX_FORMAT,
699
- granularity: granularity
700
- });
701
-
702
- //polygon subdivision
703
-
704
- var geom = new Cesium.PolygonGeometry.createGeometry(polygonGeometry);
705
- var totalCutVolume = 0;
706
- var maxHeight = 0;
707
- var i0, i1, i2;
708
- var height1, height2, height3;
709
- var p1, p2, p3;
710
- var bottomP1, bottomP2, bottomP3;
711
- var scratchCartesian = new Cesium.Cartesian3();
712
- var cartographic;
713
- var bottomArea;
714
- var subTrianglePositions;
715
- for (i = 0; i < geom.indices.length; i += 3) {
716
- i0 = geom.indices[i];
717
- i1 = geom.indices[i + 1];
718
- i2 = geom.indices[i + 2];
719
- subTrianglePositions = geom.attributes.position.values;
720
- scratchCartesian.x = subTrianglePositions[i0 * 3];
721
- scratchCartesian.y = subTrianglePositions[i0 * 3 + 1];
722
- scratchCartesian.z = subTrianglePositions[i0 * 3 + 2];
723
- cartographic = Cesium.Cartographic.fromCartesian(scratchCartesian);
724
- height1 = that._viewer.scene.globe.getHeight(cartographic);
725
- p1 = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, height1);
726
- bottomP1 = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0);
727
- if (maxHeight < height1) maxHeight = height1;
728
- scratchCartesian.x = subTrianglePositions[i1 * 3];
729
- scratchCartesian.y = subTrianglePositions[i1 * 3 + 1];
730
- scratchCartesian.z = subTrianglePositions[i1 * 3 + 2];
731
- cartographic = Cesium.Cartographic.fromCartesian(scratchCartesian);
732
- height2 = that._viewer.scene.globe.getHeight(cartographic);
733
- p2 = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, height2);
734
- bottomP2 = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0);
735
- if (maxHeight < height2) maxHeight = height2;
736
- scratchCartesian.x = subTrianglePositions[i2 * 3];
737
- scratchCartesian.y = subTrianglePositions[i2 * 3 + 1];
738
- scratchCartesian.z = subTrianglePositions[i2 * 3 + 2];
739
- cartographic = Cesium.Cartographic.fromCartesian(scratchCartesian);
740
- height3 = that._viewer.scene.globe.getHeight(cartographic);
741
- p3 = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, height3);
742
- bottomP3 = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0);
743
- if (maxHeight < height3) maxHeight = height3;
744
- bottomArea = computeAreaOfTriangle(bottomP1, bottomP2, bottomP3);
745
- totalCutVolume = totalCutVolume + bottomArea * (height1 - minHeight + height2 - minHeight + height3 - minHeight) / 3;
746
- if (_debugShowSubTriangles) {
747
- var positionsarr = [];
748
- positionsarr.push(p1);
749
- positionsarr.push(p2);
750
- positionsarr.push(p3);
751
- var drawingPolygon = {
752
- polygon: {
753
- hierarchy: {
754
- positions: positionsarr
755
- },
756
- extrudedHeight: 0,
757
- perPositionHeight: true,
758
- material: Cesium.Color.fromRandom().withAlpha(0.5),
759
- outline: true,
760
- closeTop: true,
761
- closeBottom: true,
762
- outlineColor: Cesium.Color.WHITE,
763
- outlineWidth: 2
764
- }
765
- };
766
- that._analysisLayer.entities.add(drawingPolygon);
767
- }
768
- }
769
- var centroid = computeCentroidOfPolygon(positions);
770
- $this._volumeLabel = that._analysisLayer.entities.add({
771
- position: Cesium.Cartesian3.fromRadians(centroid.longitude, centroid.latitude, maxHeight + 1000),
772
- label: {
773
- text: 'Cut Volume ' + totalCutVolume.toString() + 'm3'
774
- }
775
- });
776
- return maxHeight;
777
- }
778
- ;
779
- }