deeptwins-engine-3d 0.1.48 → 0.1.50
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.
- package/dist/esm/constant.d.ts +9 -0
- package/dist/esm/constant.js +18 -0
- package/dist/esm/drawCommand/index.d.ts +2 -0
- package/dist/esm/drawCommand/index.js +2 -0
- package/dist/esm/drawCommand/viewShed/Event.d.ts +42 -0
- package/dist/esm/drawCommand/viewShed/Event.js +142 -0
- package/dist/esm/drawCommand/viewShed/RectangularSensorPrimitive.d.ts +266 -0
- package/dist/esm/drawCommand/viewShed/RectangularSensorPrimitive.js +1271 -0
- package/dist/esm/drawCommand/viewShed/ViewShadowPrimitive.d.ts +29 -0
- package/dist/esm/drawCommand/viewShed/ViewShadowPrimitive.js +66 -0
- package/dist/esm/drawCommand/viewShed/ViewShedAnalyserLayer.d.ts +182 -0
- package/dist/esm/drawCommand/viewShed/ViewShedAnalyserLayer.js +466 -0
- package/dist/esm/drawCommand/viewShed/ViewShedMap.d.ts +22 -0
- package/dist/esm/drawCommand/viewShed/ViewShedMap.js +1238 -0
- package/dist/esm/drawCommand/viewShed/config.d.ts +20 -0
- package/dist/esm/drawCommand/viewShed/config.js +21 -0
- package/dist/esm/graphicLayer/BaseLayer.js +3 -0
- package/dist/esm/graphicLayer/BasePrimitiveInstance.d.ts +2 -0
- package/dist/esm/graphicLayer/BasePrimitiveInstance.js +13 -5
- package/dist/esm/graphicLayer/BaseSource.d.ts +1 -1
- package/dist/esm/graphicLayer/BaseSource.js +6 -0
- package/dist/esm/graphicLayer/PolygonGroundPrimitiveImageMaterialInstance.d.ts +5 -0
- package/dist/esm/graphicLayer/PolygonGroundPrimitiveImageMaterialInstance.js +84 -0
- package/dist/esm/graphicLayer/PolygonPrimitiveImageMaterialInstance.js +7 -1
- package/dist/esm/graphicLayer/PolylineGroundPrimitiveInstance.js +1 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +7 -2
- package/dist/esm/map/Map.js +2 -2
- package/dist/esm/material/primitive/ImageMaterialAppearance.d.ts +1 -1
- package/dist/esm/tool/BuildClampedPolygonGrid.d.ts +4 -0
- package/dist/esm/tool/BuildClampedPolygonGrid.js +273 -0
- package/dist/esm/tool/utils.d.ts +9 -0
- package/dist/esm/tool/utils.js +50 -0
- package/dist/esm/videoFusion/BaseVideo.js +17 -17
- package/dist/esm/videoFusion/VideoProject.d.ts +5 -5
- package/dist/esm/videoFusion/VideoProject.js +174 -184
- package/dist/esm/videoFusion/VideoTexture.d.ts +5 -1
- package/dist/esm/videoFusion/VideoTexture.js +133 -46
- package/dist/umd/deeptwins-engine-3d.min.js +1 -1
- package/package.json +5 -3
|
@@ -0,0 +1,273 @@
|
|
|
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
+
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; }
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
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); }
|
|
8
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
9
|
+
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); }
|
|
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 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); } }
|
|
12
|
+
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); }); }; }
|
|
13
|
+
import { Delaunay } from 'd3-delaunay';
|
|
14
|
+
import * as Cesium from 'deeptwins-cesium';
|
|
15
|
+
import BaseSource from "../graphicLayer/BaseSource";
|
|
16
|
+
import { translateSource } from "../tool/common";
|
|
17
|
+
import * as utils from "./utils";
|
|
18
|
+
function distanceToSegment(p, a, b) {
|
|
19
|
+
var abx = b.x - a.x;
|
|
20
|
+
var aby = b.y - a.y;
|
|
21
|
+
var apx = p.x - a.x;
|
|
22
|
+
var apy = p.y - a.y;
|
|
23
|
+
var abLen2 = abx * abx + aby * aby;
|
|
24
|
+
var t = abLen2 === 0 ? 0 : Math.max(0, Math.min(1, (apx * abx + apy * aby) / abLen2));
|
|
25
|
+
var dx = a.x + t * abx - p.x;
|
|
26
|
+
var dy = a.y + t * aby - p.y;
|
|
27
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
28
|
+
}
|
|
29
|
+
function distanceToPolygonEdge(p, polygon) {
|
|
30
|
+
var min = Infinity;
|
|
31
|
+
for (var i = 0; i < polygon.length; i++) {
|
|
32
|
+
var a = polygon[i];
|
|
33
|
+
var b = polygon[(i + 1) % polygon.length];
|
|
34
|
+
min = Math.min(min, distanceToSegment(p, a, b));
|
|
35
|
+
}
|
|
36
|
+
return min;
|
|
37
|
+
}
|
|
38
|
+
function pointInPolygon(pt, polygon) {
|
|
39
|
+
var inside = false;
|
|
40
|
+
for (var i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
|
|
41
|
+
var xi = polygon[i].x,
|
|
42
|
+
yi = polygon[i].y;
|
|
43
|
+
var xj = polygon[j].x,
|
|
44
|
+
yj = polygon[j].y;
|
|
45
|
+
var intersect = yi > pt.y !== yj > pt.y && pt.x < (xj - xi) * (pt.y - yi) / (yj - yi) + xi;
|
|
46
|
+
if (intersect) inside = !inside;
|
|
47
|
+
}
|
|
48
|
+
return inside;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// 构建贴模型/贴地网格
|
|
52
|
+
export default function BuildClampedPolygonGridUnified(_x, _x2) {
|
|
53
|
+
return _BuildClampedPolygonGridUnified.apply(this, arguments);
|
|
54
|
+
}
|
|
55
|
+
function _BuildClampedPolygonGridUnified() {
|
|
56
|
+
_BuildClampedPolygonGridUnified = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(map, geoJson) {
|
|
57
|
+
var gridSize,
|
|
58
|
+
heightBuffer,
|
|
59
|
+
scene,
|
|
60
|
+
translatedSource,
|
|
61
|
+
source,
|
|
62
|
+
finalSource,
|
|
63
|
+
_loop,
|
|
64
|
+
i,
|
|
65
|
+
_args2 = arguments;
|
|
66
|
+
return _regeneratorRuntime().wrap(function _callee$(_context2) {
|
|
67
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
68
|
+
case 0:
|
|
69
|
+
gridSize = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : 10;
|
|
70
|
+
heightBuffer = _args2.length > 3 && _args2[3] !== undefined ? _args2[3] : 0.5;
|
|
71
|
+
scene = map.scene; // 地形至少加载一次(给 fallback 用)
|
|
72
|
+
_context2.next = 5;
|
|
73
|
+
return utils.isTerrainReady(map);
|
|
74
|
+
case 5:
|
|
75
|
+
translatedSource = translateSource(geoJson);
|
|
76
|
+
source = BaseSource.geoJsonToGeoCartesian3Array(translatedSource);
|
|
77
|
+
finalSource = [];
|
|
78
|
+
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
79
|
+
var positions, ring, center, plane, poly2D, minX, minY, maxX, maxY, _iterator, _step, p, gridPoints2D, edgeFactor, edgeThreshold, y, x, center2D, dist, step, j, a, b, edgeLen, n, k, t, delaunay, indices, positions3D, modelClamped, needTerrain, terrainClamped, cartos, sampled, finalPositions;
|
|
80
|
+
return _regeneratorRuntime().wrap(function _loop$(_context) {
|
|
81
|
+
while (1) switch (_context.prev = _context.next) {
|
|
82
|
+
case 0:
|
|
83
|
+
positions = source[i].positions;
|
|
84
|
+
ring = utils.buildPolygonHierarchy(positions).positions;
|
|
85
|
+
/* ---------------------------------- */
|
|
86
|
+
/* 1. 局部切平面 */
|
|
87
|
+
/* ---------------------------------- */
|
|
88
|
+
center = Cesium.BoundingSphere.fromPoints(ring).center;
|
|
89
|
+
plane = new Cesium.EllipsoidTangentPlane(center, Cesium.Ellipsoid.WGS84);
|
|
90
|
+
poly2D = ring.map(function (p) {
|
|
91
|
+
return plane.projectPointOntoPlane(p);
|
|
92
|
+
});
|
|
93
|
+
/* ---------------------------------- */
|
|
94
|
+
/* 2. 包围盒 */
|
|
95
|
+
/* ---------------------------------- */
|
|
96
|
+
minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
97
|
+
_iterator = _createForOfIteratorHelper(poly2D);
|
|
98
|
+
try {
|
|
99
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
100
|
+
p = _step.value;
|
|
101
|
+
minX = Math.min(minX, p.x);
|
|
102
|
+
minY = Math.min(minY, p.y);
|
|
103
|
+
maxX = Math.max(maxX, p.x);
|
|
104
|
+
maxY = Math.max(maxY, p.y);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/* ---------------------------------- */
|
|
108
|
+
/* 3. 自适应采样 */
|
|
109
|
+
/* ---------------------------------- */
|
|
110
|
+
} catch (err) {
|
|
111
|
+
_iterator.e(err);
|
|
112
|
+
} finally {
|
|
113
|
+
_iterator.f();
|
|
114
|
+
}
|
|
115
|
+
gridPoints2D = [];
|
|
116
|
+
edgeFactor = 0.3;
|
|
117
|
+
edgeThreshold = gridSize;
|
|
118
|
+
y = minY;
|
|
119
|
+
case 12:
|
|
120
|
+
if (!(y < maxY)) {
|
|
121
|
+
_context.next = 28;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
x = minX;
|
|
125
|
+
case 14:
|
|
126
|
+
if (!(x < maxX)) {
|
|
127
|
+
_context.next = 25;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
center2D = new Cesium.Cartesian2(x + gridSize * 0.5, y + gridSize * 0.5);
|
|
131
|
+
if (pointInPolygon(center2D, poly2D)) {
|
|
132
|
+
_context.next = 19;
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
x += gridSize;
|
|
136
|
+
return _context.abrupt("continue", 14);
|
|
137
|
+
case 19:
|
|
138
|
+
dist = distanceToPolygonEdge(center2D, poly2D);
|
|
139
|
+
step = dist < edgeThreshold ? gridSize * edgeFactor : gridSize;
|
|
140
|
+
gridPoints2D.push(center2D);
|
|
141
|
+
x += step;
|
|
142
|
+
_context.next = 14;
|
|
143
|
+
break;
|
|
144
|
+
case 25:
|
|
145
|
+
y += gridSize;
|
|
146
|
+
_context.next = 12;
|
|
147
|
+
break;
|
|
148
|
+
case 28:
|
|
149
|
+
/* ---------------------------------- */
|
|
150
|
+
/* 4. 边界插值 */
|
|
151
|
+
/* ---------------------------------- */
|
|
152
|
+
|
|
153
|
+
for (j = 0; j < poly2D.length; j++) {
|
|
154
|
+
a = poly2D[j];
|
|
155
|
+
b = poly2D[(j + 1) % poly2D.length];
|
|
156
|
+
edgeLen = Cesium.Cartesian2.distance(a, b);
|
|
157
|
+
n = Math.ceil(edgeLen / (gridSize * edgeFactor));
|
|
158
|
+
for (k = 0; k <= n; k++) {
|
|
159
|
+
t = k / n;
|
|
160
|
+
gridPoints2D.push(new Cesium.Cartesian2(Cesium.Math.lerp(a.x, b.x, t), Cesium.Math.lerp(a.y, b.y, t)));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/* ---------------------------------- */
|
|
165
|
+
/* 5. Delaunay */
|
|
166
|
+
/* ---------------------------------- */
|
|
167
|
+
delaunay = Delaunay.from(gridPoints2D.map(function (p) {
|
|
168
|
+
return [p.x, p.y];
|
|
169
|
+
}));
|
|
170
|
+
indices = Array.from(delaunay.triangles);
|
|
171
|
+
/* ---------------------------------- */
|
|
172
|
+
/* 6. 回投 3D(无高度) */
|
|
173
|
+
/* ---------------------------------- */
|
|
174
|
+
positions3D = gridPoints2D.map(function (p) {
|
|
175
|
+
return plane.projectPointOntoEllipsoid(p);
|
|
176
|
+
});
|
|
177
|
+
/* ---------------------------------- */
|
|
178
|
+
/* 7. 贴模型(优先) */
|
|
179
|
+
/* ---------------------------------- */
|
|
180
|
+
// await scene.render();
|
|
181
|
+
modelClamped = null;
|
|
182
|
+
_context.prev = 33;
|
|
183
|
+
_context.next = 36;
|
|
184
|
+
return scene.clampToHeightMostDetailed(JSON.parse(JSON.stringify(positions3D)));
|
|
185
|
+
case 36:
|
|
186
|
+
modelClamped = _context.sent;
|
|
187
|
+
_context.next = 42;
|
|
188
|
+
break;
|
|
189
|
+
case 39:
|
|
190
|
+
_context.prev = 39;
|
|
191
|
+
_context.t0 = _context["catch"](33);
|
|
192
|
+
modelClamped = null;
|
|
193
|
+
case 42:
|
|
194
|
+
/* ---------------------------------- */
|
|
195
|
+
/* 8. terrain fallback(只给失败点) */
|
|
196
|
+
/* ---------------------------------- */
|
|
197
|
+
needTerrain = !modelClamped || modelClamped.some(function (p) {
|
|
198
|
+
return !Cesium.defined(p);
|
|
199
|
+
});
|
|
200
|
+
terrainClamped = null;
|
|
201
|
+
if (!needTerrain) {
|
|
202
|
+
_context.next = 50;
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
cartos = JSON.parse(JSON.stringify(positions3D)).map(function (p) {
|
|
206
|
+
return Cesium.Cartographic.fromCartesian(p);
|
|
207
|
+
});
|
|
208
|
+
_context.next = 48;
|
|
209
|
+
return Cesium.sampleTerrainMostDetailed(map.terrainProvider, cartos);
|
|
210
|
+
case 48:
|
|
211
|
+
sampled = _context.sent;
|
|
212
|
+
terrainClamped = sampled.map(function (c) {
|
|
213
|
+
return Cesium.Cartesian3.fromRadians(c.longitude, c.latitude, c.height);
|
|
214
|
+
});
|
|
215
|
+
case 50:
|
|
216
|
+
/* ---------------------------------- */
|
|
217
|
+
/* 9. 合并结果(模型优先,terrain 兜底) */
|
|
218
|
+
/* ---------------------------------- */
|
|
219
|
+
finalPositions = positions3D.map(function (_, idx) {
|
|
220
|
+
var p = modelClamped && Cesium.defined(modelClamped[idx]) ? modelClamped[idx] : terrainClamped ? terrainClamped[idx] : null;
|
|
221
|
+
if (!p) return null;
|
|
222
|
+
var carto = Cesium.Cartographic.fromCartesian(p);
|
|
223
|
+
return Cesium.Cartesian3.fromRadians(carto.longitude, carto.latitude, carto.height + heightBuffer);
|
|
224
|
+
});
|
|
225
|
+
if (!finalPositions.some(function (p) {
|
|
226
|
+
return !p;
|
|
227
|
+
})) {
|
|
228
|
+
_context.next = 54;
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
console.warn('存在无法贴地/贴模型的点,已跳过该 polygon');
|
|
232
|
+
return _context.abrupt("return", 1);
|
|
233
|
+
case 54:
|
|
234
|
+
finalSource.push(_objectSpread(_objectSpread({}, source[i]), {}, {
|
|
235
|
+
positions: finalPositions,
|
|
236
|
+
indices: indices
|
|
237
|
+
}));
|
|
238
|
+
case 55:
|
|
239
|
+
case "end":
|
|
240
|
+
return _context.stop();
|
|
241
|
+
}
|
|
242
|
+
}, _loop, null, [[33, 39]]);
|
|
243
|
+
});
|
|
244
|
+
i = 0;
|
|
245
|
+
case 10:
|
|
246
|
+
if (!(i < source.length)) {
|
|
247
|
+
_context2.next = 17;
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
return _context2.delegateYield(_loop(), "t0", 12);
|
|
251
|
+
case 12:
|
|
252
|
+
if (!_context2.t0) {
|
|
253
|
+
_context2.next = 14;
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
return _context2.abrupt("continue", 14);
|
|
257
|
+
case 14:
|
|
258
|
+
i++;
|
|
259
|
+
_context2.next = 10;
|
|
260
|
+
break;
|
|
261
|
+
case 17:
|
|
262
|
+
return _context2.abrupt("return", {
|
|
263
|
+
type: 'clampedPolygonGrid',
|
|
264
|
+
source: finalSource
|
|
265
|
+
});
|
|
266
|
+
case 18:
|
|
267
|
+
case "end":
|
|
268
|
+
return _context2.stop();
|
|
269
|
+
}
|
|
270
|
+
}, _callee);
|
|
271
|
+
}));
|
|
272
|
+
return _BuildClampedPolygonGridUnified.apply(this, arguments);
|
|
273
|
+
}
|
package/dist/esm/tool/utils.d.ts
CHANGED
|
@@ -11,6 +11,11 @@ export declare const arrCartesian3: (data: any[]) => Cesium.Cartesian3;
|
|
|
11
11
|
export declare const toDegrees: (radians: number, precision?: number) => number;
|
|
12
12
|
export declare const toRadians: (degrees: number) => number;
|
|
13
13
|
export declare const lngLatAltToCartographic: (lng: number, lat: number, alt?: number) => Cesium.Cartographic;
|
|
14
|
+
export declare const cartographicToLngLatAlt: (cartographic: any) => {
|
|
15
|
+
lng: number;
|
|
16
|
+
lat: number;
|
|
17
|
+
alt: any;
|
|
18
|
+
};
|
|
14
19
|
export declare const cartesian3ToLngLatAlt: (cartesian3: any) => {
|
|
15
20
|
lng: number;
|
|
16
21
|
lat: number;
|
|
@@ -18,6 +23,8 @@ export declare const cartesian3ToLngLatAlt: (cartesian3: any) => {
|
|
|
18
23
|
};
|
|
19
24
|
export declare const lngLatAltToCartesian3: (lng: number, lat: number, alt?: number) => Cesium.Cartesian3;
|
|
20
25
|
export declare const lngLatAltArrayToCartesian3Array: (lngLatAltArray: any[]) => Cesium.Cartesian3[];
|
|
26
|
+
export declare const cartesian3ToCartographic: (cartesian3: any) => Cesium.Cartographic;
|
|
27
|
+
export declare const cartographicToCartesian3: (cartographic: any) => Cesium.Cartesian3;
|
|
21
28
|
export declare const isWKT: (str: string) => boolean;
|
|
22
29
|
export declare const styleFun: (style: any, properties: any) => any;
|
|
23
30
|
export declare const dateToJulianDate: (date: Date) => Cesium.JulianDate;
|
|
@@ -63,3 +70,5 @@ export declare function getMidpoint(position1: Cartesian3, position2: Cartesian3
|
|
|
63
70
|
lat: number;
|
|
64
71
|
alt: number;
|
|
65
72
|
};
|
|
73
|
+
export declare function densifyLine(p1: Cartesian3, p2: Cartesian3, count?: number): Cesium.Cartesian3[];
|
|
74
|
+
export declare function isTerrainReady(map: any): Promise<void>;
|
package/dist/esm/tool/utils.js
CHANGED
|
@@ -149,6 +149,15 @@ export var lngLatAltToCartographic = function lngLatAltToCartographic(lng, lat)
|
|
|
149
149
|
return Cesium.Cartographic.fromDegrees(lng, lat, alt);
|
|
150
150
|
};
|
|
151
151
|
|
|
152
|
+
// Cartographic转经纬度
|
|
153
|
+
export var cartographicToLngLatAlt = function cartographicToLngLatAlt(cartographic) {
|
|
154
|
+
return {
|
|
155
|
+
lng: toDegrees(cartographic.longitude),
|
|
156
|
+
lat: toDegrees(cartographic.latitude),
|
|
157
|
+
alt: cartographic.height || 0
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
|
|
152
161
|
// Cartesian3转经纬度
|
|
153
162
|
export var cartesian3ToLngLatAlt = function cartesian3ToLngLatAlt(cartesian3) {
|
|
154
163
|
var cartographic = Cesium.Cartographic.fromCartesian(cartesian3);
|
|
@@ -178,6 +187,16 @@ export var lngLatAltArrayToCartesian3Array = function lngLatAltArrayToCartesian3
|
|
|
178
187
|
return Cesium.Cartesian3.fromDegreesArrayHeights(lngLatAltArrayString);
|
|
179
188
|
};
|
|
180
189
|
|
|
190
|
+
// Cartesian3转Cartographic
|
|
191
|
+
export var cartesian3ToCartographic = function cartesian3ToCartographic(cartesian3) {
|
|
192
|
+
return Cesium.Cartographic.fromCartesian(cartesian3);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// Cartographic转Cartesian3
|
|
196
|
+
export var cartographicToCartesian3 = function cartographicToCartesian3(cartographic) {
|
|
197
|
+
return Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, cartographic.height);
|
|
198
|
+
};
|
|
199
|
+
|
|
181
200
|
// 是否是wkt类型的字符串
|
|
182
201
|
export var isWKT = function isWKT(str) {
|
|
183
202
|
return str.startsWith('POINT') || str.startsWith('LINESTRING') || str.startsWith('POLYGON') || str.startsWith('MULTIPOINT') || str.startsWith('MULTILINESTRING') || str.startsWith('GEOMETRYCOLLECTION');
|
|
@@ -448,4 +467,35 @@ export function getMidpoint(position1, position2) {
|
|
|
448
467
|
lat: lat,
|
|
449
468
|
alt: alt
|
|
450
469
|
};
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// 对两点间进行插值
|
|
473
|
+
export function densifyLine(p1, p2) {
|
|
474
|
+
var count = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 10;
|
|
475
|
+
var result = [];
|
|
476
|
+
for (var i = 0; i <= count; i++) {
|
|
477
|
+
result.push(Cesium.Cartesian3.lerp(p1, p2, i / count, new Cesium.Cartesian3()));
|
|
478
|
+
}
|
|
479
|
+
return result;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// 判断地形是否加载完成
|
|
483
|
+
export function isTerrainReady(map) {
|
|
484
|
+
return new Promise(function (resolve) {
|
|
485
|
+
if (!map.scene.globe || !map.scene.terrainProvider) {
|
|
486
|
+
resolve();
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
if (map.scene.globe.tilesLoaded) {
|
|
490
|
+
resolve();
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
var remove = map.scene.postRender.addEventListener(function () {
|
|
494
|
+
if (map.scene.globe.tilesLoaded) {
|
|
495
|
+
remove();
|
|
496
|
+
resolve();
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
map.scene.requestRender();
|
|
500
|
+
});
|
|
451
501
|
}
|
|
@@ -157,8 +157,10 @@ var BaseVideo = /*#__PURE__*/function () {
|
|
|
157
157
|
}, {
|
|
158
158
|
key: "_drawCanvas",
|
|
159
159
|
value: function _drawCanvas(options) {
|
|
160
|
-
var
|
|
161
|
-
|
|
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
|
-
|
|
174
|
+
if (edgeFeather) {
|
|
175
|
+
ctx.globalCompositeOperation = 'destination-in'; // 使用遮罩影响透明度
|
|
173
176
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
4
|
+
private _videoOptions;
|
|
5
|
+
private _preRenderEvent;
|
|
6
6
|
constructor(map: any, options: any);
|
|
7
|
-
addToMap():
|
|
7
|
+
addToMap(): Promise<unknown>;
|
|
8
|
+
private _create;
|
|
8
9
|
show(isShow: boolean): void;
|
|
9
|
-
private
|
|
10
|
-
private _getInterPointByLine;
|
|
10
|
+
private _getInterPointByRayTerrain;
|
|
11
11
|
destroy(): void;
|
|
12
12
|
}
|