@skzz/components-gis 0.1.4 → 0.1.6

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 (53) hide show
  1. package/dist/assets/twinPreviewWorker-DvpSZYqE.js +3 -0
  2. package/dist/assets/twinTextureMipWorker-BWoFEUdX.js +3 -0
  3. package/dist/color-DVYdxZow.js +359 -0
  4. package/dist/esm-BXiGX6xE.js +86 -0
  5. package/dist/index.css +1 -1
  6. package/dist/index.d.ts +72 -6
  7. package/dist/index.es.js +1164 -9665
  8. package/dist/index.umd.js +209 -5
  9. package/dist/interpolation-Ctw2-y9G.js +211 -0
  10. package/dist/layerStack-CbiVJONn.js +181 -0
  11. package/dist/pako.esm-D6zcBi67.js +1455 -0
  12. package/dist/query-DgSNPfJM.js +239 -0
  13. package/dist/queryPoint-BOi_hkig.js +189 -0
  14. package/dist/tw2Parser-Dxs5xGvB.js +115 -0
  15. package/dist/zz-3dtiles-BzDYB-tW.js +75 -0
  16. package/dist/zz-gltf-BDHxqQjs.js +70 -0
  17. package/dist/zz-layer/zz-layer-shp-zzts/shpZztsBounds.d.ts +19 -0
  18. package/dist/zz-layer/zz-layer-shp-zzts/shpZztsCacheUtils.d.ts +53 -0
  19. package/dist/zz-layer/zz-layer-shp-zzts/shpZztsGeometry.d.ts +27 -0
  20. package/dist/zz-layer/zz-layer-shp-zzts/shpZztsGeometryWorker.d.ts +1 -0
  21. package/dist/zz-layer/zz-layer-shp-zzts/shpZztsPreviewBudget.d.ts +78 -0
  22. package/dist/zz-layer/zz-layer-shp-zzts/shpZztsRenderer.d.ts +281 -16
  23. package/dist/zz-layer/zz-layer-shp-zzts/shpZztsViewState.d.ts +20 -0
  24. package/dist/zz-layer/zz-layer-zzts/zztsRasterCacheUtils.d.ts +35 -0
  25. package/dist/zz-layer/zz-layer-zzts/zztsRasterPreviewPolling.d.ts +10 -0
  26. package/dist/zz-layer/zz-layer-zzts3dv2/entityGridV2.d.ts +277 -0
  27. package/dist/zz-layer/zz-layer-zzts3dv2/index.vue.d.ts +1 -0
  28. package/dist/zz-layer/zz-layer-zzts3dv2/tw2Parser.d.ts +7 -0
  29. package/dist/zz-layer/zz-layer-zzts3dv2/twinAdaptiveMesh.d.ts +3 -0
  30. package/dist/zz-layer/zz-layer-zzts3dv2/twinCoarseLod.d.ts +4 -0
  31. package/dist/zz-layer/zz-layer-zzts3dv2/twinEnvironmentLighting.d.ts +16 -0
  32. package/dist/zz-layer/zz-layer-zzts3dv2/twinImagePixels.d.ts +6 -0
  33. package/dist/zz-layer/zz-layer-zzts3dv2/twinPagedIndex.d.ts +8 -0
  34. package/dist/zz-layer/zz-layer-zzts3dv2/twinParsePool.d.ts +10 -0
  35. package/dist/zz-layer/zz-layer-zzts3dv2/twinPreviewWorker.d.ts +1 -0
  36. package/dist/zz-layer/zz-layer-zzts3dv2/twinRegionalIndex.d.ts +23 -0
  37. package/dist/zz-layer/zz-layer-zzts3dv2/twinResourceBatch.d.ts +34 -0
  38. package/dist/zz-layer/zz-layer-zzts3dv2/twinTextureAppearance.d.ts +89 -0
  39. package/dist/zz-layer/zz-layer-zzts3dv2/twinTextureMipWorker.d.ts +1 -0
  40. package/dist/zz-layer/zz-layer-zzts3dv2/twinVisualRuntime.d.ts +107 -0
  41. package/dist/zz-layer-geojson-CtTpn_f9.js +867 -0
  42. package/dist/zz-layer-mvt-R1-GwSIW.js +609 -0
  43. package/dist/zz-layer-shp-zzts-Dr3Gxeba.js +1881 -0
  44. package/dist/zz-layer-zzts3d-CsIWse3P.js +835 -0
  45. package/dist/zz-layer-zzts3d-grid-CTHFZBpo.js +314 -0
  46. package/dist/zz-layer-zzts3d-las-D3w01aGe.js +561 -0
  47. package/dist/zz-layer-zzts3d-point-BjaTPTqj.js +752 -0
  48. package/dist/zz-layer-zzts3dtype-BRl3mCk9.js +493 -0
  49. package/dist/zz-layer-zzts3dv2-DFXCOaMe.js +4019 -0
  50. package/dist/zz-terrain-excavation-A2NXSQ5P.js +502 -0
  51. package/dist/zz-viewer/index.vue.d.ts +2 -2
  52. package/dist/zzts3dLayerSignature-DzrPeJTd.js +44 -0
  53. package/package.json +5 -4
@@ -0,0 +1,752 @@
1
+ import { t as e } from "./pako.esm-D6zcBi67.js";
2
+ import { n as t, t as n } from "./esm-BXiGX6xE.js";
3
+ import { n as r, t as i } from "./zzts3dLayerSignature-DzrPeJTd.js";
4
+ import { computed as a, inject as o, onUnmounted as s, ref as c, shallowRef as l, watch as u } from "vue";
5
+ import { IndexedDBManager as d, httpService as f, useDataService as p } from "@skzz/libs-base";
6
+ import m from "axios";
7
+ import { latlng as h } from "@skzz/libs-gis";
8
+ //#region src/zz-layer/zz-layer-zzts3d-point/pointTileUtils.js
9
+ function g(e) {
10
+ return e instanceof ArrayBuffer ? e : ArrayBuffer.isView(e) ? e.buffer.slice(e.byteOffset, e.byteOffset + e.byteLength) : null;
11
+ }
12
+ function _(e) {
13
+ if (!e || e.byteLength === 0) return null;
14
+ let t = new Uint8Array(e), n = t.find((e) => e > 32);
15
+ if (n !== 123 && n !== 91) return null;
16
+ try {
17
+ return JSON.parse(new TextDecoder().decode(t));
18
+ } catch {
19
+ return null;
20
+ }
21
+ }
22
+ function v(e, t = {}) {
23
+ return console.warn("[zzts3d-point] skip invalid tile data:", e, t), [];
24
+ }
25
+ var y = [
26
+ 13,
27
+ 14,
28
+ 15,
29
+ 16,
30
+ 18
31
+ ], b = 16;
32
+ function x(e, t = b) {
33
+ let n = Number(e);
34
+ if (Number.isFinite(n) && n > 0) return y.find((e) => n <= e) || y[y.length - 1];
35
+ let r = Number(t);
36
+ return Number.isFinite(r) && r > 0 ? y.find((e) => r <= e) || y[y.length - 1] : b;
37
+ }
38
+ function S(e, t) {
39
+ let n = (String(e ?? "").split("_")[0].match(/\d/g) || []).length;
40
+ return n > 0 ? x(n, t) : x(t);
41
+ }
42
+ function C(t, n) {
43
+ let r = g(t);
44
+ if (!r || r.byteLength < 4 || _(r)) return [];
45
+ let i = [], a = new DataView(r), o = 0, s = a.getInt32(o, !0);
46
+ if (o += 4, s < 0 || s > 1e5) return v("invalid entity count", {
47
+ entityCount: s,
48
+ byteLength: r.byteLength
49
+ });
50
+ for (let t = 0; t < s; t++) {
51
+ if (o + 4 > r.byteLength) return v("missing compressed chunk length", {
52
+ offset: o,
53
+ byteLength: r.byteLength
54
+ });
55
+ let t = a.getInt32(o, !0);
56
+ if (o += 4, t <= 0 || o + t > r.byteLength) return v("invalid compressed chunk length", {
57
+ compressedLength: t,
58
+ offset: o,
59
+ byteLength: r.byteLength
60
+ });
61
+ let s = new Uint8Array(r, o, t);
62
+ o += t;
63
+ let c;
64
+ try {
65
+ let t = e.inflate(s);
66
+ c = new DataView(t.buffer, t.byteOffset, t.byteLength);
67
+ } catch {
68
+ c = new DataView(s.buffer, s.byteOffset, s.byteLength);
69
+ }
70
+ if (c.byteLength < 12) return v("chunk too small", { byteLength: c.byteLength });
71
+ let l = 0, u = c.getBigInt64(l, !0);
72
+ l += 8;
73
+ let d = c.getInt32(l, !0);
74
+ if (l += 4, d < 0 || d % 12 != 0 || l + d > c.byteLength) return v("invalid positions byte length", {
75
+ positionsByteLength: d,
76
+ innerOffset: l,
77
+ byteLength: c.byteLength
78
+ });
79
+ let f = d / 4, p = new Float64Array(f);
80
+ for (let e = 0; e < f; e++) p[e] = c.getInt32(l, !0), l += 4;
81
+ i.push({
82
+ positions: p,
83
+ positionCount: f,
84
+ modelId: u.toString(),
85
+ lodLevel: n
86
+ });
87
+ }
88
+ return i;
89
+ }
90
+ function w({ destroyed: e, currentVersion: t, requestVersion: n, cancelToken: r } = {}) {
91
+ return !e && t === n && !r?.token?.reason;
92
+ }
93
+ //#endregion
94
+ //#region src/zz-layer/zz-layer-zzts3d-point/entityGrid.js
95
+ function T(e) {
96
+ if (!e) return null;
97
+ let t = e;
98
+ if (typeof e == "string") try {
99
+ t = JSON.parse(e);
100
+ } catch {
101
+ return null;
102
+ }
103
+ if (!t || typeof t != "object") return null;
104
+ let n = Number(t.longitudeWest ?? t.west), r = Number(t.latitudeSouth ?? t.south), i = Number(t.longitudeEast ?? t.east), a = Number(t.latitudeNorth ?? t.north);
105
+ return ![
106
+ n,
107
+ r,
108
+ i,
109
+ a
110
+ ].every(Number.isFinite) || n < -180 || i > 180 || r < -90 || a > 90 || n >= i || r >= a ? null : {
111
+ west: n,
112
+ south: r,
113
+ east: i,
114
+ north: a
115
+ };
116
+ }
117
+ function E(e, t) {
118
+ if (!e || !t) return null;
119
+ let n = {
120
+ west: Math.max(e.west, t.west),
121
+ south: Math.max(e.south, t.south),
122
+ east: Math.min(e.east, t.east),
123
+ north: Math.min(e.north, t.north)
124
+ };
125
+ return n.west < n.east && n.south < n.north ? n : null;
126
+ }
127
+ var D = class {
128
+ constructor(e, t = !1, n = null, r = "255,255,255", i = 5, a = 1, o = {}) {
129
+ this.id = e, this.dataLayerId = o.dataLayerId || e, this.viewer = o.viewer || null, this.isStatic = t, this.loadedTiles = /* @__PURE__ */ new Map(), this.currentTileIds = /* @__PURE__ */ new Set(), this.currentNewLevel = c(n || 15), this.gridDb = null, this.entityNum = 0, this.handlers = null, this.requestController = null, this.pendingRequests = /* @__PURE__ */ new Map(), this.fadeAnimations = /* @__PURE__ */ new Map(), this.lastTime = 0, this.pointSize = i, this.opacity = a, this.fixedLevel = n, this.dictCode = o.dictCode || "", this.serviceName = o.serviceName || "", this.enableServiceColor = o.enableServiceColor === !0, this.modelColorUrl = o.modelColorUrl || "/v1/zzts/style/render/modelColors", this.displayRange = T(o.displayRange), this.modelColorCache = /* @__PURE__ */ new Map(), this.requestVersion = 0, this.destroyed = !1, this.initTimer = null, this.levels_add = window.levels_add_plus || 0, this.tileColor = r, this.tileSleepTime = window.tileSleepTime || 400, this.highlightModelId = null, this.highlightColor = "255,255,0", this.highlightOpacity = 1, this.highlightPointSize = null, this.modelPointIndex = /* @__PURE__ */ new Map(), this.tilePointIndex = /* @__PURE__ */ new Map(), this.modelCollections = /* @__PURE__ */ new Map(), this.renderedPointCount = 0, this.pointBudgetWarned = !1, this.maxRenderPoints = window.zztsPointRenderBudget || 12e5;
130
+ }
131
+ getBaseStyle() {
132
+ return {
133
+ color: Cesium.Color.fromCssColorString(`rgba(${this.tileColor}, ${this.opacity})`),
134
+ pointSize: this.pointSize
135
+ };
136
+ }
137
+ isServiceColorEnabled() {
138
+ return !!(this.enableServiceColor && this.dictCode && this.modelColorUrl);
139
+ }
140
+ unwrapResponseData(e) {
141
+ return e?.data?.data === void 0 ? e?.data === void 0 ? e : e.data : e.data.data;
142
+ }
143
+ normalizeServiceColor(e) {
144
+ return !e || typeof e != "string" ? null : e.startsWith("rgb(") || e.startsWith("rgba(") ? e : e.startsWith("#") ? this.hexToRgba(e) : `rgba(${e}, ${this.opacity})`;
145
+ }
146
+ async loadModelColorsByIds(e = []) {
147
+ if (!this.isServiceColorEnabled()) return /* @__PURE__ */ new Map();
148
+ let t = [...new Set(e.map((e) => String(e || "").trim()).filter((e) => e))], n = /* @__PURE__ */ new Map(), r = [];
149
+ if (t.forEach((e) => {
150
+ this.modelColorCache.has(e) ? n.set(e, this.modelColorCache.get(e)) : r.push(e);
151
+ }), r.length === 0) return n;
152
+ for (let e = 0; e < r.length; e += 800) {
153
+ let t = r.slice(e, e + 800);
154
+ try {
155
+ let e = await f.request({
156
+ method: "POST",
157
+ url: this.modelColorUrl,
158
+ data: {
159
+ serviceName: this.serviceName,
160
+ dictCode: this.dictCode,
161
+ modelIds: t
162
+ },
163
+ timeout: 6e4
164
+ });
165
+ (this.unwrapResponseData(e)?.rows || []).forEach((e) => {
166
+ let t = String(e.modelId || e.model_id || "").trim(), r = this.normalizeServiceColor(e.color);
167
+ t && r && (this.modelColorCache.set(t, r), n.set(t, r));
168
+ });
169
+ } catch (e) {
170
+ console.error("[zzts-point-style] 查询模型颜色失败", {
171
+ dictCode: this.dictCode,
172
+ serviceName: this.serviceName,
173
+ requestCount: t.length,
174
+ error: e
175
+ });
176
+ }
177
+ }
178
+ return n;
179
+ }
180
+ getHighlightStyle() {
181
+ let e = this.highlightPointSize ?? this.pointSize * 2;
182
+ return {
183
+ color: Cesium.Color.fromCssColorString(`rgba(${this.highlightColor}, ${this.highlightOpacity})`),
184
+ pointSize: e
185
+ };
186
+ }
187
+ createModelCollection(e, t, n, r, i) {
188
+ let a = t.positions.length / 3;
189
+ if (this.renderedPointCount + a > this.maxRenderPoints) return this.pointBudgetWarned ||= (console.warn(`[zzts3d-point] 图层 ${this.id} 达到渲染点数预算 ${this.maxRenderPoints},跳过后续模型渲染`), !0), null;
190
+ let o = new Cesium.PointPrimitiveCollection(), s = i.get(e), c = Cesium.Color.fromCssColorString(s || `rgba(${this.tileColor}, ${this.opacity})`), l = this.highlightModelId === e ? this.getHighlightStyle() : null;
191
+ for (let n = 0; n < t.positions.length; n += 3) {
192
+ let r = o.add({
193
+ position: new Cesium.Cartesian3(t.positions[n], t.positions[n + 1], t.positions[n + 2]),
194
+ color: l ? l.color : c,
195
+ pixelSize: l ? l.pointSize : this.pointSize
196
+ });
197
+ r.geomModelId = e, r.type = "zzts3dPoint";
198
+ }
199
+ if (o.layerId = this.id, this.viewer && !this.viewer.isDestroyed()) this.viewer.scene.primitives.add(o);
200
+ else return null;
201
+ let u = /* @__PURE__ */ new Set(), d = o.length;
202
+ for (let e = 0; e < d; e++) u.add(o.get(e));
203
+ return this.modelPointIndex.set(e, u), this.modelCollections.set(e, {
204
+ collection: o,
205
+ refs: new Set([r]),
206
+ points: a,
207
+ lodLevel: n
208
+ }), this.renderedPointCount += a, o;
209
+ }
210
+ destroyModelCollection(e) {
211
+ let t = this.modelCollections.get(e);
212
+ if (!t) return;
213
+ let n = this.viewer && !this.viewer.isDestroyed() ? this.viewer.scene.primitives : null;
214
+ t.collection && n?.contains(t.collection) && n.remove(t.collection), this.modelPointIndex.delete(e), this.modelCollections.delete(e), this.renderedPointCount -= t.points;
215
+ }
216
+ releaseTileModels(e) {
217
+ let t = this.tilePointIndex.get(e);
218
+ if (t) {
219
+ for (let n of t) {
220
+ let t = this.modelCollections.get(n);
221
+ t && (t.refs.delete(e), t.refs.size === 0 && this.destroyModelCollection(n));
222
+ }
223
+ this.tilePointIndex.delete(e);
224
+ }
225
+ }
226
+ resetPoints(e) {
227
+ if (!e || e.size === 0) return;
228
+ let t = this.getBaseStyle();
229
+ for (let n of e) try {
230
+ n.color = t.color, n.pixelSize = t.pointSize;
231
+ } catch {}
232
+ }
233
+ highlightPoints(e) {
234
+ if (!e || e.size === 0) return;
235
+ let t = this.getHighlightStyle();
236
+ for (let n of e) try {
237
+ n.color = t.color, n.pixelSize = t.pointSize;
238
+ } catch {}
239
+ }
240
+ applyHighlightStateToLoadedPoints() {
241
+ if (this.destroyed) return;
242
+ let e = this.getBaseStyle(), t = !!this.highlightModelId, n = t ? this.getHighlightStyle() : null;
243
+ for (let [, r] of this.modelCollections) {
244
+ let i = r?.collection;
245
+ if (!i || i.isDestroyed?.() || !(i instanceof Cesium.PointPrimitiveCollection)) continue;
246
+ let a = i.length;
247
+ for (let r = 0; r < a; r++) {
248
+ let a = i.get(r);
249
+ if (!(!a || a.type !== "zzts3dPoint")) try {
250
+ t && a.geomModelId === this.highlightModelId ? (a.color = n.color, a.pixelSize = n.pointSize) : (a.color = e.color, a.pixelSize = e.pointSize);
251
+ } catch {}
252
+ }
253
+ }
254
+ }
255
+ setHighlight(e, t = {}) {
256
+ let n = this.highlightModelId;
257
+ this.highlightModelId = e || null, t.highlightColor && (this.highlightColor = t.highlightColor), typeof t.highlightOpacity == "number" && (this.highlightOpacity = t.highlightOpacity), t.highlightPointSize !== void 0 && (this.highlightPointSize = t.highlightPointSize);
258
+ let r = n ? this.modelPointIndex.get(n) : null, i = this.highlightModelId ? this.modelPointIndex.get(this.highlightModelId) : null;
259
+ r && this.resetPoints(r), i && this.highlightPoints(i), !i && this.highlightModelId && this.applyHighlightStateToLoadedPoints();
260
+ }
261
+ clearHighlight() {
262
+ let e = this.highlightModelId;
263
+ if (this.highlightModelId = null, !e || this.destroyed) return;
264
+ let t = this.modelPointIndex.get(e);
265
+ t ? this.resetPoints(t) : this.applyHighlightStateToLoadedPoints();
266
+ }
267
+ async init() {
268
+ let e = this.isStatic ? "_static" : "", t = new d(`gridDbs_${this.id}${e}_point`, 1);
269
+ if (this.gridDb = t, await t.openDatabase("gridEntity", "id"), this.destroyed) {
270
+ t.closeDatabase(), this.gridDb === t && (this.gridDb = null);
271
+ return;
272
+ }
273
+ this.initTimer = setTimeout(() => {
274
+ this.destroyed || (this.isStatic || this.initHandler(), this.getViewportInfo());
275
+ }, 400);
276
+ }
277
+ getCurrentLevel() {
278
+ return this.currentNewLevel.value;
279
+ }
280
+ remove() {
281
+ this.destroyed = !0, this.destroyHandler(), this.gridDb?.closeDatabase(), this.gridDb = null, this.modelColorCache.clear(), this.modelPointIndex.clear(), this.tilePointIndex.clear(), this.viewer = null;
282
+ }
283
+ removeTilesOnly() {
284
+ this.clearAllTiles();
285
+ }
286
+ clearAllTiles() {
287
+ this.requestVersion += 1, this.initTimer &&= (clearTimeout(this.initTimer), null), this.fadeAnimations.forEach((e) => {
288
+ e.interval && clearInterval(e.interval);
289
+ }), this.fadeAnimations.clear(), this.pendingRequests.forEach((e) => {
290
+ e.cancel && e.cancel();
291
+ }), this.pendingRequests.clear();
292
+ let e = this.viewer && !this.viewer.isDestroyed() ? this.viewer.scene.primitives : null;
293
+ this.modelCollections.forEach((t) => {
294
+ t.collection && e?.contains(t.collection) && e.remove(t.collection);
295
+ }), this.modelCollections.clear(), this.renderedPointCount = 0, this.pointBudgetWarned = !1, this.modelPointIndex.clear(), this.tilePointIndex.clear(), this.currentTileIds = /* @__PURE__ */ new Set(), this.loadedTiles.clear();
296
+ }
297
+ initHandler1() {
298
+ if (!(!this.viewer || this.viewer.isDestroyed())) {
299
+ if (this.getViewportInfo(), this.handlers) try {
300
+ this.viewer.camera.moveEnd.removeEventListener(this.handlers);
301
+ } catch (e) {
302
+ console.warn("移除旧的事件监听器失败:", e);
303
+ }
304
+ this.handlers = () => {
305
+ this.getViewportInfo();
306
+ }, this.viewer.camera.moveEnd.addEventListener(this.handlers);
307
+ }
308
+ }
309
+ initHandler() {
310
+ if (!this.viewer || this.viewer.isDestroyed()) return;
311
+ if (this.getViewportInfo(), this.handlers) try {
312
+ this.viewer.camera.changed.removeEventListener(this.handlers);
313
+ } catch (e) {
314
+ console.warn("移除旧的事件监听器失败:", e);
315
+ }
316
+ let e = null, t = () => {
317
+ clearTimeout(e), e = setTimeout(() => {
318
+ this.getViewportInfo();
319
+ }, 250);
320
+ };
321
+ this.viewer.camera.changed.addEventListener(t), this.handlers = t;
322
+ }
323
+ getViewportInfo() {
324
+ if (this.destroyed || !this.viewer || this.viewer.isDestroyed()) return;
325
+ this.requestController && this.requestController.abort(), this.requestController = new AbortController(), this.entityNum = 0;
326
+ let e = h.getFrustumGroundIntersectionPoints(this.viewer), r = h.getCenter(this.viewer), i = h.getCameraView(this.viewer);
327
+ if (i.pitch > -18) return;
328
+ let a;
329
+ if (this.isStatic && this.fixedLevel) a = this.fixedLevel + this.levels_add;
330
+ else {
331
+ let t = Cesium.Cartesian3.distance(Cesium.Cartesian3.fromDegrees(r.x, r.y, 0), Cesium.Cartesian3.fromDegrees(i.x, i.y, i.z)), n = h.entityGridLevels.filter((e) => e.max >= t && e.min <= t);
332
+ if (!n[0] || e.length < 4) return;
333
+ a = n[0].level + this.levels_add;
334
+ }
335
+ if (this.currentNewLevel.value = a, e.length < 4) return;
336
+ let o = n(t([
337
+ [e[0].x, e[0].y],
338
+ [e[1].x, e[1].y],
339
+ [e[2].x, e[2].y],
340
+ [e[3].x, e[3].y]
341
+ ])), s = {
342
+ west: o[0],
343
+ south: o[1],
344
+ east: o[2],
345
+ north: o[3]
346
+ }, c = this.displayRange ? E(s, this.displayRange) : s;
347
+ if (!c) {
348
+ this.clearAllTiles();
349
+ return;
350
+ }
351
+ let l = [
352
+ c.west,
353
+ c.south,
354
+ c.east,
355
+ c.north
356
+ ];
357
+ this.getEntityData(l, a, e, this.requestController.signal);
358
+ }
359
+ showDebugPoints(e) {
360
+ this.viewer.entities.values.filter((e) => e.id && e.id.startsWith(`debug_${this.id}_`)).forEach((e) => this.viewer.entities.remove(e)), e.forEach((e, t) => {
361
+ this.showPoint(e.x, e.y, 1, t);
362
+ });
363
+ }
364
+ async getEntityData(e, t, n, r) {
365
+ if (this.destroyed || !this.viewer || this.viewer.isDestroyed()) return;
366
+ let i = this.viewer.scene.canvas, a = i.clientWidth, o = i.clientHeight;
367
+ try {
368
+ let t = await f.request({
369
+ method: "GET",
370
+ url: `/v1/zzts/layer/3d/point/calTiles?region=${e[0]},${e[1]},0,${e[2]},${e[3]},10&width=${a}&height=${o}`,
371
+ timeout: 6e4,
372
+ signal: r
373
+ });
374
+ !r.aborted && !this.destroyed && this.render3DFaces(t.tiles, t.lodLevel);
375
+ } catch (e) {
376
+ !this.destroyed && !r.aborted && !m.isCancel(e) && e.name !== "AbortError" && console.error(`图层 ${this.id} 获取实体数据出错:`, e);
377
+ }
378
+ }
379
+ render3DFaces(e, t) {
380
+ if (this.destroyed || !this.viewer || this.viewer.isDestroyed()) return;
381
+ this.lastTime = (/* @__PURE__ */ new Date()).getTime();
382
+ let n = h.getCameraView(this.viewer), r = Array.isArray(e) ? e : [];
383
+ r.forEach((e) => {
384
+ if (this.isStatic && this.fixedLevel) e.geoSot = e.geoSot, e.level = t;
385
+ else {
386
+ let r = S(e.geoSot, t), i = Cesium.Cartesian3.distance(Cesium.Cartesian3.fromDegrees((e.xmax + e.xmin) / 2, (e.ymax + e.ymin) / 2, 0), Cesium.Cartesian3.fromDegrees(n.x, n.y, n.z));
387
+ h.entityGridLevels.filter((e) => e.max >= i && e.min <= i), e.geoSot = e.geoSot, e.level = r;
388
+ }
389
+ });
390
+ let i = this.displayRange, a = r.filter((e) => i ? !!E({
391
+ west: Number(e?.xmin),
392
+ south: Number(e?.ymin),
393
+ east: Number(e?.xmax),
394
+ north: Number(e?.ymax)
395
+ }, i) : !0), o = new Set(a.map((e) => e.geoSot)), s = [], c = [];
396
+ this.currentTileIds.forEach((e) => {
397
+ o.has(e) || c.push(e);
398
+ }), o.forEach((e) => {
399
+ if (!this.currentTileIds.has(e)) {
400
+ let t = a.find((t) => e === t.geoSot);
401
+ t && s.push(t);
402
+ }
403
+ }), s.forEach((e) => {
404
+ this.addTile(e, e.level);
405
+ }), c.forEach((e) => {
406
+ let t = this.loadedTiles.get(e);
407
+ t && this.fadeOut(t, e);
408
+ }), this.currentTileIds = o;
409
+ }
410
+ fadeOut(e, t) {
411
+ if (this.fadeAnimations.has(t)) {
412
+ let e = this.fadeAnimations.get(t);
413
+ e.interval && clearInterval(e.interval);
414
+ }
415
+ let n = 0, r = this.tileSleepTime / 100, i = setInterval(() => {
416
+ n < r ? n++ : (clearInterval(i), this.fadeAnimations.delete(t), this.releaseTileModels(t), this.loadedTiles.delete(t), this.currentTileIds.delete(t));
417
+ }, 100);
418
+ this.fadeAnimations.set(t, { interval: i });
419
+ }
420
+ isActiveRequest(e, t) {
421
+ return w({
422
+ destroyed: this.destroyed || !this.viewer || this.viewer.isDestroyed(),
423
+ currentVersion: this.requestVersion,
424
+ requestVersion: e,
425
+ cancelToken: t
426
+ });
427
+ }
428
+ async getTileData(e, t, n, r) {
429
+ let i = "v2_" + e + "_" + n, a = await this.gridDb.getDataById("gridEntity", i);
430
+ return a ? {
431
+ cacheId: i,
432
+ data: a.data,
433
+ fromCache: !0
434
+ } : {
435
+ cacheId: i,
436
+ data: (await f.request({
437
+ method: "GET",
438
+ url: `/v1/zzts/layer/3d/point/getTileNew?layerId=${encodeURIComponent(this.dataLayerId)}&level=${t}&geosot=${e}`,
439
+ headers: { Accept: "application/octet-stream" },
440
+ responseType: "arraybuffer",
441
+ timeout: 6e4,
442
+ cancelToken: r.token
443
+ })).data,
444
+ fromCache: !1
445
+ };
446
+ }
447
+ async addTileDataToMap(e, t, n, r, i, a, o) {
448
+ if (!this.isActiveRequest(a, o) || !n?.data?.byteLength) return !1;
449
+ let s = this.parseCompressedMeshData(n.data, i);
450
+ return !s.length || !this.isActiveRequest(a, o) || (n.fromCache || await this.gridDb.addData("gridEntity", {
451
+ id: n.cacheId || "v2_" + t + "_" + r,
452
+ data: n.data
453
+ }), !this.isActiveRequest(a, o)) ? !1 : (this.loadedTiles.has(t) || await this.addGridToMap({
454
+ ...e,
455
+ geoSot: t
456
+ }, s, i, a, o), !0);
457
+ }
458
+ async addTile(e, t) {
459
+ if (this.destroyed) return;
460
+ let n = e.geoSot, r = this.requestVersion;
461
+ if (this.pendingRequests.has(n)) {
462
+ let e = this.pendingRequests.get(n);
463
+ e.cancel && e.cancel();
464
+ }
465
+ let i = m.CancelToken.source(), a = () => i.cancel("请求被取消");
466
+ this.pendingRequests.set(n, { cancel: a });
467
+ try {
468
+ let a = await this.getTileData(n, e.level, t, i);
469
+ this.isActiveRequest(r, i) && await this.addTileDataToMap(e, n, a, t, e.level, r, i);
470
+ } catch (e) {
471
+ this.isActiveRequest(r, i) && !m.isCancel(e) && console.error(`图层 ${this.id} 获取瓦片数据出错:`, e);
472
+ } finally {
473
+ this.pendingRequests.get(n)?.cancel === a && this.pendingRequests.delete(n);
474
+ }
475
+ }
476
+ createUniqueVertices(e, t) {
477
+ let n = e instanceof Float64Array ? e : new Float64Array(e), r = t.length, i = new Float64Array(r * 3), a = new Uint32Array(r);
478
+ for (let e = 0; e < t.length; e++) {
479
+ let r = t[e] * 3;
480
+ i[e * 3] = n[r], i[e * 3 + 1] = n[r + 1], i[e * 3 + 2] = n[r + 2], a[e] = e;
481
+ }
482
+ return {
483
+ positions: i,
484
+ indices: a
485
+ };
486
+ }
487
+ calculateFlatNormalsForUniqueVertices(e, t) {
488
+ let n = new Float32Array(e.length);
489
+ for (let r = 0; r < t.length; r += 3) {
490
+ let i = t[r] * 3, a = t[r + 1] * 3, o = t[r + 2] * 3, s = [
491
+ e[i],
492
+ e[i + 1],
493
+ e[i + 2]
494
+ ], c = [
495
+ e[a],
496
+ e[a + 1],
497
+ e[a + 2]
498
+ ], l = [
499
+ e[o],
500
+ e[o + 1],
501
+ e[o + 2]
502
+ ], u = [
503
+ c[0] - s[0],
504
+ c[1] - s[1],
505
+ c[2] - s[2]
506
+ ], d = [
507
+ l[0] - s[0],
508
+ l[1] - s[1],
509
+ l[2] - s[2]
510
+ ], f = [
511
+ u[1] * d[2] - u[2] * d[1],
512
+ u[2] * d[0] - u[0] * d[2],
513
+ u[0] * d[1] - u[1] * d[0]
514
+ ], p = Math.sqrt(f[0] * f[0] + f[1] * f[1] + f[2] * f[2]), m;
515
+ m = p > 1e-10 && !isNaN(f[0]) && !isNaN(f[1]) && !isNaN(f[2]) && isFinite(f[0]) && isFinite(f[1]) && isFinite(f[2]) ? [
516
+ f[0] / p,
517
+ f[1] / p,
518
+ f[2] / p
519
+ ] : [
520
+ 0,
521
+ 0,
522
+ 1
523
+ ], n[i] = m[0], n[i + 1] = m[1], n[i + 2] = m[2], n[a] = m[0], n[a + 1] = m[1], n[a + 2] = m[2], n[o] = m[0], n[o + 1] = m[1], n[o + 2] = m[2];
524
+ }
525
+ return n;
526
+ }
527
+ async addGridToMap(e, t, n, r, i) {
528
+ if (!this.isActiveRequest(r, i)) return null;
529
+ if (!t || t.length === 0) return console.warn("没有几何数据可渲染"), null;
530
+ let a = e.geoSot, o = await this.loadModelColorsByIds(t.map((e) => e.modelId));
531
+ if (!this.isActiveRequest(r, i)) return null;
532
+ let s = /* @__PURE__ */ new Set();
533
+ for (let e of t) {
534
+ let t = String(e.modelId ?? "").trim();
535
+ if (!t || !e.positions || e.positions.length === 0 || s.has(t)) continue;
536
+ s.add(t);
537
+ let r = this.modelCollections.get(t);
538
+ r && !r.refs.has(a) && r.refs.add(a), r && r.lodLevel !== n && (this.destroyModelCollection(t), r = null), !r && this.createModelCollection(t, e, n, a, o);
539
+ }
540
+ this.tilePointIndex.set(a, s), this.loadedTiles.set(a, { models: s });
541
+ }
542
+ hexToRgba(e) {
543
+ e = e.replace("#", "");
544
+ let t = 1;
545
+ if (e.length === 8) t = parseInt(e.slice(6, 8), 16) / 255;
546
+ else if (e.length !== 6) return console.error("Invalid hex format"), null;
547
+ return `rgba(${parseInt(e.slice(0, 2), 16)}, ${parseInt(e.slice(2, 4), 16)}, ${parseInt(e.slice(4, 6), 16)}, ${t})`;
548
+ }
549
+ destroyHandler() {
550
+ this.handlers &&= (this.viewer && !this.viewer.isDestroyed() && this.viewer.camera.changed.removeEventListener(this.handlers), null), this.clearAllTiles(), this.requestController &&= (this.requestController.abort(), null);
551
+ }
552
+ parseCompressedMeshData(e, t) {
553
+ return C(e, t);
554
+ }
555
+ showPoint(e, t, n, r) {
556
+ this.viewer.entities.add({
557
+ position: Cesium.Cartesian3.fromDegrees(e, t, n),
558
+ point: {
559
+ pixelSize: 5,
560
+ color: Cesium.Color.RED,
561
+ outlineColor: Cesium.Color.WHITE,
562
+ outlineWidth: 2
563
+ },
564
+ id: `debug_${this.id}_${r}`,
565
+ label: {
566
+ text: r + "",
567
+ font: "14pt monospace",
568
+ outlineWidth: 2,
569
+ horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
570
+ pixelOffset: new Cesium.Cartesian2(10, 0)
571
+ }
572
+ });
573
+ }
574
+ }, O = new class {
575
+ constructor() {
576
+ this.layers = /* @__PURE__ */ new Map();
577
+ }
578
+ async createLayer(e) {
579
+ let t = typeof e == "string" ? e : e?.layerId || e?.id, n = typeof e == "object" ? e?.color : void 0, a = e?.level, o = e?.isStatic, s = e?.pointSize, c = e?.opacity;
580
+ if (!t) return console.error("创建图层失败:缺少id参数"), null;
581
+ if (this.layers.has(t)) {
582
+ console.warn(`图层 ${t} 已存在`);
583
+ let o = this.layers.get(t), s = r(o.renderSignature, e || {});
584
+ return n && (o.tileColor = n), o.dictCode = e?.dictCode || o.dictCode || "", o.dataLayerId = e?.dataLayerId || t, o.serviceName = e?.serviceName || o.serviceName || "", e?.displayRange !== void 0 && (o.displayRange = T(e.displayRange)), e?.enableServiceColor !== void 0 && (o.enableServiceColor = !!e.enableServiceColor), o.modelColorUrl = e?.modelColorUrl || o.modelColorUrl || "/v1/zzts/style/render/modelColors", a != null && (o.fixedLevel = a, o.currentNewLevel.value = a), s && (o.renderSignature = i(e || {}), o.modelColorCache.clear(), o.clearAllTiles(), o.getViewportInfo()), o;
585
+ }
586
+ let l = new D(t, o, a, n, s, c, e);
587
+ l.renderSignature = i(e || {}), this.layers.set(t, l);
588
+ try {
589
+ return await l.init(), l.destroyed ? (this.layers.get(t) === l && this.layers.delete(t), null) : l;
590
+ } catch (e) {
591
+ throw this.layers.get(t) === l && this.layers.delete(t), l.remove(), e;
592
+ }
593
+ }
594
+ removeLayer(e) {
595
+ let t = this.layers.get(e);
596
+ t && (this.layers.delete(e), t.remove());
597
+ }
598
+ removeAllLayers() {
599
+ this.layers.forEach((e) => e.remove()), this.layers.clear();
600
+ }
601
+ getLayer(e) {
602
+ return this.layers.get(e);
603
+ }
604
+ getLayerIds() {
605
+ return Array.from(this.layers.keys());
606
+ }
607
+ removeTilesByLayerId(e) {
608
+ let t = this.layers.get(e);
609
+ t && t.removeTilesOnly();
610
+ }
611
+ refreshLayer(e) {
612
+ let t = this.layers.get(e);
613
+ t && t.getViewportInfo();
614
+ }
615
+ }(), k = async (e) => O.createLayer(e, !1), A = (e) => {
616
+ O.removeLayer(e);
617
+ }, j = (e) => O.getLayer(e);
618
+ a(() => {
619
+ let e = O.getLayerIds();
620
+ if (e.length > 0) {
621
+ let t = O.getLayer(e[0]);
622
+ return t ? t.getCurrentLevel() : 15;
623
+ }
624
+ return 15;
625
+ });
626
+ //#endregion
627
+ //#region src/zz-layer/zz-layer-zzts3d-point/index.vue
628
+ var M = {
629
+ __name: "index",
630
+ props: { config: {
631
+ type: Object,
632
+ default: () => ({})
633
+ } },
634
+ emits: ["point-click"],
635
+ setup(e, { emit: t }) {
636
+ let n = o("cesiumViewer");
637
+ p();
638
+ let i = e, d = t, m = l(null), h = l(null), g = c(null), _ = 0, v = 0, y = null, b = !1, x = {
639
+ layerId: "",
640
+ dataLayerId: "",
641
+ color: "255,255,255",
642
+ isStatic: !1,
643
+ level: null,
644
+ pointSize: 5,
645
+ opacity: 1,
646
+ highlightEnabled: !0,
647
+ highlightColor: "255,255,0",
648
+ highlightPointSize: null,
649
+ highlightOpacity: 1,
650
+ highlightToggle: !1,
651
+ highlightClearOnEmptyClick: !1,
652
+ dictCode: "",
653
+ serviceName: "",
654
+ enableServiceColor: !1,
655
+ modelColorUrl: "/v1/zzts/style/render/modelColors",
656
+ displayRange: null
657
+ }, S = a(() => ({
658
+ ...x,
659
+ ...i.config
660
+ })), C = () => {
661
+ g.value = null, h.value?.clearHighlight && h.value.clearHighlight();
662
+ }, w = (e) => {
663
+ e && (g.value = e, h.value?.setHighlight && h.value.setHighlight(e, {
664
+ highlightColor: S.value.highlightColor,
665
+ highlightOpacity: S.value.highlightOpacity,
666
+ highlightPointSize: S.value.highlightPointSize
667
+ }));
668
+ }, T = () => {
669
+ if (m.value) {
670
+ try {
671
+ m.value.destroy();
672
+ } catch {}
673
+ m.value = null;
674
+ }
675
+ };
676
+ function E(e) {
677
+ let t = e.level ? !0 : e.isStatic;
678
+ return {
679
+ layerId: e.layerId,
680
+ dataLayerId: e.dataLayerId || e.layerId,
681
+ color: e.color,
682
+ isStatic: t,
683
+ level: e.level,
684
+ pointSize: e.pointSize,
685
+ opacity: e.opacity,
686
+ dictCode: e.dictCode,
687
+ serviceName: e.serviceName,
688
+ enableServiceColor: e.enableServiceColor,
689
+ modelColorUrl: e.modelColorUrl,
690
+ displayRange: e.displayRange,
691
+ viewer: n.value
692
+ };
693
+ }
694
+ let D = async () => {
695
+ let e = ++_, t = S.value, i = n.value;
696
+ if (!t.layerId || !i || i.isDestroyed()) return;
697
+ let a = E(t), o = j(t.layerId);
698
+ o && o.viewer !== i && (A(t.layerId), o = null);
699
+ let s = o && !r(o.renderSignature, a) ? o : await k(a);
700
+ if (!(b || e !== _ || !s)) {
701
+ if (h.value = s, g.value && S.value.highlightEnabled && h.value?.setHighlight && h.value.setHighlight(g.value, {
702
+ highlightColor: S.value.highlightColor,
703
+ highlightOpacity: S.value.highlightOpacity,
704
+ highlightPointSize: S.value.highlightPointSize
705
+ }), T(), !S.value.highlightEnabled) {
706
+ C();
707
+ return;
708
+ }
709
+ m.value = new Cesium.ScreenSpaceEventHandler(n.value.scene.canvas), m.value.setInputAction(async (e) => {
710
+ let t = ++v;
711
+ y?.abort(), y = new AbortController();
712
+ let r = n.value.scene.pick(e.position), i = Cesium.defined(r) && Cesium.defined(r.primitive) && r.primitive.type === "zzts3dPoint" ? r.primitive : null;
713
+ if (!i) {
714
+ C(), d("point-click", {});
715
+ return;
716
+ }
717
+ let a = i.geomModelId;
718
+ g.value === a ? S.value.highlightToggle && C() : (C(), w(a));
719
+ let o = await f.request({
720
+ method: "POST",
721
+ url: "/v1/zzts/layer/3d/getModelInfo",
722
+ data: { twCode: a },
723
+ timeout: 6e4,
724
+ signal: y.signal
725
+ }), s = await f.request({
726
+ method: "POST",
727
+ url: "/v1/zzts/layer/3d/point/calTaste",
728
+ data: { modelId: a },
729
+ timeout: 6e4,
730
+ signal: y.signal
731
+ });
732
+ b || t !== v || d("point-click", {
733
+ modelId: a,
734
+ baseData: o,
735
+ propData: s
736
+ });
737
+ }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
738
+ }
739
+ }, O = () => {
740
+ T(), g.value = null, h.value = null, A(S.value.layerId || i.config.layerId);
741
+ };
742
+ return u(S, () => {
743
+ D();
744
+ }, { deep: !0 }), u(n, () => {
745
+ D();
746
+ }, { immediate: !0 }), s(() => {
747
+ console.log("组件卸载,开始清理资源..."), b = !0, _++, v++, y?.abort(), y = null, O();
748
+ }), (e, t) => null;
749
+ }
750
+ };
751
+ //#endregion
752
+ export { M as default };