deeptwins-engine-3d 0.0.43 → 0.0.45
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/cameraControl/ModelRoamHistory.d.ts +11 -3
- package/dist/cameraControl/ModelRoamHistory.js +101 -27
- package/dist/cameraControl/ModelRoamRealTime.d.ts +23 -47
- package/dist/cameraControl/ModelRoamRealTime.js +210 -374
- package/dist/constant.d.ts +3 -1
- package/dist/constant.js +4 -20
- package/dist/deepTwins/index.d.ts +0 -3
- package/dist/deepTwins/index.js +2 -18
- package/dist/drawer/base.js +1 -1
- package/dist/drawer/index.js +1 -1
- package/dist/graphicLayer/BaseLayer.d.ts +1 -1
- package/dist/graphicLayer/BaseLayer.js +1 -1
- package/dist/graphicLayer/BaseSource.d.ts +1 -1
- package/dist/graphicLayer/BaseSource.js +4 -6
- package/dist/graphicLayer/GraphicLayerCollection.d.ts +3 -2
- package/dist/graphicLayer/GraphicLayerCollection.js +33 -40
- package/dist/graphicLayer/PolylinePrimitiveInstance.js +2 -6
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -3
- package/dist/map/Map.d.ts +1 -1
- package/dist/map/Map.js +12 -6
- package/dist/material/CircleWaveMaterialProperty.js +2 -3
- package/dist/material/DynamicWallMaterialProperty.js +2 -3
- package/dist/material/PolylineTrailLinkMaterialProperty.js +2 -3
- package/dist/material/WeatherEffects.js +6 -3
- package/package.json +2 -1
- package/dist/cameraControl/ModelRoamRunTime.d.ts +0 -32
- package/dist/cameraControl/ModelRoamRunTime.js +0 -244
|
@@ -1,9 +1,9 @@
|
|
|
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
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
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; }
|
|
6
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 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); } }
|
|
6
|
+
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); }); }; }
|
|
7
7
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
8
|
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); } }
|
|
9
9
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
@@ -11,8 +11,11 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
11
11
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
12
|
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); }
|
|
13
13
|
import * as Cesium from 'deeptwins-cesium';
|
|
14
|
+
import { cloneDeep, merge } from 'lodash';
|
|
14
15
|
import { v4 as uuidv4 } from 'uuid';
|
|
15
|
-
import * as
|
|
16
|
+
import * as constant from "../constant";
|
|
17
|
+
import { colorString } from "../tool/utils";
|
|
18
|
+
|
|
16
19
|
/**
|
|
17
20
|
* 位置信息
|
|
18
21
|
*/
|
|
@@ -27,154 +30,142 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
27
30
|
_classCallCheck(this, ModelRoamRealTime);
|
|
28
31
|
//传入的参数
|
|
29
32
|
_defineProperty(this, "_map", void 0);
|
|
30
|
-
|
|
31
|
-
_defineProperty(this, "polylineLayer", void 0);
|
|
33
|
+
// 模型参数
|
|
32
34
|
_defineProperty(this, "modelOptions", void 0);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
_defineProperty(this, "follow", 'third');
|
|
38
|
-
_defineProperty(this, "flyTo", false);
|
|
35
|
+
// 轨迹参数
|
|
36
|
+
_defineProperty(this, "polylineOptions", void 0);
|
|
37
|
+
// 视角
|
|
38
|
+
_defineProperty(this, "follow", null);
|
|
39
39
|
// 是否定位到模型位置
|
|
40
|
-
_defineProperty(this, "
|
|
41
|
-
//
|
|
42
|
-
_defineProperty(this, "
|
|
43
|
-
//
|
|
44
|
-
_defineProperty(this, "
|
|
45
|
-
//
|
|
40
|
+
_defineProperty(this, "flyTo", false);
|
|
41
|
+
// 位置更新触发回调
|
|
42
|
+
_defineProperty(this, "_onPositionUpdate", null);
|
|
43
|
+
// 模型layer
|
|
44
|
+
_defineProperty(this, "modelLayer", void 0);
|
|
45
|
+
// 轨迹layer
|
|
46
|
+
_defineProperty(this, "polylineLayer", void 0);
|
|
47
|
+
// 所有位置信息点
|
|
46
48
|
_defineProperty(this, "positions", []);
|
|
47
|
-
//
|
|
49
|
+
// 所有轨迹位置信息点 Cartesian3
|
|
50
|
+
_defineProperty(this, "positionsLineC3", []);
|
|
51
|
+
// 插值后的位置信息点 Cartesian3
|
|
52
|
+
_defineProperty(this, "positionInterC3", []);
|
|
53
|
+
// 帧率更新的事件
|
|
54
|
+
_defineProperty(this, "_eventPreUpdate", void 0);
|
|
48
55
|
// 模型参数
|
|
49
|
-
_defineProperty(this, "modelMatrix", new Cesium.Matrix4());
|
|
50
56
|
// 模型变换矩阵
|
|
51
|
-
_defineProperty(this, "
|
|
57
|
+
_defineProperty(this, "modelMatrix", new Cesium.Matrix4());
|
|
52
58
|
// 模型姿态
|
|
53
|
-
_defineProperty(this, "
|
|
54
|
-
// 坐标转换函数
|
|
59
|
+
_defineProperty(this, "hpRoll", new Cesium.HeadingPitchRoll());
|
|
55
60
|
// 漫游相关
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
// 上个点位的时间
|
|
62
|
+
_defineProperty(this, "_time", new Date().getTime());
|
|
63
|
+
// 状态
|
|
64
|
+
_defineProperty(this, "status", 'stop');
|
|
59
65
|
// 当前漫游路径点索引
|
|
60
|
-
_defineProperty(this, "
|
|
66
|
+
_defineProperty(this, "currentPathIndex", 0);
|
|
61
67
|
// 最大路径点索引
|
|
62
|
-
_defineProperty(this, "
|
|
63
|
-
// 是否正在移动到目标点
|
|
64
|
-
_defineProperty(this, "targetHeading", 0);
|
|
68
|
+
_defineProperty(this, "maxPathIndex", 0);
|
|
65
69
|
// 目标朝向角度
|
|
66
|
-
_defineProperty(this, "
|
|
70
|
+
_defineProperty(this, "targetHeading", 0);
|
|
67
71
|
// 当前朝向角度
|
|
68
|
-
_defineProperty(this, "
|
|
72
|
+
_defineProperty(this, "currentHeading", 0);
|
|
69
73
|
// 转向速度(弧度/帧)
|
|
70
|
-
|
|
71
|
-
_defineProperty(this, "keyState", {});
|
|
72
|
-
// 存储按键状态
|
|
73
|
-
_defineProperty(this, "keyStep", 1);
|
|
74
|
-
// 每次按键的步进值
|
|
74
|
+
_defineProperty(this, "rotationSpeed", 0.05);
|
|
75
75
|
// 第一人称视角设置
|
|
76
|
-
_defineProperty(this, "
|
|
76
|
+
_defineProperty(this, "firstCameraSettings", {
|
|
77
77
|
distance: 0,
|
|
78
|
-
height: 0,
|
|
79
78
|
pitch: -45
|
|
80
79
|
});
|
|
81
80
|
// 第三人称视角设置
|
|
82
81
|
_defineProperty(this, "thirdPersonSettings", {
|
|
83
|
-
distance:
|
|
84
|
-
|
|
85
|
-
pitch: -85
|
|
82
|
+
distance: 500,
|
|
83
|
+
pitch: -45
|
|
86
84
|
});
|
|
87
85
|
/**
|
|
88
86
|
* 渲染回调函数
|
|
89
87
|
* 更新模型位置、朝向和路径线
|
|
90
|
-
* @param scene Cesium场景
|
|
91
|
-
* @param time 当前时间
|
|
92
88
|
*/
|
|
93
89
|
_defineProperty(this, "updateModel", function () {
|
|
94
90
|
if (_this.currentPathIndex >= _this.maxPathIndex) {
|
|
95
|
-
_this.isMovingToTarget = false;
|
|
96
91
|
return;
|
|
97
92
|
}
|
|
98
|
-
if (_this.currentPathIndex > 0 && _this.currentPathIndex < _this.
|
|
99
|
-
_this.getHeading(_this.
|
|
93
|
+
if (_this.currentPathIndex > 0 && _this.currentPathIndex < _this.positionInterC3.length - 1 && !_this.positionInterC3[_this.currentPathIndex - 1].equals(_this.positionInterC3[_this.currentPathIndex])) {
|
|
94
|
+
_this.getHeading(_this.positionInterC3[_this.currentPathIndex - 1], _this.positionInterC3[_this.currentPathIndex]);
|
|
100
95
|
}
|
|
101
96
|
// 更新朝向
|
|
102
97
|
_this.updateHeading();
|
|
103
|
-
var currentPos = _this.
|
|
104
|
-
if (!_this.
|
|
98
|
+
var currentPos = _this.positionInterC3[_this.currentPathIndex];
|
|
99
|
+
if (!_this.positionsLineC3.some(function (pos) {
|
|
105
100
|
return pos.equals(currentPos);
|
|
106
101
|
})) {
|
|
107
|
-
_this.
|
|
108
|
-
if (_this.
|
|
109
|
-
|
|
102
|
+
_this.positionsLineC3.push(currentPos);
|
|
103
|
+
if (_this.positions.length > 1) {
|
|
104
|
+
// 更新轨迹
|
|
105
|
+
_this.polylineLayer && _this._map.scene.primitives.remove(_this.polylineLayer);
|
|
110
106
|
var trailGeometry = new Cesium.GeometryInstance({
|
|
111
107
|
id: '_modelRoamRealTimePolyline',
|
|
112
108
|
geometry: new Cesium.PolylineGeometry({
|
|
113
|
-
positions: _this.
|
|
109
|
+
positions: _this.positionsLineC3,
|
|
114
110
|
width: _this.polylineOptions.width,
|
|
115
111
|
vertexFormat: Cesium.PolylineMaterialAppearance.VERTEX_FORMAT
|
|
116
112
|
})
|
|
117
113
|
});
|
|
118
114
|
_this.polylineLayer = _this._map.scene.primitives.add(new Cesium.Primitive({
|
|
119
115
|
geometryInstances: trailGeometry,
|
|
120
|
-
appearance: _this.polylineLayer.appearance
|
|
116
|
+
appearance: _this.polylineLayer ? _this.polylineLayer.appearance : new Cesium.PolylineMaterialAppearance({
|
|
117
|
+
material: new Cesium.Material({
|
|
118
|
+
fabric: {
|
|
119
|
+
type: 'Color',
|
|
120
|
+
uniforms: {
|
|
121
|
+
color: colorString(_this.polylineOptions.color)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
}),
|
|
121
126
|
asynchronous: false
|
|
122
127
|
}));
|
|
123
128
|
}
|
|
124
129
|
}
|
|
125
|
-
if (_this.modelLayer && _this.currentPathIndex < _this.
|
|
126
|
-
|
|
127
|
-
|
|
130
|
+
if (_this.modelLayer && _this.currentPathIndex < _this.positionInterC3.length) {
|
|
131
|
+
// 更新模型位置
|
|
132
|
+
var _position = _this.positionInterC3[_this.currentPathIndex];
|
|
133
|
+
_this.modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(_position, _this.hpRoll, Cesium.Ellipsoid.WGS84, Cesium.Transforms.localFrameToFixedFrameGenerator('north', 'west'));
|
|
128
134
|
_this.modelLayer.modelMatrix = _this.modelMatrix;
|
|
129
135
|
|
|
130
136
|
// 调用位置更新回调
|
|
131
|
-
if (_this.
|
|
137
|
+
if (_this._onPositionUpdate) {
|
|
132
138
|
var cartographic = Cesium.Cartographic.fromCartesian(_position);
|
|
133
|
-
_this.
|
|
139
|
+
_this._onPositionUpdate({
|
|
134
140
|
lon: Cesium.Math.toDegrees(cartographic.longitude),
|
|
135
141
|
lat: Cesium.Math.toDegrees(cartographic.latitude),
|
|
136
142
|
height: cartographic.height
|
|
137
143
|
});
|
|
138
144
|
}
|
|
139
|
-
_this.
|
|
145
|
+
if (_this.follow) {
|
|
146
|
+
_this.updateCameraView();
|
|
147
|
+
}
|
|
140
148
|
}
|
|
141
149
|
_this.currentPathIndex++;
|
|
142
150
|
});
|
|
143
|
-
/**
|
|
144
|
-
* 处理按键按下事件
|
|
145
|
-
*/
|
|
146
|
-
_defineProperty(this, "handleKeyDown", function (event) {
|
|
147
|
-
_this.keyState[event.key.toLowerCase()] = true;
|
|
148
|
-
});
|
|
149
|
-
/**
|
|
150
|
-
* 处理按键释放事件
|
|
151
|
-
*/
|
|
152
|
-
_defineProperty(this, "handleKeyUp", function (event) {
|
|
153
|
-
_this.keyState[event.key.toLowerCase()] = false;
|
|
154
|
-
});
|
|
155
151
|
var _ref = options || {},
|
|
156
152
|
model = _ref.model,
|
|
157
153
|
polyline = _ref.polyline,
|
|
158
|
-
follow = _ref.follow,
|
|
159
154
|
onPositionUpdate = _ref.onPositionUpdate,
|
|
160
155
|
flyTo = _ref.flyTo;
|
|
161
156
|
if (!map) {
|
|
162
|
-
throw new Error('undefined
|
|
163
|
-
return;
|
|
157
|
+
throw new Error('undefined map');
|
|
164
158
|
}
|
|
165
159
|
if (!options.model && !((_options$model = options.model) !== null && _options$model !== void 0 && _options$model.url)) {
|
|
166
160
|
throw new Error('undefined model');
|
|
167
|
-
return;
|
|
168
161
|
}
|
|
169
162
|
this._map = map;
|
|
170
|
-
this.fixedFrameTransform = Cesium.Transforms.localFrameToFixedFrameGenerator('north', 'west');
|
|
171
163
|
this.modelOptions = model;
|
|
172
|
-
this.polylineOptions =
|
|
173
|
-
this.follow = follow ? follow : 'third';
|
|
164
|
+
this.polylineOptions = merge(constant.DEFAULT_POLYLINE_PRIMITIVE_OPTIONS(), cloneDeep(polyline || {}));
|
|
174
165
|
this.flyTo = flyTo || false;
|
|
175
|
-
this.
|
|
176
|
-
this.initKeyboardControls();
|
|
166
|
+
this._onPositionUpdate = onPositionUpdate;
|
|
177
167
|
}
|
|
168
|
+
|
|
178
169
|
/**
|
|
179
170
|
* 实时添加点位
|
|
180
171
|
* @param newPosition 新位置点
|
|
@@ -182,266 +173,165 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
182
173
|
*/
|
|
183
174
|
_createClass(ModelRoamRealTime, [{
|
|
184
175
|
key: "updatePosition",
|
|
185
|
-
value:
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
if (!(this.linePath.length === 0)) {
|
|
192
|
-
_context.next = 3;
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
this.initModel(newPosition);
|
|
196
|
-
return _context.abrupt("return");
|
|
197
|
-
case 3:
|
|
198
|
-
// 获取最后一个目标点的位置(而不是当前飞行位置)
|
|
199
|
-
lastTargetPos = this.positions[this.positions.length - 1];
|
|
200
|
-
if (!lastTargetPos) {
|
|
201
|
-
_context.next = 7;
|
|
202
|
-
break;
|
|
203
|
-
}
|
|
204
|
-
if (!(newPosition.lng === lastTargetPos.lng && newPosition.lat === lastTargetPos.lat && Math.abs(newPosition.alt - lastTargetPos.alt) < 0.1)) {
|
|
205
|
-
_context.next = 7;
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
return _context.abrupt("return");
|
|
209
|
-
case 7:
|
|
210
|
-
// 将新位置添加到目标点数组
|
|
211
|
-
this.positions.push(_objectSpread({}, newPosition));
|
|
176
|
+
value: function updatePosition(newPosition) {
|
|
177
|
+
if (this.status === 'destroy') return;
|
|
178
|
+
if (!this.positions.length) {
|
|
179
|
+
this.initModel(newPosition);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
212
182
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return _context.stop();
|
|
239
|
-
}
|
|
240
|
-
}, _callee, this);
|
|
241
|
-
}));
|
|
242
|
-
function updatePosition(_x) {
|
|
243
|
-
return _updatePosition.apply(this, arguments);
|
|
183
|
+
// 获取最后一个目标点的位置(而不是当前飞行位置)
|
|
184
|
+
var lastTargetPos = this.positions[this.positions.length - 1];
|
|
185
|
+
if (lastTargetPos) {
|
|
186
|
+
if (newPosition.lng === lastTargetPos.lng && newPosition.lat === lastTargetPos.lat && Math.abs(newPosition.alt - lastTargetPos.alt) < 0.1) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// 将新位置添加到目标点数组
|
|
192
|
+
this.positions.push(newPosition);
|
|
193
|
+
|
|
194
|
+
// 从最后一个目标点计算到新点的路径
|
|
195
|
+
var lastPos = Cesium.Cartesian3.fromDegrees(lastTargetPos.lng, lastTargetPos.lat, lastTargetPos.alt);
|
|
196
|
+
var newPos = Cesium.Cartesian3.fromDegrees(newPosition.lng, newPosition.lat, newPosition.alt);
|
|
197
|
+
|
|
198
|
+
// 飞行时间
|
|
199
|
+
var newTime = new Date().getTime();
|
|
200
|
+
var flightTime = (newTime - this._time) / 1000;
|
|
201
|
+
this._time = newTime;
|
|
202
|
+
var newPath = this._getInterPosition(lastPos, newPos, flightTime);
|
|
203
|
+
if (this.status === 'running') {
|
|
204
|
+
this.positionInterC3 = this.positionInterC3.concat(newPath);
|
|
205
|
+
this.maxPathIndex = this.positionInterC3.length;
|
|
206
|
+
} else {
|
|
207
|
+
this.currentPathIndex = 0;
|
|
244
208
|
}
|
|
245
|
-
|
|
246
|
-
}()
|
|
209
|
+
}
|
|
247
210
|
/**
|
|
248
211
|
* 计算两点之间的路径点
|
|
249
212
|
* 使用插值算法生成平滑的路径
|
|
250
213
|
* @param startP 起始点
|
|
251
214
|
* @param endP 终点
|
|
215
|
+
* @param flightTime 飞行时间
|
|
252
216
|
* @returns 插值后的路径点数组
|
|
253
217
|
*/
|
|
254
|
-
)
|
|
255
218
|
}, {
|
|
256
|
-
key: "
|
|
257
|
-
value:
|
|
258
|
-
var
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
var startCartographic = Cesium.Cartographic.fromCartesian(startP);
|
|
270
|
-
var endCartographic = Cesium.Cartographic.fromCartesian(endP);
|
|
271
|
-
var startLonLat = [Cesium.Math.toDegrees(startCartographic.longitude), Cesium.Math.toDegrees(startCartographic.latitude)];
|
|
272
|
-
var endLonLat = [Cesium.Math.toDegrees(endCartographic.longitude), Cesium.Math.toDegrees(endCartographic.latitude)];
|
|
273
|
-
|
|
274
|
-
// 计算水平距离和高度差
|
|
275
|
-
var heightDiff = endCartographic.height - startCartographic.height;
|
|
276
|
-
var horizontalDistance = Cesium.Cartesian3.distance(Cesium.Cartesian3.fromDegrees(startLonLat[0], startLonLat[1], startCartographic.height), Cesium.Cartesian3.fromDegrees(endLonLat[0], endLonLat[1], startCartographic.height));
|
|
219
|
+
key: "_getInterPosition",
|
|
220
|
+
value: function _getInterPosition(startP, endP, flightTime) {
|
|
221
|
+
var arr = [];
|
|
222
|
+
if (!startP || !endP) {
|
|
223
|
+
console.error('Invalid start or end position');
|
|
224
|
+
return arr;
|
|
225
|
+
}
|
|
226
|
+
var startCartographic = Cesium.Cartographic.fromCartesian(startP);
|
|
227
|
+
var endCartographic = Cesium.Cartographic.fromCartesian(endP);
|
|
228
|
+
var startLonLat = [Cesium.Math.toDegrees(startCartographic.longitude), Cesium.Math.toDegrees(startCartographic.latitude)];
|
|
229
|
+
var endLonLat = [Cesium.Math.toDegrees(endCartographic.longitude), Cesium.Math.toDegrees(endCartographic.latitude)];
|
|
277
230
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
arr.push(startP);
|
|
282
|
-
resolve(arr);
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
231
|
+
// 计算水平距离和高度差
|
|
232
|
+
var heightDiff = endCartographic.height - startCartographic.height;
|
|
233
|
+
var horizontalDistance = Cesium.Cartesian3.distance(Cesium.Cartesian3.fromDegrees(startLonLat[0], startLonLat[1], startCartographic.height), Cesium.Cartesian3.fromDegrees(endLonLat[0], endLonLat[1], startCartographic.height));
|
|
285
234
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
235
|
+
// 计算总距离
|
|
236
|
+
var totalDistance = Math.sqrt(horizontalDistance * horizontalDistance + heightDiff * heightDiff);
|
|
237
|
+
if (totalDistance === 0) {
|
|
238
|
+
arr.push(startP);
|
|
239
|
+
return arr;
|
|
240
|
+
}
|
|
289
241
|
|
|
290
|
-
|
|
291
|
-
|
|
242
|
+
// 设置无人机飞行参数
|
|
243
|
+
var updateRate = 60; // 每秒更新次数
|
|
292
244
|
|
|
293
|
-
|
|
294
|
-
|
|
245
|
+
// 计算总的插值点数
|
|
246
|
+
var numberOfPoints = Math.max(10, Math.floor(flightTime * updateRate));
|
|
295
247
|
|
|
296
|
-
|
|
297
|
-
|
|
248
|
+
// 计算时间步长
|
|
249
|
+
var timeStep = 1.0 / (numberOfPoints - 1);
|
|
298
250
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
251
|
+
// 生成插值点
|
|
252
|
+
for (var i = 0; i < numberOfPoints; i++) {
|
|
253
|
+
var t = i * timeStep;
|
|
302
254
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
255
|
+
// 经纬度线性插值
|
|
256
|
+
var currentLon = startLonLat[0] + (endLonLat[0] - startLonLat[0]) * t;
|
|
257
|
+
var currentLat = startLonLat[1] + (endLonLat[1] - startLonLat[1]) * t;
|
|
306
258
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
259
|
+
// 高度使用余弦插值使过渡更平滑
|
|
260
|
+
var heightFactor = void 0;
|
|
261
|
+
if (Math.abs(heightDiff) > 0.1) {
|
|
262
|
+
// 使用余弦插值使高度变化更平滑
|
|
263
|
+
heightFactor = (1 - Math.cos(t * Math.PI)) / 2;
|
|
264
|
+
} else {
|
|
265
|
+
// 高度差很小时使用线性插值
|
|
266
|
+
heightFactor = t;
|
|
267
|
+
}
|
|
268
|
+
var currentHeight = startCartographic.height + heightDiff * heightFactor;
|
|
317
269
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
270
|
+
// 创建当前位置的笛卡尔坐标
|
|
271
|
+
var pos = Cesium.Cartesian3.fromDegrees(currentLon, currentLat, currentHeight);
|
|
272
|
+
arr.push(pos);
|
|
273
|
+
}
|
|
322
274
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}
|
|
327
|
-
resolve(arr);
|
|
328
|
-
}));
|
|
329
|
-
case 1:
|
|
330
|
-
case "end":
|
|
331
|
-
return _context2.stop();
|
|
332
|
-
}
|
|
333
|
-
}, _callee2);
|
|
334
|
-
}));
|
|
335
|
-
function getPosition(_x2, _x3) {
|
|
336
|
-
return _getPosition.apply(this, arguments);
|
|
275
|
+
// 确保最后一个点精确匹配终点
|
|
276
|
+
if (!arr[arr.length - 1].equals(endP)) {
|
|
277
|
+
arr.push(endP);
|
|
337
278
|
}
|
|
338
|
-
return
|
|
339
|
-
}
|
|
279
|
+
return arr;
|
|
280
|
+
}
|
|
340
281
|
/**
|
|
341
282
|
* 初始化模型
|
|
342
283
|
* 加载模型
|
|
343
284
|
* @param initialPosition 初始位置
|
|
344
285
|
*/
|
|
345
|
-
)
|
|
346
286
|
}, {
|
|
347
287
|
key: "initModel",
|
|
348
288
|
value: (function () {
|
|
349
|
-
var _initModel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
289
|
+
var _initModel = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(initialPosition) {
|
|
350
290
|
var _this2 = this;
|
|
351
291
|
var pos, model;
|
|
352
|
-
return _regeneratorRuntime().wrap(function
|
|
353
|
-
while (1) switch (
|
|
292
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
293
|
+
while (1) switch (_context.prev = _context.next) {
|
|
354
294
|
case 0:
|
|
355
295
|
// 添加初始位置到目标点数组
|
|
356
|
-
this.positions.push(
|
|
296
|
+
this.positions.push(initialPosition);
|
|
357
297
|
pos = Cesium.Cartesian3.fromDegrees(initialPosition.lng, initialPosition.lat, initialPosition.alt);
|
|
358
|
-
this.
|
|
359
|
-
this.initPolyline();
|
|
298
|
+
this.positionsLineC3 = [pos];
|
|
360
299
|
// 创建模型矩阵
|
|
361
|
-
this.modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(pos, this.hpRoll, Cesium.Ellipsoid.WGS84,
|
|
362
|
-
|
|
300
|
+
this.modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(pos, this.hpRoll, Cesium.Ellipsoid.WGS84, Cesium.Transforms.localFrameToFixedFrameGenerator('north', 'west'));
|
|
301
|
+
_context.next = 6;
|
|
363
302
|
return Cesium.Model.fromGltfAsync(_objectSpread({
|
|
364
303
|
id: uuidv4(),
|
|
365
304
|
modelMatrix: this.modelMatrix
|
|
366
305
|
}, this.modelOptions));
|
|
367
|
-
case
|
|
368
|
-
model =
|
|
306
|
+
case 6:
|
|
307
|
+
model = _context.sent;
|
|
369
308
|
this.modelLayer = this._map.scene.primitives.add(model);
|
|
370
309
|
// 开启动画
|
|
371
310
|
this.modelLayer.readyEvent.addEventListener(function () {
|
|
372
311
|
if (_this2.flyTo) {
|
|
373
|
-
_this2.
|
|
312
|
+
_this2._flyToModel();
|
|
374
313
|
}
|
|
375
314
|
_this2.modelLayer.activeAnimations.addAll({
|
|
376
315
|
loop: Cesium.ModelAnimationLoop.REPEAT,
|
|
377
316
|
multiplier: 2
|
|
378
317
|
});
|
|
379
|
-
_this2.
|
|
318
|
+
if (_this2.status === 'stop') {
|
|
319
|
+
_this2.status = 'running';
|
|
320
|
+
// 监听帧率
|
|
321
|
+
_this2._eventPreUpdate = _this2._map.on(constant.SCENE_EVENT_TYPE.PRE_UPDATE, _this2.updateModel);
|
|
322
|
+
}
|
|
380
323
|
});
|
|
381
|
-
case
|
|
324
|
+
case 9:
|
|
382
325
|
case "end":
|
|
383
|
-
return
|
|
326
|
+
return _context.stop();
|
|
384
327
|
}
|
|
385
|
-
},
|
|
328
|
+
}, _callee, this);
|
|
386
329
|
}));
|
|
387
|
-
function initModel(
|
|
330
|
+
function initModel(_x) {
|
|
388
331
|
return _initModel.apply(this, arguments);
|
|
389
332
|
}
|
|
390
333
|
return initModel;
|
|
391
|
-
}()
|
|
392
|
-
/**
|
|
393
|
-
* 初始化线路
|
|
394
|
-
*/
|
|
395
|
-
)
|
|
396
|
-
}, {
|
|
397
|
-
key: "initPolyline",
|
|
398
|
-
value: function initPolyline() {
|
|
399
|
-
// 创建轨迹线
|
|
400
|
-
var trailAppearance = new Cesium.PolylineMaterialAppearance({
|
|
401
|
-
material: new Cesium.Material({
|
|
402
|
-
fabric: {
|
|
403
|
-
type: 'Color',
|
|
404
|
-
uniforms: {
|
|
405
|
-
color: utils.colorString(this.polylineOptions.color)
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
})
|
|
409
|
-
});
|
|
410
|
-
var trailGeometry = new Cesium.GeometryInstance({
|
|
411
|
-
id: '_modelRoamRealTimePolyline',
|
|
412
|
-
geometry: new Cesium.PolylineGeometry({
|
|
413
|
-
positions: [this.linePath[0], this.linePath[0]],
|
|
414
|
-
width: this.polylineOptions.width,
|
|
415
|
-
vertexFormat: Cesium.PolylineMaterialAppearance.VERTEX_FORMAT
|
|
416
|
-
})
|
|
417
|
-
});
|
|
418
|
-
var polylinePrimitive = new Cesium.Primitive({
|
|
419
|
-
geometryInstances: trailGeometry,
|
|
420
|
-
appearance: trailAppearance,
|
|
421
|
-
asynchronous: false
|
|
422
|
-
});
|
|
423
|
-
this.polylineLayer = this._map.scene.primitives.add(polylinePrimitive);
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* 开始漫游
|
|
427
|
-
*/
|
|
428
|
-
}, {
|
|
429
|
-
key: "startRun",
|
|
430
|
-
value: function startRun() {
|
|
431
|
-
if (this.isRun) return;
|
|
432
|
-
this.isRun = true;
|
|
433
|
-
this._map.scene.preUpdate.addEventListener(this.updateModel);
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
436
|
-
* 结束漫游
|
|
437
|
-
*/
|
|
438
|
-
}, {
|
|
439
|
-
key: "stopRun",
|
|
440
|
-
value: function stopRun() {
|
|
441
|
-
this.isRun = false;
|
|
442
|
-
this._map.scene.preUpdate.removeEventListener(this.updateModel);
|
|
443
|
-
this._map.scene.preRender.removeEventListener(this.updateFirstPersonView);
|
|
444
|
-
}
|
|
334
|
+
}())
|
|
445
335
|
}, {
|
|
446
336
|
key: "getHeading",
|
|
447
337
|
value:
|
|
@@ -499,13 +389,13 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
499
389
|
}, {
|
|
500
390
|
key: "updateCameraView",
|
|
501
391
|
value: function updateCameraView() {
|
|
502
|
-
if (!this.modelLayer || !this.
|
|
392
|
+
if (!this.modelLayer || !this.positionInterC3) {
|
|
503
393
|
return;
|
|
504
394
|
}
|
|
505
|
-
var position = this.
|
|
395
|
+
var position = this.currentPathIndex >= this.positionInterC3.length ? this.positionInterC3[this.positionInterC3.length - 1] : this.positionInterC3[this.currentPathIndex];
|
|
506
396
|
if (this.follow === 'first') {
|
|
507
397
|
this.updateFirstPersonView(position);
|
|
508
|
-
} else {
|
|
398
|
+
} else if (this.follow === 'third') {
|
|
509
399
|
this.updateThirdPersonView(position);
|
|
510
400
|
}
|
|
511
401
|
}
|
|
@@ -521,7 +411,7 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
521
411
|
destination: position,
|
|
522
412
|
orientation: {
|
|
523
413
|
heading: this.hpRoll.heading,
|
|
524
|
-
pitch: Cesium.Math.toRadians(this.
|
|
414
|
+
pitch: Cesium.Math.toRadians(this.firstCameraSettings.pitch),
|
|
525
415
|
roll: 0.0
|
|
526
416
|
}
|
|
527
417
|
});
|
|
@@ -533,100 +423,48 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
533
423
|
}, {
|
|
534
424
|
key: "updateThirdPersonView",
|
|
535
425
|
value: function updateThirdPersonView(position) {
|
|
536
|
-
|
|
537
|
-
var transform = Cesium.Transforms.headingPitchRollToFixedFrame(position, this.hpRoll, Cesium.Ellipsoid.WGS84, this.fixedFrameTransform);
|
|
538
|
-
var offset = new Cesium.Cartesian3(-this.thirdPersonSettings.distance, 0, this.thirdPersonSettings.height);
|
|
539
|
-
var cameraPosition = Cesium.Matrix4.multiplyByPoint(transform, offset, new Cesium.Cartesian3());
|
|
540
|
-
|
|
541
|
-
// 设置相机位置和朝向
|
|
542
|
-
this._map.camera.setView({
|
|
543
|
-
destination: cameraPosition,
|
|
544
|
-
orientation: {
|
|
545
|
-
heading: this.hpRoll.heading,
|
|
546
|
-
pitch: Cesium.Math.toRadians(this.thirdPersonSettings.pitch),
|
|
547
|
-
roll: 0.0
|
|
548
|
-
}
|
|
549
|
-
});
|
|
426
|
+
this._map.camera.lookAt(position, new Cesium.HeadingPitchRange(this.hpRoll.heading, Cesium.Math.toRadians(this.thirdPersonSettings.pitch), this.thirdPersonSettings.distance));
|
|
550
427
|
}
|
|
551
428
|
/**
|
|
552
|
-
*
|
|
553
|
-
* 在第一人称和第三人称之间切换
|
|
429
|
+
* 设置第一人称视角
|
|
554
430
|
*/
|
|
555
431
|
}, {
|
|
556
|
-
key: "
|
|
557
|
-
value: function
|
|
558
|
-
if (
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
if (this.follow === type) {
|
|
562
|
-
return;
|
|
563
|
-
} else {
|
|
564
|
-
this.follow = type;
|
|
565
|
-
}
|
|
432
|
+
key: "setFollowFirst",
|
|
433
|
+
value: function setFollowFirst(options) {
|
|
434
|
+
if (this.status === 'destroy') return;
|
|
435
|
+
this.firstCameraSettings = _objectSpread(_objectSpread({}, this.firstCameraSettings), options);
|
|
436
|
+
this.follow = 'first';
|
|
566
437
|
this.updateCameraView();
|
|
567
438
|
}
|
|
568
439
|
/**
|
|
569
|
-
*
|
|
440
|
+
* 设置第一人称视角
|
|
570
441
|
*/
|
|
571
442
|
}, {
|
|
572
|
-
key: "
|
|
573
|
-
value: function
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
this.
|
|
443
|
+
key: "setFollowThird",
|
|
444
|
+
value: function setFollowThird(options) {
|
|
445
|
+
if (this.status === 'destroy') return;
|
|
446
|
+
this.thirdPersonSettings = _objectSpread(_objectSpread({}, this.thirdPersonSettings), options);
|
|
447
|
+
this.follow = 'third';
|
|
448
|
+
this.updateCameraView();
|
|
577
449
|
}
|
|
578
450
|
/**
|
|
579
|
-
*
|
|
451
|
+
* 取消视角跟随
|
|
580
452
|
*/
|
|
581
453
|
}, {
|
|
582
|
-
key: "
|
|
583
|
-
value: function
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
document.addEventListener('keydown', this.handleKeyDown);
|
|
587
|
-
document.addEventListener('keyup', this.handleKeyUp);
|
|
588
|
-
|
|
589
|
-
// 添加定时器持续更新视角
|
|
590
|
-
setInterval(function () {
|
|
591
|
-
return _this3.updateViewFromKeyboard();
|
|
592
|
-
}, 16); // 约60fps
|
|
454
|
+
key: "cancelFollow",
|
|
455
|
+
value: function cancelFollow() {
|
|
456
|
+
if (this.status === 'destroy') return;
|
|
457
|
+
this.follow = null;
|
|
593
458
|
}
|
|
594
|
-
}, {
|
|
595
|
-
key: "updateViewFromKeyboard",
|
|
596
|
-
value:
|
|
597
459
|
/**
|
|
598
|
-
*
|
|
460
|
+
* 飞行定位到模型
|
|
599
461
|
*/
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
currentSettings.pitch = Math.min(90, currentSettings.pitch + this.keyStep);
|
|
607
|
-
hasChanged = true;
|
|
608
|
-
}
|
|
609
|
-
if (this.keyState['s']) {
|
|
610
|
-
currentSettings.pitch = Math.max(-90, currentSettings.pitch - this.keyStep);
|
|
611
|
-
hasChanged = true;
|
|
612
|
-
}
|
|
613
|
-
if (this.follow === 'third') {
|
|
614
|
-
// 第三视角控制
|
|
615
|
-
// A/D 控制高度
|
|
616
|
-
if (this.keyState['a']) {
|
|
617
|
-
currentSettings.height = Math.max(0, currentSettings.height - this.keyStep);
|
|
618
|
-
hasChanged = true;
|
|
619
|
-
}
|
|
620
|
-
if (this.keyState['d']) {
|
|
621
|
-
currentSettings.height = Math.min(10000, currentSettings.height + this.keyStep);
|
|
622
|
-
hasChanged = true;
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
// 如果设置发生变化,更新视角
|
|
627
|
-
if (hasChanged) {
|
|
628
|
-
this.updateCameraView();
|
|
629
|
-
}
|
|
462
|
+
}, {
|
|
463
|
+
key: "_flyToModel",
|
|
464
|
+
value: function _flyToModel() {
|
|
465
|
+
var boundingSphere = this.modelLayer.boundingSphere;
|
|
466
|
+
boundingSphere.radius = Math.max(boundingSphere.radius || 100);
|
|
467
|
+
this._map.camera.flyToBoundingSphere(boundingSphere);
|
|
630
468
|
}
|
|
631
469
|
/**
|
|
632
470
|
* 监听
|
|
@@ -643,9 +481,9 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
643
481
|
}, {
|
|
644
482
|
key: "destroy",
|
|
645
483
|
value: function destroy() {
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
this.
|
|
484
|
+
if (this.status === 'destroy') return;
|
|
485
|
+
this.status = 'destroy';
|
|
486
|
+
this._eventPreUpdate.off();
|
|
649
487
|
if (this.modelLayer) {
|
|
650
488
|
this._map.scene.primitives.remove(this.modelLayer);
|
|
651
489
|
this.modelLayer = null;
|
|
@@ -655,12 +493,10 @@ var ModelRoamRealTime = /*#__PURE__*/function () {
|
|
|
655
493
|
this.polylineLayer = null;
|
|
656
494
|
}
|
|
657
495
|
this.positions = [];
|
|
658
|
-
this.
|
|
659
|
-
this.
|
|
496
|
+
this.positionsLineC3 = [];
|
|
497
|
+
this.positionInterC3 = [];
|
|
660
498
|
this.currentPathIndex = 0;
|
|
661
499
|
this.maxPathIndex = 0;
|
|
662
|
-
this.isRun = false;
|
|
663
|
-
this.isMovingToTarget = false;
|
|
664
500
|
}
|
|
665
501
|
}]);
|
|
666
502
|
return ModelRoamRealTime;
|