deeptwins-engine-3d 0.1.49 → 0.1.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/esm/constant.d.ts +9 -0
  2. package/dist/esm/constant.js +16 -0
  3. package/dist/esm/drawCommand/index.d.ts +2 -0
  4. package/dist/esm/drawCommand/index.js +2 -0
  5. package/dist/esm/drawCommand/viewShed/Event.d.ts +42 -0
  6. package/dist/esm/drawCommand/viewShed/Event.js +142 -0
  7. package/dist/esm/drawCommand/viewShed/RectangularSensorPrimitive.d.ts +266 -0
  8. package/dist/esm/drawCommand/viewShed/RectangularSensorPrimitive.js +1271 -0
  9. package/dist/esm/drawCommand/viewShed/ViewShadowPrimitive.d.ts +29 -0
  10. package/dist/esm/drawCommand/viewShed/ViewShadowPrimitive.js +66 -0
  11. package/dist/esm/drawCommand/viewShed/ViewShedAnalyserLayer.d.ts +182 -0
  12. package/dist/esm/drawCommand/viewShed/ViewShedAnalyserLayer.js +466 -0
  13. package/dist/esm/drawCommand/viewShed/ViewShedMap.d.ts +22 -0
  14. package/dist/esm/drawCommand/viewShed/ViewShedMap.js +1238 -0
  15. package/dist/esm/drawCommand/viewShed/config.d.ts +20 -0
  16. package/dist/esm/drawCommand/viewShed/config.js +21 -0
  17. package/dist/esm/graphicLayer/BaseSource.d.ts +1 -1
  18. package/dist/esm/graphicLayer/PolygonGroundPrimitiveImageMaterialInstance.js +1 -1
  19. package/dist/esm/index.d.ts +2 -1
  20. package/dist/esm/index.js +7 -4
  21. package/dist/esm/map/Map.d.ts +1 -0
  22. package/dist/esm/map/Map.js +6 -1
  23. package/dist/esm/material/primitive/ImageMaterialAppearance.d.ts +1 -1
  24. package/dist/esm/tool/BuildClampedPolygonGrid.d.ts +2 -9
  25. package/dist/esm/tool/BuildClampedPolygonGrid.js +200 -73
  26. package/dist/esm/tool/utils.d.ts +1 -0
  27. package/dist/esm/tool/utils.js +21 -0
  28. package/dist/esm/videoFusion/BaseVideo.js +17 -17
  29. package/dist/esm/videoFusion/VideoProject.d.ts +5 -5
  30. package/dist/esm/videoFusion/VideoProject.js +174 -184
  31. package/dist/esm/videoFusion/VideoTexture.d.ts +5 -1
  32. package/dist/esm/videoFusion/VideoTexture.js +133 -46
  33. package/dist/umd/deeptwins-engine-3d.min.js +1 -1
  34. package/package.json +4 -2
@@ -157,8 +157,10 @@ var BaseVideo = /*#__PURE__*/function () {
157
157
  }, {
158
158
  key: "_drawCanvas",
159
159
  value: function _drawCanvas(options) {
160
- var width = options.width,
161
- height = options.height;
160
+ var _options$videoOptions = options.videoOptions,
161
+ width = _options$videoOptions.width,
162
+ height = _options$videoOptions.height,
163
+ edgeFeather = options.style.edgeFeather;
162
164
  var canvas = document.createElement('canvas');
163
165
  canvas.width = width;
164
166
  canvas.height = height;
@@ -169,18 +171,20 @@ var BaseVideo = /*#__PURE__*/function () {
169
171
  ctx.drawImage(this.videoElement, 0, 0, width, height);
170
172
 
171
173
  // 2. 应用羽化遮罩
172
- ctx.globalCompositeOperation = 'destination-in'; // 使用遮罩影响透明度
174
+ if (edgeFeather) {
175
+ ctx.globalCompositeOperation = 'destination-in'; // 使用遮罩影响透明度
173
176
 
174
- var maskCanvas = document.createElement('canvas');
175
- maskCanvas.width = width;
176
- maskCanvas.height = height;
177
- var maskCtx = maskCanvas.getContext('2d');
178
- if (maskCtx && this._maskImage) {
179
- // 绘制并拉伸遮罩图片到整个画布
180
- maskCtx.drawImage(this._maskImage, 0, 0, width, height);
181
- ctx.drawImage(maskCanvas, 0, 0);
177
+ var maskCanvas = document.createElement('canvas');
178
+ maskCanvas.width = width;
179
+ maskCanvas.height = height;
180
+ var maskCtx = maskCanvas.getContext('2d');
181
+ if (maskCtx && this._maskImage) {
182
+ // 绘制并拉伸遮罩图片到整个画布
183
+ maskCtx.drawImage(this._maskImage, 0, 0, width, height);
184
+ ctx.drawImage(maskCanvas, 0, 0);
185
+ }
186
+ ctx.globalCompositeOperation = 'source-over'; // 还原默认混合模式
182
187
  }
183
- ctx.globalCompositeOperation = 'source-over'; // 还原默认混合模式
184
188
  return canvas;
185
189
  }
186
190
 
@@ -213,11 +217,6 @@ var BaseVideo = /*#__PURE__*/function () {
213
217
  _this2.onErrorFun && _this2.onErrorFun(e);
214
218
  });
215
219
  }
216
- if (this.videoPolygonLayer) {
217
- this.videoPolygonLayer.setStyle({
218
- material: this.videoElement
219
- });
220
- }
221
220
  }
222
221
  // 暂停后继续播放
223
222
  if (this.synchronizer && this.videoType === 'hls') {
@@ -250,6 +249,7 @@ var BaseVideo = /*#__PURE__*/function () {
250
249
  });
251
250
  this.getMap().clock.shouldAnimate = true;
252
251
  }
252
+ this.videoElement.style.display = 'none';
253
253
  }
254
254
 
255
255
  // 监听错误
@@ -1,12 +1,12 @@
1
1
  import BaseVideo from './BaseVideo';
2
2
  export default class VideoProject extends BaseVideo {
3
- type: 'fixed' | 'projection';
4
3
  frustum: any;
5
- frustumLineLayer: any;
4
+ private _videoOptions;
5
+ private _preRenderEvent;
6
6
  constructor(map: any, options: any);
7
- addToMap(): void;
7
+ addToMap(): Promise<unknown>;
8
+ private _create;
8
9
  show(isShow: boolean): void;
9
- private _drawLine;
10
- private _getInterPointByLine;
10
+ private _getInterPointByRayTerrain;
11
11
  destroy(): void;
12
12
  }
@@ -1,4 +1,7 @@
1
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); }); }; }
2
5
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
6
  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); } }
4
7
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -16,8 +19,9 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
16
19
  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
20
  import * as Cesium from 'deeptwins-cesium';
18
21
  import { merge } from 'lodash';
19
- import { DEFAULT_VIDEO_TEXTURE_HLS, DEFAULT_VIDEO_TEXTURE_VIDEO } from "../constant";
20
- import { ClampToGround } from "../tool/common";
22
+ import { DEFAULT_VIDEO_FUSION_STYLE, DEFAULT_VIDEO_TEXTURE_HLS, DEFAULT_VIDEO_TEXTURE_VIDEO } from "../constant";
23
+ import ImageMaterialAppearance from "../material/primitive/ImageMaterialAppearance";
24
+ import BuildClampedPolygonGridUnified from "../tool/BuildClampedPolygonGrid";
21
25
  import * as utils from "../tool/utils";
22
26
  import BaseVideo from "./BaseVideo";
23
27
 
@@ -28,211 +32,197 @@ var VideoProject = /*#__PURE__*/function (_BaseVideo) {
28
32
  function VideoProject(map, options) {
29
33
  var _this;
30
34
  _classCallCheck(this, VideoProject);
35
+ options.style = merge(DEFAULT_VIDEO_FUSION_STYLE(), options.style || {});
31
36
  _this = _super.call(this, map, options);
32
- _defineProperty(_assertThisInitialized(_this), "type", 'fixed');
33
37
  _defineProperty(_assertThisInitialized(_this), "frustum", void 0);
34
- _defineProperty(_assertThisInitialized(_this), "frustumLineLayer", void 0);
38
+ _defineProperty(_assertThisInitialized(_this), "_videoOptions", void 0);
39
+ _defineProperty(_assertThisInitialized(_this), "_preRenderEvent", void 0);
35
40
  return _this;
36
41
  }
37
42
  _createClass(VideoProject, [{
38
43
  key: "addToMap",
39
- value: function addToMap() {
40
- var _this2 = this;
41
- if (!this._canOperate()) {
42
- return;
43
- }
44
- var videoOptions;
45
- if (this.videoType === 'video') {
46
- this.options.video.autoPlay && this.play();
47
- videoOptions = merge(DEFAULT_VIDEO_TEXTURE_VIDEO(), this.options.video);
48
- }
49
- if (this.videoType === 'hls') {
50
- this.options.hls.autoPlay && this.status === 'READY' && this.play();
51
- videoOptions = merge(DEFAULT_VIDEO_TEXTURE_HLS(), this.options.hls);
52
- }
53
- if (this.videoType === 'custom') {
54
- videoOptions = merge({}, this.options.custom);
55
- }
56
- setTimeout(function () {
57
- var _this2$options = _this2.options,
58
- _this2$options$type = _this2$options.type,
59
- type = _this2$options$type === void 0 ? 'fixed' : _this2$options$type,
60
- frustum = _this2$options.frustum,
61
- _this2$options$style = _this2$options.style,
62
- _this2$options$style2 = _this2$options$style === void 0 ? {
63
- edgeFeather: false,
64
- clampToGround: 'terrain',
65
- showLine: true
66
- } : _this2$options$style,
67
- edgeFeather = _this2$options$style2.edgeFeather,
68
- clampToGround = _this2$options$style2.clampToGround,
69
- showLine = _this2$options$style2.showLine;
70
- frustum.show(false);
71
- _this2.type = type;
72
- _this2.frustum = frustum;
73
- // 取后4个点
74
- var points = _this2.frustum.getFarPlane();
75
- if (_this2.type === 'projection') {
76
- // 交点数组
77
- var interPoints = [];
78
- points.forEach(function (point) {
79
- var interPoint = _this2._getInterPointByLine(_this2.frustum.options.position, point);
80
- interPoints.push(interPoint);
81
- });
82
- if (showLine) {
83
- // 绘制线
84
- _this2._drawLine(interPoints);
44
+ value: function () {
45
+ var _addToMap = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
46
+ var _this2 = this;
47
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
48
+ while (1) switch (_context2.prev = _context2.next) {
49
+ case 0:
50
+ if (this._canOperate()) {
51
+ _context2.next = 2;
52
+ break;
53
+ }
54
+ return _context2.abrupt("return");
55
+ case 2:
56
+ if (this.videoType === 'video') {
57
+ this.options.video.autoPlay && this.play();
58
+ this._videoOptions = merge(DEFAULT_VIDEO_TEXTURE_VIDEO(), this.options.video);
59
+ }
60
+ if (this.videoType === 'hls') {
61
+ this.options.hls.autoPlay && this.status === 'READY' && this.play();
62
+ this._videoOptions = merge(DEFAULT_VIDEO_TEXTURE_HLS(), this.options.hls);
63
+ }
64
+ if (this.videoType === 'custom') {
65
+ this._videoOptions = merge({}, this.options.custom);
66
+ }
67
+ return _context2.abrupt("return", new Promise(function (resolve) {
68
+ setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
69
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
70
+ while (1) switch (_context.prev = _context.next) {
71
+ case 0:
72
+ _context.next = 2;
73
+ return _this2._create();
74
+ case 2:
75
+ resolve(null);
76
+ case 3:
77
+ case "end":
78
+ return _context.stop();
79
+ }
80
+ }, _callee);
81
+ })), 200);
82
+ }));
83
+ case 6:
84
+ case "end":
85
+ return _context2.stop();
85
86
  }
86
- _this2.videoPolygonLayer = _this2.getMap().addGraphicLayer({
87
- type: 'Feature',
88
- geometry: {
89
- type: 'Polygon',
90
- coordinates: [interPoints]
91
- }
92
- }, {
93
- type: 'polygon',
94
- style: {
95
- material: edgeFeather ? new Cesium.ImageMaterialProperty({
96
- image: new Cesium.CallbackProperty(function () {
97
- return _this2._drawCanvas(videoOptions);
98
- }, false),
99
- transparent: true
100
- }) : _this2.videoElement,
101
- heightReference: clampToGround ? Cesium.HeightReference.CLAMP_TO_GROUND : Cesium.HeightReference.NONE,
102
- perPositionHeight: !clampToGround
103
- }
104
- });
105
- }
106
- if (_this2.type === 'fixed') {
107
- if (showLine) {
108
- // 绘制线
109
- _this2._drawLine(points);
87
+ }, _callee2, this);
88
+ }));
89
+ function addToMap() {
90
+ return _addToMap.apply(this, arguments);
91
+ }
92
+ return addToMap;
93
+ }()
94
+ }, {
95
+ key: "_create",
96
+ value: function () {
97
+ var _create2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
98
+ var _this3 = this;
99
+ var _this$options, frustum, _this$options$style, clampToGround, _this$options$style$b, gridSize, heightBuffer, stRotation, points, canvas, material, interPoints, feature, data, _feature;
100
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
101
+ while (1) switch (_context3.prev = _context3.next) {
102
+ case 0:
103
+ _this$options = this.options, frustum = _this$options.frustum, _this$options$style = _this$options.style, clampToGround = _this$options$style.clampToGround, _this$options$style$b = _this$options$style.buildClampedPolygonGrid, gridSize = _this$options$style$b.gridSize, heightBuffer = _this$options$style$b.heightBuffer, stRotation = _this$options$style.stRotation;
104
+ this.frustum = frustum;
105
+ // 远平面的点
106
+ points = this.frustum.getFarPlane();
107
+ canvas = this._drawCanvas({
108
+ videoOptions: this._videoOptions,
109
+ style: this.options.style
110
+ });
111
+ material = new ImageMaterialAppearance({
112
+ image: canvas,
113
+ color: '#ffffff',
114
+ mixRatio: 0
115
+ });
116
+ if (!clampToGround) {
117
+ _context3.next = 20;
118
+ break;
119
+ }
120
+ _context3.next = 8;
121
+ return utils.isTerrainReady(this.getMap());
122
+ case 8:
123
+ // 交点数组
124
+ interPoints = [];
125
+ points.forEach(function (point) {
126
+ var interPoint = _this3._getInterPointByRayTerrain(_this3.frustum.options.position, point);
127
+ interPoints.push(interPoint);
128
+ });
129
+ if (!interPoints.includes(null)) {
130
+ _context3.next = 13;
131
+ break;
132
+ }
133
+ utils.error('未找到与地形/模型相交的点');
134
+ return _context3.abrupt("return");
135
+ case 13:
136
+ feature = {
137
+ type: 'Feature',
138
+ geometry: {
139
+ type: 'Polygon',
140
+ coordinates: [interPoints]
141
+ }
142
+ };
143
+ _context3.next = 16;
144
+ return BuildClampedPolygonGridUnified(this.getMap(), feature, gridSize, heightBuffer);
145
+ case 16:
146
+ data = _context3.sent;
147
+ this.videoPolygonLayer = this.getMap().addGraphicLayer(data, {
148
+ type: 'polygonGroundImageP',
149
+ style: {
150
+ material: material,
151
+ stRotation: stRotation
152
+ }
153
+ });
154
+ _context3.next = 22;
155
+ break;
156
+ case 20:
157
+ _feature = {
158
+ type: 'Feature',
159
+ geometry: {
160
+ type: 'Polygon',
161
+ coordinates: [points]
162
+ }
163
+ };
164
+ this.videoPolygonLayer = this.getMap().addGraphicLayer(_feature, {
165
+ type: 'polygonImageP',
166
+ style: {
167
+ material: material,
168
+ stRotation: stRotation
169
+ }
170
+ });
171
+ case 22:
172
+ this.status = 'START';
173
+ this._preRenderEvent = function () {
174
+ if (_this3.videoElement && _this3.status != 'PAUSE') {
175
+ // 通知 Cesium 更新纹理
176
+ material.material.uniforms.image = _this3._drawCanvas({
177
+ videoOptions: _this3._videoOptions,
178
+ style: _this3.options.style
179
+ });
180
+ }
181
+ };
182
+ this.getMap().scene.preRender.addEventListener(this._preRenderEvent);
183
+ case 25:
184
+ case "end":
185
+ return _context3.stop();
110
186
  }
111
- _this2.videoPolygonLayer = _this2.getMap().addGraphicLayer({
112
- type: 'Feature',
113
- geometry: {
114
- type: 'Polygon',
115
- coordinates: [points]
116
- }
117
- }, {
118
- type: 'polygon',
119
- style: {
120
- material: edgeFeather ? new Cesium.ImageMaterialProperty({
121
- image: new Cesium.CallbackProperty(function () {
122
- return _this2._drawCanvas(videoOptions);
123
- }, false),
124
- transparent: true
125
- }) : _this2.videoElement,
126
- heightReference: Cesium.HeightReference.NONE,
127
- perPositionHeight: true
128
- }
129
- });
130
- }
131
- _this2.status = 'START';
132
- }, 200);
133
- }
134
-
135
- // 显示隐藏
187
+ }, _callee3, this);
188
+ }));
189
+ function _create() {
190
+ return _create2.apply(this, arguments);
191
+ }
192
+ return _create;
193
+ }() // 显示隐藏
136
194
  }, {
137
195
  key: "show",
138
196
  value: function show(isShow) {
139
- if (!this._canOperate()) {
140
- return;
141
- }
142
- this.frustumLineLayer && this.frustumLineLayer.show(isShow);
143
197
  _get(_getPrototypeOf(VideoProject.prototype), "show", this).call(this, isShow);
198
+ this.frustum && this.frustum.show(isShow);
144
199
  }
145
-
146
- // 绘制线
147
200
  }, {
148
- key: "_drawLine",
149
- value: function _drawLine(interPoints) {
150
- var _this3 = this,
151
- _this$options$style;
152
- var draw = function draw(geoJson) {
153
- _this3.frustumLineLayer = _this3.getMap().addGraphicLayer(geoJson, {
154
- type: 'polylineP',
155
- style: {
156
- color: '#ffffff'
157
- }
158
- });
159
- };
160
- var linePoints = [];
161
- // 是否计算贴地
162
- if ((_this$options$style = this.options.style) !== null && _this$options$style !== void 0 && _this$options$style.clampToGround && this.type === 'projection') {
163
- var clampToGround = new ClampToGround(this.getMap());
164
- var c3arr = utils.lngLatAltArrayToCartesian3Array(interPoints);
165
- clampToGround.getLngLatAltArrToHeight(c3arr, 'terrain').then(function (result) {
166
- result.coordinates.forEach(function (point) {
167
- linePoints.push({
168
- type: 'Feature',
169
- geometry: {
170
- type: 'LineString',
171
- coordinates: [_this3.frustum.options.position, point]
172
- }
173
- });
174
- });
175
- draw({
176
- type: 'FeatureCollection',
177
- features: linePoints
178
- });
179
- });
180
- } else {
181
- interPoints.forEach(function (interPoint) {
182
- linePoints.push({
183
- type: 'Feature',
184
- geometry: {
185
- type: 'LineString',
186
- coordinates: [_this3.frustum.options.position, interPoint]
187
- }
188
- });
189
- });
190
- draw({
191
- type: 'FeatureCollection',
192
- features: linePoints
193
- });
194
- }
195
- }
196
-
197
- // 求射线的交点
198
- }, {
199
- key: "_getInterPointByLine",
200
- value: function _getInterPointByLine(start, end) {
201
- var startPoint = utils.lngLatAltToCartographic(start[0], start[1], start[2]);
202
- var endPoint = utils.lngLatAltToCartographic(end[0], end[1], end[2]);
203
- // 创建起点和终点的笛卡尔坐标
204
- var startCartesian = this.getMap().scene.globe.ellipsoid.cartographicToCartesian(startPoint);
205
- var endCartesian = this.getMap().scene.globe.ellipsoid.cartographicToCartesian(endPoint);
206
- // 通过原点和方向 创建射线
201
+ key: "_getInterPointByRayTerrain",
202
+ value: function _getInterPointByRayTerrain(start, end) {
203
+ var ellipsoid = this.getMap().scene.globe.ellipsoid;
204
+ var startCarto = Cesium.Cartographic.fromDegrees(start[0], start[1], start[2]);
205
+ var endCarto = Cesium.Cartographic.fromDegrees(end[0], end[1], end[2]);
206
+ var startCartesian = ellipsoid.cartographicToCartesian(startCarto);
207
+ var endCartesian = ellipsoid.cartographicToCartesian(endCarto);
207
208
  var direction = Cesium.Cartesian3.subtract(endCartesian, startCartesian, new Cesium.Cartesian3());
209
+ Cesium.Cartesian3.normalize(direction, direction);
208
210
  var ray = new Cesium.Ray(startCartesian, direction);
209
211
 
210
- // 计算射线与地球表面的交点
211
- var result = Cesium.IntersectionTests.rayEllipsoid(ray, this.getMap().scene.globe.ellipsoid);
212
- if (result && result.start !== result.stop) {
213
- // 计算交点的位置
214
- var intersectionPoint = Cesium.Ray.getPoint(ray, result.start);
215
- // 将交点的笛卡尔坐标转换为地理坐标
216
- var cartographic = Cesium.Cartographic.fromCartesian(intersectionPoint);
217
- var lng = utils.toDegrees(cartographic.longitude); //经度
218
- var lat = utils.toDegrees(cartographic.latitude); //纬度
219
- var alt = cartographic.height || 0;
220
- return [lng, lat, alt];
221
- } else {
222
- return null;
223
- }
212
+ // 与地形求交
213
+ var intersection = this.getMap().scene.globe.pick(ray, this.getMap().scene);
214
+ if (!intersection) return null;
215
+ var cartographic = Cesium.Cartographic.fromCartesian(intersection);
216
+ return [Cesium.Math.toDegrees(cartographic.longitude), Cesium.Math.toDegrees(cartographic.latitude), cartographic.height];
224
217
  }
225
218
  }, {
226
219
  key: "destroy",
227
220
  value: function destroy() {
228
- if (!this._canOperate()) {
229
- return;
230
- }
221
+ _get(_getPrototypeOf(VideoProject.prototype), "destroy", this).call(this);
231
222
  this.frustum && this.frustum.destroy();
232
223
  this.frustum = null;
233
- this.frustumLineLayer && this.getMap().removeGraphicSource(this.frustumLineLayer.id);
234
- this.frustumLineLayer = null;
235
- _get(_getPrototypeOf(VideoProject.prototype), "destroy", this).call(this);
224
+ this.getMap().scene.preRender.removeEventListener(this._preRenderEvent);
225
+ this._preRenderEvent = null;
236
226
  }
237
227
  }]);
238
228
  return VideoProject;
@@ -1,5 +1,9 @@
1
1
  import BaseVideo from './BaseVideo';
2
2
  export default class VideoTexture extends BaseVideo {
3
+ private _videoOptions;
4
+ private _preRenderEvent;
3
5
  constructor(map: any, options: any);
4
- addToMap(): void;
6
+ addToMap(): Promise<unknown>;
7
+ private _create;
8
+ destroy(): void;
5
9
  }