deeptwins-engine-3d 0.1.69 → 0.1.71

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.
Files changed (41) hide show
  1. package/dist/assets/Build/DeepTwins/Image/fire.png +0 -0
  2. package/dist/assets/Build/DeepTwins/Image/fountain.png +0 -0
  3. package/dist/assets/Build/DeepTwins/Image/smoke.png +0 -0
  4. package/dist/esm/analyze/LineOfSightAnalysis.d.ts +44 -0
  5. package/dist/esm/analyze/LineOfSightAnalysis.js +326 -0
  6. package/dist/esm/analyze/TerrainExcavationAnalysis.d.ts +59 -0
  7. package/dist/esm/analyze/TerrainExcavationAnalysis.js +612 -0
  8. package/dist/esm/constant.d.ts +88 -0
  9. package/dist/esm/constant.js +132 -0
  10. package/dist/esm/drawCommand/viewShed/RectangularSensorPrimitive.d.ts +3 -0
  11. package/dist/esm/drawCommand/viewShed/RectangularSensorPrimitive.js +56 -21
  12. package/dist/esm/drawCommand/viewShed/config.d.ts +2 -2
  13. package/dist/esm/drawCommand/viewShed/config.js +2 -2
  14. package/dist/esm/drawer/index.d.ts +1 -1
  15. package/dist/esm/graphicLayer/BaseSource.d.ts +1 -1
  16. package/dist/esm/index.d.ts +15 -0
  17. package/dist/esm/index.js +24 -2
  18. package/dist/esm/map/Map.d.ts +1 -0
  19. package/dist/esm/map/Map.js +18 -0
  20. package/dist/esm/particle/BaseParticle.d.ts +61 -0
  21. package/dist/esm/particle/BaseParticle.js +196 -0
  22. package/dist/esm/particle/FireParticle.d.ts +8 -0
  23. package/dist/esm/particle/FireParticle.js +65 -0
  24. package/dist/esm/particle/FountainParticle.d.ts +10 -0
  25. package/dist/esm/particle/FountainParticle.js +80 -0
  26. package/dist/esm/particle/SmokeParticle.d.ts +8 -0
  27. package/dist/esm/particle/SmokeParticle.js +65 -0
  28. package/dist/esm/particle/common.d.ts +18 -0
  29. package/dist/esm/particle/common.js +23 -0
  30. package/dist/esm/particle/index.d.ts +5 -0
  31. package/dist/esm/particle/index.js +5 -0
  32. package/dist/esm/tileLayer/CustomRasterLayer.d.ts +188 -0
  33. package/dist/esm/tileLayer/CustomRasterLayer.js +776 -0
  34. package/dist/esm/visualization/DynamicWater.d.ts +39 -0
  35. package/dist/esm/visualization/DynamicWater.js +289 -0
  36. package/dist/esm/visualization/MigrationEffect.d.ts +36 -0
  37. package/dist/esm/visualization/MigrationEffect.js +397 -0
  38. package/dist/esm/visualization/RadarScan.d.ts +39 -0
  39. package/dist/esm/visualization/RadarScan.js +333 -0
  40. package/dist/umd/deeptwins-engine-3d.min.js +1 -1
  41. package/package.json +4 -2
@@ -0,0 +1,612 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
9
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
13
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
14
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
16
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
17
+ import * as Cesium from 'deeptwins-cesium';
18
+ import { merge } from 'lodash';
19
+ import { DEFAULT_TERRAIN_EXCAVATION_ANALYSIS_OPTIONS } from "../constant";
20
+ import * as utils from "../tool/utils";
21
+ // 地形开挖分析
22
+ var TerrainExcavationAnalysis = /*#__PURE__*/function () {
23
+ function TerrainExcavationAnalysis(map, extent) {
24
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
25
+ _classCallCheck(this, TerrainExcavationAnalysis);
26
+ _defineProperty(this, "_mapContext", void 0);
27
+ _defineProperty(this, "options", void 0);
28
+ _defineProperty(this, "isDestroyed", false);
29
+ _defineProperty(this, "extent", void 0);
30
+ _defineProperty(this, "_bottomLayer", null);
31
+ _defineProperty(this, "_wallLayer", null);
32
+ _defineProperty(this, "_edgeLayer", null);
33
+ _defineProperty(this, "_clippingPlanes", null);
34
+ _defineProperty(this, "_previousClippingPlanes", null);
35
+ _defineProperty(this, "_result", null);
36
+ _defineProperty(this, "_createToken", 0);
37
+ this._mapContext = map._mapContext;
38
+ this.extent = extent;
39
+ this.options = merge(DEFAULT_TERRAIN_EXCAVATION_ANALYSIS_OPTIONS(), options);
40
+ this._replaceNullableOptions(options);
41
+ }
42
+
43
+ // 是否能进行操作
44
+ _createClass(TerrainExcavationAnalysis, [{
45
+ key: "_canOperate",
46
+ value: function _canOperate() {
47
+ if (this.isDestroyed) {
48
+ utils.error('TerrainExcavationAnalysis实例已销毁');
49
+ return false;
50
+ }
51
+ return true;
52
+ }
53
+ }, {
54
+ key: "_replaceNullableOptions",
55
+ value: function _replaceNullableOptions() {
56
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
57
+ if (Object.prototype.hasOwnProperty.call(options, 'bottomHeight')) {
58
+ this.options.bottomHeight = options.bottomHeight;
59
+ }
60
+ }
61
+ }, {
62
+ key: "_toFiniteNumber",
63
+ value: function _toFiniteNumber(value) {
64
+ var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
65
+ var number = Number(value);
66
+ return Number.isFinite(number) ? number : fallback;
67
+ }
68
+ }, {
69
+ key: "_isSamePosition",
70
+ value: function _isSamePosition(a, b) {
71
+ return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
72
+ }
73
+ }, {
74
+ key: "_normalizeCoordinate",
75
+ value: function _normalizeCoordinate(coordinate) {
76
+ if (!Array.isArray(coordinate) || coordinate.length < 2) {
77
+ return null;
78
+ }
79
+ var lng = Number(coordinate[0]);
80
+ var lat = Number(coordinate[1]);
81
+ var alt = this._toFiniteNumber(coordinate[2], 0);
82
+ if (!Number.isFinite(lng) || !Number.isFinite(lat)) {
83
+ return null;
84
+ }
85
+ return [lng, lat, alt];
86
+ }
87
+ }, {
88
+ key: "_getPolygonGeometry",
89
+ value: function _getPolygonGeometry(extent) {
90
+ var _extent$geometry;
91
+ if (!extent) {
92
+ return null;
93
+ }
94
+ if (extent.type === 'Polygon') {
95
+ return extent;
96
+ }
97
+ if (extent.type === 'Feature' && ((_extent$geometry = extent.geometry) === null || _extent$geometry === void 0 ? void 0 : _extent$geometry.type) === 'Polygon') {
98
+ return extent.geometry;
99
+ }
100
+ if (extent.type === 'FeatureCollection') {
101
+ var _extent$features;
102
+ var feature = (_extent$features = extent.features) === null || _extent$features === void 0 ? void 0 : _extent$features.find(function (item) {
103
+ var _item$geometry;
104
+ return (item === null || item === void 0 || (_item$geometry = item.geometry) === null || _item$geometry === void 0 ? void 0 : _item$geometry.type) === 'Polygon';
105
+ });
106
+ return (feature === null || feature === void 0 ? void 0 : feature.geometry) || null;
107
+ }
108
+ return null;
109
+ }
110
+ }, {
111
+ key: "_getOuterRing",
112
+ value: function _getOuterRing() {
113
+ var _geometry$coordinates,
114
+ _this = this;
115
+ var geometry = this._getPolygonGeometry(this.extent);
116
+ var ring = geometry === null || geometry === void 0 || (_geometry$coordinates = geometry.coordinates) === null || _geometry$coordinates === void 0 ? void 0 : _geometry$coordinates[0];
117
+ if (!Array.isArray(ring)) {
118
+ utils.error('地形开挖范围必须是GeoJSON Polygon');
119
+ return null;
120
+ }
121
+ var positions = ring.map(function (coordinate) {
122
+ return _this._normalizeCoordinate(coordinate);
123
+ }).filter(Boolean);
124
+ if (positions.length > 3) {
125
+ var first = positions[0];
126
+ var last = positions[positions.length - 1];
127
+ if (this._isSamePosition(first, last)) {
128
+ positions.pop();
129
+ }
130
+ }
131
+ if (positions.length < 3) {
132
+ utils.error('地形开挖范围至少需要3个有效顶点');
133
+ return null;
134
+ }
135
+ return positions;
136
+ }
137
+ }, {
138
+ key: "_closeRing",
139
+ value: function _closeRing(coordinates) {
140
+ if (!coordinates.length) {
141
+ return coordinates;
142
+ }
143
+ var result = coordinates.slice();
144
+ var first = result[0];
145
+ var last = result[result.length - 1];
146
+ if (!this._isSamePosition(first, last)) {
147
+ result.push(_toConsumableArray(first));
148
+ }
149
+ return result;
150
+ }
151
+ }, {
152
+ key: "_densifyRing",
153
+ value: function _densifyRing(ring) {
154
+ var splitNum = Math.max(1, Math.round(this._toFiniteNumber(this.options.edgeSplitNum, 1)));
155
+ var result = [];
156
+ for (var i = 0; i < ring.length; i += 1) {
157
+ var start = ring[i];
158
+ var end = ring[(i + 1) % ring.length];
159
+ for (var j = 0; j < splitNum; j += 1) {
160
+ var percent = j / splitNum;
161
+ result.push([start[0] + (end[0] - start[0]) * percent, start[1] + (end[1] - start[1]) * percent, start[2] + (end[2] - start[2]) * percent]);
162
+ }
163
+ }
164
+ return result;
165
+ }
166
+ }, {
167
+ key: "_sampleTerrain",
168
+ value: function () {
169
+ var _sampleTerrain2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(ring) {
170
+ var _this2 = this;
171
+ var map, coordinates, cartographics, sampled;
172
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
173
+ while (1) switch (_context.prev = _context.next) {
174
+ case 0:
175
+ map = this.getMap();
176
+ coordinates = this._densifyRing(ring);
177
+ if (!(!this.options.sampleTerrain || !(map !== null && map !== void 0 && map.terrainProvider))) {
178
+ _context.next = 4;
179
+ break;
180
+ }
181
+ return _context.abrupt("return", coordinates);
182
+ case 4:
183
+ _context.prev = 4;
184
+ _context.next = 7;
185
+ return utils.isTerrainReady(map);
186
+ case 7:
187
+ cartographics = coordinates.map(function (coordinate) {
188
+ return Cesium.Cartographic.fromDegrees(coordinate[0], coordinate[1]);
189
+ });
190
+ _context.next = 10;
191
+ return Cesium.sampleTerrainMostDetailed(map.terrainProvider, cartographics);
192
+ case 10:
193
+ sampled = _context.sent;
194
+ return _context.abrupt("return", sampled.map(function (cartographic, index) {
195
+ var source = coordinates[index];
196
+ var height = _this2._toFiniteNumber(cartographic === null || cartographic === void 0 ? void 0 : cartographic.height, source[2]);
197
+ return [source[0], source[1], height];
198
+ }));
199
+ case 14:
200
+ _context.prev = 14;
201
+ _context.t0 = _context["catch"](4);
202
+ utils.warn('地形高程采样失败,已使用输入坐标高度');
203
+ return _context.abrupt("return", coordinates);
204
+ case 18:
205
+ case "end":
206
+ return _context.stop();
207
+ }
208
+ }, _callee, this, [[4, 14]]);
209
+ }));
210
+ function _sampleTerrain(_x) {
211
+ return _sampleTerrain2.apply(this, arguments);
212
+ }
213
+ return _sampleTerrain;
214
+ }()
215
+ }, {
216
+ key: "_getBottomHeight",
217
+ value: function _getBottomHeight(minHeight) {
218
+ var bottomHeight = Number(this.options.bottomHeight);
219
+ if (Number.isFinite(bottomHeight)) {
220
+ return bottomHeight;
221
+ }
222
+ var depth = Math.max(this._toFiniteNumber(this.options.depth, 0), 0);
223
+ return minHeight - depth;
224
+ }
225
+ }, {
226
+ key: "_getCenterPosition",
227
+ value: function _getCenterPosition(ring) {
228
+ var center = ring.reduce(function (result, coordinate) {
229
+ result.lng += coordinate[0];
230
+ result.lat += coordinate[1];
231
+ result.alt += coordinate[2];
232
+ return result;
233
+ }, {
234
+ lng: 0,
235
+ lat: 0,
236
+ alt: 0
237
+ });
238
+ return Cesium.Cartesian3.fromDegrees(center.lng / ring.length, center.lat / ring.length, center.alt / ring.length);
239
+ }
240
+ }, {
241
+ key: "_getLocalPositions",
242
+ value: function _getLocalPositions(ring, inverseMatrix) {
243
+ return ring.map(function (coordinate) {
244
+ return Cesium.Matrix4.multiplyByPoint(inverseMatrix, Cesium.Cartesian3.fromDegrees(coordinate[0], coordinate[1], coordinate[2]), new Cesium.Cartesian3());
245
+ });
246
+ }
247
+ }, {
248
+ key: "_getLocalCenter",
249
+ value: function _getLocalCenter(localPositions) {
250
+ var center = new Cesium.Cartesian3();
251
+ localPositions.forEach(function (position) {
252
+ Cesium.Cartesian3.add(center, position, center);
253
+ });
254
+ return Cesium.Cartesian3.multiplyByScalar(center, 1 / localPositions.length, center);
255
+ }
256
+ }, {
257
+ key: "_createPlane",
258
+ value: function _createPlane(start, end, center) {
259
+ var dx = end.x - start.x;
260
+ var dy = end.y - start.y;
261
+ var length = Math.sqrt(dx * dx + dy * dy);
262
+ if (length <= 0) {
263
+ return null;
264
+ }
265
+ var normal = new Cesium.Cartesian3(dy / length, -dx / length, 0);
266
+ var distance = -Cesium.Cartesian3.dot(normal, start);
267
+ var centerDistance = Cesium.Cartesian3.dot(normal, center) + distance;
268
+ if (centerDistance >= 0) {
269
+ Cesium.Cartesian3.negate(normal, normal);
270
+ distance = -distance;
271
+ }
272
+ return new Cesium.ClippingPlane(normal, distance);
273
+ }
274
+ }, {
275
+ key: "_createClippingPlanes",
276
+ value: function _createClippingPlanes(ring) {
277
+ var center = this._getCenterPosition(ring);
278
+ var modelMatrix = Cesium.Transforms.eastNorthUpToFixedFrame(center);
279
+ var inverseMatrix = Cesium.Matrix4.inverse(modelMatrix, new Cesium.Matrix4());
280
+ var localPositions = this._getLocalPositions(ring, inverseMatrix);
281
+ var localCenter = this._getLocalCenter(localPositions);
282
+ var planes = [];
283
+ for (var i = 0; i < localPositions.length; i += 1) {
284
+ var plane = this._createPlane(localPositions[i], localPositions[(i + 1) % localPositions.length], localCenter);
285
+ if (plane) {
286
+ planes.push(plane);
287
+ }
288
+ }
289
+ return new Cesium.ClippingPlaneCollection({
290
+ planes: planes,
291
+ modelMatrix: modelMatrix,
292
+ unionClippingRegions: false,
293
+ edgeColor: utils.colorString(this.options.edgeColor),
294
+ edgeWidth: this.options.edgeWidth,
295
+ enabled: this.options.enabled
296
+ });
297
+ }
298
+ }, {
299
+ key: "_setClippingPlanes",
300
+ value: function _setClippingPlanes(clippingPlanes) {
301
+ var _this$getMap;
302
+ var globe = (_this$getMap = this.getMap()) === null || _this$getMap === void 0 || (_this$getMap = _this$getMap.scene) === null || _this$getMap === void 0 ? void 0 : _this$getMap.globe;
303
+ if (!globe) {
304
+ utils.error('当前场景不存在Globe,无法进行地形开挖分析');
305
+ return false;
306
+ }
307
+ this._previousClippingPlanes = globe.clippingPlanes;
308
+ this._clippingPlanes = clippingPlanes;
309
+ globe.clippingPlanes = clippingPlanes;
310
+ return true;
311
+ }
312
+ }, {
313
+ key: "_restoreClippingPlanes",
314
+ value: function _restoreClippingPlanes() {
315
+ var _this$getMap2;
316
+ if (!this._clippingPlanes) {
317
+ return;
318
+ }
319
+ var globe = (_this$getMap2 = this.getMap()) === null || _this$getMap2 === void 0 || (_this$getMap2 = _this$getMap2.scene) === null || _this$getMap2 === void 0 ? void 0 : _this$getMap2.globe;
320
+ if ((globe === null || globe === void 0 ? void 0 : globe.clippingPlanes) === this._clippingPlanes) {
321
+ globe.clippingPlanes = this._previousClippingPlanes;
322
+ }
323
+ if (!this._clippingPlanes.isDestroyed()) {
324
+ this._clippingPlanes.destroy();
325
+ }
326
+ this._clippingPlanes = null;
327
+ this._previousClippingPlanes = null;
328
+ }
329
+ }, {
330
+ key: "_buildPolygonGeoJson",
331
+ value: function _buildPolygonGeoJson(coordinates) {
332
+ return {
333
+ type: 'Feature',
334
+ geometry: {
335
+ type: 'Polygon',
336
+ coordinates: [this._closeRing(coordinates)]
337
+ },
338
+ properties: {}
339
+ };
340
+ }
341
+ }, {
342
+ key: "_buildLineGeoJson",
343
+ value: function _buildLineGeoJson(coordinates) {
344
+ return {
345
+ type: 'Feature',
346
+ geometry: {
347
+ type: 'LineString',
348
+ coordinates: this._closeRing(coordinates)
349
+ },
350
+ properties: {}
351
+ };
352
+ }
353
+ }, {
354
+ key: "_draw",
355
+ value: function _draw(result) {
356
+ var bottomCoordinates = result.sampledCoordinates.map(function (coordinate) {
357
+ return [coordinate[0], coordinate[1], result.bottomHeight];
358
+ });
359
+ if (this.options.showBottom) {
360
+ this._bottomLayer = this.getMap().addGraphicLayer(this._buildPolygonGeoJson(bottomCoordinates), {
361
+ type: 'polygon',
362
+ style: {
363
+ heightReference: Cesium.HeightReference.NONE,
364
+ perPositionHeight: true,
365
+ material: this.options.bottomColor,
366
+ outline: false
367
+ }
368
+ });
369
+ }
370
+ if (this.options.showWall) {
371
+ this._wallLayer = this.getMap().addGraphicLayer(this._buildLineGeoJson(result.sampledCoordinates), {
372
+ type: 'wall',
373
+ style: {
374
+ minimumHeights: this._closeRing(result.sampledCoordinates).map(function () {
375
+ return result.bottomHeight;
376
+ }),
377
+ maximumHeights: this._closeRing(result.sampledCoordinates).map(function (coordinate) {
378
+ return coordinate[2];
379
+ }),
380
+ material: this.options.wallColor
381
+ }
382
+ });
383
+ }
384
+ if (this.options.showEdge) {
385
+ this._edgeLayer = this.getMap().addGraphicLayer(this._buildLineGeoJson(result.sampledCoordinates), {
386
+ type: 'polyline',
387
+ style: {
388
+ width: this.options.edgeWidth,
389
+ material: this.options.edgeColor,
390
+ depthFailMaterial: this.options.edgeColor,
391
+ clampToGround: false
392
+ }
393
+ });
394
+ }
395
+ }
396
+ }, {
397
+ key: "_clearLayers",
398
+ value: function _clearLayers() {
399
+ if (this._bottomLayer) {
400
+ this._bottomLayer.remove();
401
+ this._bottomLayer = null;
402
+ }
403
+ if (this._wallLayer) {
404
+ this._wallLayer.remove();
405
+ this._wallLayer = null;
406
+ }
407
+ if (this._edgeLayer) {
408
+ this._edgeLayer.remove();
409
+ this._edgeLayer = null;
410
+ }
411
+ }
412
+ }, {
413
+ key: "getMap",
414
+ value: function getMap() {
415
+ return this._mapContext && this._mapContext.getMap();
416
+ }
417
+ }, {
418
+ key: "create",
419
+ value: function () {
420
+ var _create = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
421
+ var token, ring, sampledCoordinates, heights, minHeight, maxHeight, bottomHeight, clippingPlanes, result;
422
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
423
+ while (1) switch (_context2.prev = _context2.next) {
424
+ case 0:
425
+ if (this._canOperate()) {
426
+ _context2.next = 2;
427
+ break;
428
+ }
429
+ return _context2.abrupt("return", null);
430
+ case 2:
431
+ token = this._createToken += 1;
432
+ this._clearLayers();
433
+ this._restoreClippingPlanes();
434
+ ring = this._getOuterRing();
435
+ if (ring) {
436
+ _context2.next = 8;
437
+ break;
438
+ }
439
+ return _context2.abrupt("return", null);
440
+ case 8:
441
+ _context2.next = 10;
442
+ return this._sampleTerrain(ring);
443
+ case 10:
444
+ sampledCoordinates = _context2.sent;
445
+ if (!(token !== this._createToken || this.isDestroyed)) {
446
+ _context2.next = 13;
447
+ break;
448
+ }
449
+ return _context2.abrupt("return", null);
450
+ case 13:
451
+ heights = sampledCoordinates.map(function (coordinate) {
452
+ return coordinate[2];
453
+ });
454
+ minHeight = Math.min.apply(Math, _toConsumableArray(heights));
455
+ maxHeight = Math.max.apply(Math, _toConsumableArray(heights));
456
+ bottomHeight = this._getBottomHeight(minHeight);
457
+ clippingPlanes = this._createClippingPlanes(ring);
458
+ if (this._setClippingPlanes(clippingPlanes)) {
459
+ _context2.next = 21;
460
+ break;
461
+ }
462
+ clippingPlanes.destroy();
463
+ return _context2.abrupt("return", null);
464
+ case 21:
465
+ result = {
466
+ extent: this.extent,
467
+ coordinates: ring,
468
+ sampledCoordinates: sampledCoordinates,
469
+ bottomHeight: bottomHeight,
470
+ minHeight: minHeight,
471
+ maxHeight: maxHeight,
472
+ depth: minHeight - bottomHeight,
473
+ clippingPlanes: clippingPlanes
474
+ };
475
+ this._result = result;
476
+ this._draw(result);
477
+ this.options.onComplete && this.options.onComplete(result);
478
+ return _context2.abrupt("return", result);
479
+ case 26:
480
+ case "end":
481
+ return _context2.stop();
482
+ }
483
+ }, _callee2, this);
484
+ }));
485
+ function create() {
486
+ return _create.apply(this, arguments);
487
+ }
488
+ return create;
489
+ }()
490
+ }, {
491
+ key: "update",
492
+ value: function () {
493
+ var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
494
+ var options,
495
+ _args3 = arguments;
496
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
497
+ while (1) switch (_context3.prev = _context3.next) {
498
+ case 0:
499
+ options = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {};
500
+ if (this._canOperate()) {
501
+ _context3.next = 3;
502
+ break;
503
+ }
504
+ return _context3.abrupt("return", null);
505
+ case 3:
506
+ this.options = merge({}, this.options, options);
507
+ this._replaceNullableOptions(options);
508
+ return _context3.abrupt("return", this.create());
509
+ case 6:
510
+ case "end":
511
+ return _context3.stop();
512
+ }
513
+ }, _callee3, this);
514
+ }));
515
+ function update() {
516
+ return _update.apply(this, arguments);
517
+ }
518
+ return update;
519
+ }()
520
+ }, {
521
+ key: "setExtent",
522
+ value: function () {
523
+ var _setExtent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(extent) {
524
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
525
+ while (1) switch (_context4.prev = _context4.next) {
526
+ case 0:
527
+ if (this._canOperate()) {
528
+ _context4.next = 2;
529
+ break;
530
+ }
531
+ return _context4.abrupt("return", null);
532
+ case 2:
533
+ this.extent = extent;
534
+ return _context4.abrupt("return", this.create());
535
+ case 4:
536
+ case "end":
537
+ return _context4.stop();
538
+ }
539
+ }, _callee4, this);
540
+ }));
541
+ function setExtent(_x2) {
542
+ return _setExtent.apply(this, arguments);
543
+ }
544
+ return setExtent;
545
+ }()
546
+ }, {
547
+ key: "setDepth",
548
+ value: function () {
549
+ var _setDepth = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(depth) {
550
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
551
+ while (1) switch (_context5.prev = _context5.next) {
552
+ case 0:
553
+ if (this._canOperate()) {
554
+ _context5.next = 2;
555
+ break;
556
+ }
557
+ return _context5.abrupt("return", null);
558
+ case 2:
559
+ this.options.depth = depth;
560
+ return _context5.abrupt("return", this.create());
561
+ case 4:
562
+ case "end":
563
+ return _context5.stop();
564
+ }
565
+ }, _callee5, this);
566
+ }));
567
+ function setDepth(_x3) {
568
+ return _setDepth.apply(this, arguments);
569
+ }
570
+ return setDepth;
571
+ }()
572
+ }, {
573
+ key: "getResult",
574
+ value: function getResult() {
575
+ return this._result;
576
+ }
577
+ }, {
578
+ key: "flyTo",
579
+ value: function flyTo() {
580
+ if (!this._canOperate()) return;
581
+ if (this._edgeLayer) {
582
+ this._edgeLayer.flyTo();
583
+ return;
584
+ }
585
+ if (this._bottomLayer) {
586
+ this._bottomLayer.flyTo();
587
+ return;
588
+ }
589
+ if (this._wallLayer) {
590
+ this._wallLayer.flyTo();
591
+ }
592
+ }
593
+ }, {
594
+ key: "clear",
595
+ value: function clear() {
596
+ if (!this._canOperate()) return;
597
+ this._createToken += 1;
598
+ this._clearLayers();
599
+ this._restoreClippingPlanes();
600
+ this._result = null;
601
+ }
602
+ }, {
603
+ key: "destroy",
604
+ value: function destroy() {
605
+ if (!this._canOperate()) return;
606
+ this.clear();
607
+ this.isDestroyed = true;
608
+ }
609
+ }]);
610
+ return TerrainExcavationAnalysis;
611
+ }();
612
+ export default TerrainExcavationAnalysis;