deeptwins-engine-3d 0.1.74 → 0.1.75

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.
@@ -0,0 +1,29 @@
1
+ /*
2
+ object-assign
3
+ (c) Sindre Sorhus
4
+ @license MIT
5
+ */
6
+
7
+ /*! *****************************************************************************
8
+ Copyright (c) Microsoft Corporation. All rights reserved.
9
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
10
+ this file except in compliance with the License. You may obtain a copy of the
11
+ License at http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
15
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
16
+ MERCHANTABLITY OR NON-INFRINGEMENT.
17
+
18
+ See the Apache Version 2.0 License for specific language governing permissions
19
+ and limitations under the License.
20
+ ***************************************************************************** */
21
+
22
+ /**
23
+ * splaytree v3.1.2
24
+ * Fast Splay tree for Node and browser
25
+ *
26
+ * @author Alexander Milevski <info@w8r.name>
27
+ * @license MIT
28
+ * @preserve
29
+ */
package/dist/esm/index.js CHANGED
@@ -73,11 +73,11 @@ DEEP_TWINS_BASE_URL && (window.CESIUM_BASE_URL = DEEP_TWINS_BASE_URL);
73
73
  // 全局加载css
74
74
  loadCss(Cesium.buildModuleUrl('Widgets/widgets.css'));
75
75
  // 打印版本信息
76
- console.log('DeepTwinsEngine3D Version:', "0.1.74");
76
+ console.log('DeepTwinsEngine3D Version:', "0.1.75");
77
77
  export var DeepTwinsEngine3D = /*#__PURE__*/_createClass(function DeepTwinsEngine3D() {
78
78
  _classCallCheck(this, DeepTwinsEngine3D);
79
79
  });
80
- _defineProperty(DeepTwinsEngine3D, "Version", "0.1.74");
80
+ _defineProperty(DeepTwinsEngine3D, "Version", "0.1.75");
81
81
  _defineProperty(DeepTwinsEngine3D, "Map", Map);
82
82
  _defineProperty(DeepTwinsEngine3D, "GroundSkyBox", GroundSkyBox);
83
83
  _defineProperty(DeepTwinsEngine3D, "RasterLayer", RasterLayer);
@@ -0,0 +1,41 @@
1
+ export type CustomRasterClipBounds = [number, number, number, number];
2
+ export type CustomRasterClipFeature = {
3
+ feature: any;
4
+ bbox: CustomRasterClipBounds;
5
+ };
6
+ export type CustomRasterClipResult = {
7
+ status: 'kept';
8
+ reason: 'within-clip';
9
+ } | {
10
+ status: 'discarded';
11
+ reason: 'outside-clip';
12
+ } | {
13
+ status: 'clipped';
14
+ reason: 'intersects-clip';
15
+ paths: number[][][];
16
+ };
17
+ export type CustomRasterClipTaskOptions = {
18
+ tileBbox: CustomRasterClipBounds;
19
+ candidateIndexes: number[];
20
+ width: number;
21
+ height: number;
22
+ };
23
+ interface CustomRasterClipWorkerClientOptions {
24
+ workerUrl?: string;
25
+ features: CustomRasterClipFeature[];
26
+ }
27
+ declare class CustomRasterClipWorkerClient {
28
+ private _worker;
29
+ private _requestId;
30
+ private _pendingTasks;
31
+ constructor(options: CustomRasterClipWorkerClientOptions);
32
+ clip(options: CustomRasterClipTaskOptions): Promise<CustomRasterClipResult>;
33
+ destroy(): void;
34
+ private _init;
35
+ private _handleMessage;
36
+ private _handleError;
37
+ private _shutdown;
38
+ private _failAllPending;
39
+ private _toError;
40
+ }
41
+ export default CustomRasterClipWorkerClient;
@@ -0,0 +1,147 @@
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 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; }
3
+ 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; }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ 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); } }
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ 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; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
+ 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); }
10
+ import { getDeepTwinsFile } from "../tool/utils";
11
+ var DEFAULT_CUSTOM_RASTER_CLIP_WORKER_FILE = 'Workers/CustomRasterClip.worker.js';
12
+ var DEFAULT_CUSTOM_RASTER_CLIP_WORKER_NAME = 'CustomRasterClip.worker';
13
+ // 创建栅格裁剪 Worker。
14
+ function createClipWorker(options) {
15
+ var workerUrl = options.workerUrl || getDeepTwinsFile(DEFAULT_CUSTOM_RASTER_CLIP_WORKER_FILE);
16
+ return new Worker(workerUrl, {
17
+ type: 'module',
18
+ name: DEFAULT_CUSTOM_RASTER_CLIP_WORKER_NAME
19
+ });
20
+ }
21
+ var CustomRasterClipWorkerClient = /*#__PURE__*/function () {
22
+ function CustomRasterClipWorkerClient(options) {
23
+ var _this = this;
24
+ _classCallCheck(this, CustomRasterClipWorkerClient);
25
+ _defineProperty(this, "_worker", void 0);
26
+ _defineProperty(this, "_requestId", void 0);
27
+ _defineProperty(this, "_pendingTasks", void 0);
28
+ _defineProperty(this, "_handleMessage", function (event) {
29
+ var response = event.data;
30
+ var task = _this._pendingTasks.get(response.id);
31
+ if (!task) {
32
+ return;
33
+ }
34
+ _this._pendingTasks.delete(response.id);
35
+ if ('error' in response) {
36
+ task.reject(new Error(response.error));
37
+ return;
38
+ }
39
+ task.resolve(response.result);
40
+ });
41
+ _defineProperty(this, "_handleError", function (event) {
42
+ var _event$error;
43
+ _this._shutdown(_this._toError((_event$error = event.error) !== null && _event$error !== void 0 ? _event$error : event.message, '栅格裁剪 Worker 运行失败'));
44
+ });
45
+ if (typeof Worker !== 'function') {
46
+ throw new Error('当前环境不支持 Worker');
47
+ }
48
+ this._worker = createClipWorker(options);
49
+ this._requestId = 0;
50
+ this._pendingTasks = new Map();
51
+ this._worker.addEventListener('message', this._handleMessage);
52
+ this._worker.addEventListener('error', this._handleError);
53
+ this._init(options.features);
54
+ }
55
+
56
+ // 发送单个裁剪任务,Worker 只返回几何关系和画布路径。
57
+ _createClass(CustomRasterClipWorkerClient, [{
58
+ key: "clip",
59
+ value: function clip(options) {
60
+ var _this2 = this;
61
+ var worker = this._worker;
62
+ if (!worker) {
63
+ return Promise.reject(new Error('栅格裁剪 Worker 已销毁'));
64
+ }
65
+ var id = ++this._requestId;
66
+ return new Promise(function (resolve, reject) {
67
+ _this2._pendingTasks.set(id, {
68
+ resolve: resolve,
69
+ reject: reject
70
+ });
71
+ try {
72
+ worker.postMessage(_objectSpread({
73
+ type: 'clip',
74
+ id: id
75
+ }, options));
76
+ } catch (error) {
77
+ _this2._pendingTasks.delete(id);
78
+ reject(_this2._toError(error, '发送栅格裁剪任务失败'));
79
+ }
80
+ });
81
+ }
82
+
83
+ // 销毁 Worker,并让所有挂起任务立即失败。
84
+ }, {
85
+ key: "destroy",
86
+ value: function destroy() {
87
+ this._shutdown(new Error('栅格裁剪 Worker 已销毁'));
88
+ }
89
+ }, {
90
+ key: "_init",
91
+ value: function _init(features) {
92
+ var worker = this._worker;
93
+ if (!worker) {
94
+ return;
95
+ }
96
+ try {
97
+ worker.postMessage({
98
+ type: 'init',
99
+ features: features
100
+ });
101
+ } catch (error) {
102
+ var normalizedError = this._toError(error, '初始化栅格裁剪 Worker 失败');
103
+ this._shutdown(normalizedError);
104
+ throw normalizedError;
105
+ }
106
+ }
107
+ }, {
108
+ key: "_shutdown",
109
+ value: function _shutdown(reason) {
110
+ if (!this._worker) {
111
+ this._failAllPending(reason);
112
+ return;
113
+ }
114
+ this._worker.removeEventListener('message', this._handleMessage);
115
+ this._worker.removeEventListener('error', this._handleError);
116
+ this._worker.terminate();
117
+ this._worker = null;
118
+ this._failAllPending(reason);
119
+ }
120
+ }, {
121
+ key: "_failAllPending",
122
+ value: function _failAllPending(reason) {
123
+ var pendingTasks = [];
124
+ this._pendingTasks.forEach(function (task) {
125
+ pendingTasks.push(task);
126
+ });
127
+ this._pendingTasks.clear();
128
+ for (var _i = 0, _pendingTasks = pendingTasks; _i < _pendingTasks.length; _i++) {
129
+ var task = _pendingTasks[_i];
130
+ task.reject(reason);
131
+ }
132
+ }
133
+ }, {
134
+ key: "_toError",
135
+ value: function _toError(error, fallbackMessage) {
136
+ if (error instanceof Error) {
137
+ return error;
138
+ }
139
+ if (typeof error === 'string' && error.length > 0) {
140
+ return new Error(error);
141
+ }
142
+ return new Error(fallbackMessage);
143
+ }
144
+ }]);
145
+ return CustomRasterClipWorkerClient;
146
+ }();
147
+ export default CustomRasterClipWorkerClient;
@@ -50,8 +50,10 @@ import ImageryLayer from './ImageryLayer';
50
50
  * - `clipFeatureCrs`:可选,clipFeature 的原始坐标系,默认跟随 dataCrs。
51
51
  * - `renderCrs`:可选,bounds、clipFeature 和瓦片范围转换后的目标坐标系,默认 `EPSG:4326`。
52
52
  * - `projectionDefs`:可选,自定义 proj4 坐标系定义。
53
- * - `clipFeature`:可选,GeoJSON Polygon/MultiPolygon/Feature/FeatureCollection
53
+ * - `clipFeature`:可选,GeoJSON Polygon/MultiPolygon/Feature/FeatureCollection,`null` 等同未传。
54
54
  * - `autoFitBounds`:可选,创建后自动将相机定位到最终范围,需同时传入 `map`。
55
+ * - `clipWithWorker`:可选,裁剪几何计算优先使用 Worker,默认 `true`。
56
+ * - `clipWorkerUrl`:可选,自定义裁剪 Worker 地址。
55
57
  * - `debug`:可选,`true` 使用 console.log 输出调试信息,函数则接收结构化调试事件。
56
58
  */
57
59
  /** 通用范围格式:[minX, minY, maxX, maxY]。 */
@@ -139,7 +141,7 @@ export type CustomRasterLayerOptions = {
139
141
  renderCrs?: string;
140
142
  /** 自定义 proj4 坐标系定义,key 可为 EPSG:xxxx 或其他 proj4 名称。 */
141
143
  projectionDefs?: Record<string, string>;
142
- /** 用于裁剪瓦片的 GeoJSON 面要素。 */
144
+ /** 用于裁剪瓦片的 GeoJSON 面要素,null 等同未传。 */
143
145
  clipFeature?: any;
144
146
  /** 地图实例,autoFitBounds 或手动 fitToBounds 时用于控制相机。 */
145
147
  map?: any;
@@ -147,6 +149,10 @@ export type CustomRasterLayerOptions = {
147
149
  autoFitBounds?: boolean;
148
150
  /** 自动定位到范围时透传给相机 flyTo 的配置,默认 { duration: 0 }。 */
149
151
  fitBoundsOptions?: any;
152
+ /** 是否优先使用 Worker 计算裁剪几何,默认 true,失败时自动回退主线程。 */
153
+ clipWithWorker?: boolean;
154
+ /** 自定义裁剪 Worker 地址,优先于默认 DeepTwins 静态资源地址。 */
155
+ clipWorkerUrl?: string;
150
156
  /** 调试开关或自定义调试事件处理函数。 */
151
157
  debug?: CustomRasterLayerDebug;
152
158
  };
@@ -173,13 +179,20 @@ export default class CustomRasterLayer extends ImageryLayer {
173
179
  readonly source: Cesium.UrlTemplateImageryProvider;
174
180
  private readonly _debug?;
175
181
  private readonly _clipFeatures;
182
+ private readonly _clipFeatureEntries;
176
183
  private readonly _fitBounds?;
184
+ private readonly _clipWorkerUrl;
185
+ private _clipWithWorker;
186
+ private _clipWorkerClient;
177
187
  private _mapContext;
188
+ private _destroyed;
178
189
  /** 创建通用栅格图层。 */
179
190
  constructor(options: CustomRasterLayerOptions);
180
191
  getMap(): any;
181
192
  /** 将相机定位到当前图层最终渲染范围。 */
182
193
  fitToBounds(map?: any, options?: any): this;
194
+ /** 销毁图层并释放裁剪 Worker。 */
195
+ destroy(): void;
183
196
  /**
184
197
  * Cesium 内部纹理创建钩子。
185
198
  *
@@ -191,7 +204,16 @@ export default class CustomRasterLayer extends ImageryLayer {
191
204
  _createTexture(context: any, imagery: RasterImagery): any;
192
205
  /** 调用 Cesium 原始纹理创建逻辑。 */
193
206
  private createTexture;
194
- /** 获取当前瓦片与所有裁剪面的交集,用交集路径裁剪当前瓦片。 */
207
+ /** 根据裁剪面 bbox 粗过滤当前瓦片可能相交的面。 */
208
+ private getCandidateClipFeatureIndexes;
209
+ private getClipFeatures;
210
+ private getClipWorkerClient;
211
+ private destroyClipWorkerClient;
212
+ private createClippedTexture;
213
+ /** 主线程裁剪回退逻辑,保持与 Worker 返回结构一致。 */
214
+ private clipTileOnMainThread;
215
+ private applyClipResult;
216
+ /** 获取当前瓦片与候选裁剪面的交集,用交集路径裁剪当前瓦片。 */
195
217
  private getClipIntersections;
196
218
  /** 创建与当前瓦片同尺寸的透明 canvas。 */
197
219
  private createTileCanvas;