@skzz/components-gis 0.1.3 → 0.1.5

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 (33) hide show
  1. package/dist/assets/twinPreviewWorker-COILIqOa.js +1 -0
  2. package/dist/color-DVYdxZow.js +359 -0
  3. package/dist/esm-BXiGX6xE.js +86 -0
  4. package/dist/index.css +1 -1
  5. package/dist/index.d.ts +71 -6
  6. package/dist/index.es.js +1138 -9563
  7. package/dist/index.umd.js +5 -5
  8. package/dist/interpolation-Ctw2-y9G.js +211 -0
  9. package/dist/layerStack-CbiVJONn.js +181 -0
  10. package/dist/pako.esm-D6zcBi67.js +1455 -0
  11. package/dist/query-DgSNPfJM.js +239 -0
  12. package/dist/queryPoint-BOi_hkig.js +189 -0
  13. package/dist/zz-3dtiles-BzDYB-tW.js +75 -0
  14. package/dist/zz-gltf-BDHxqQjs.js +70 -0
  15. package/dist/zz-layer/zz-layer-shp-zzts/shpZztsCacheUtils.d.ts +53 -0
  16. package/dist/zz-layer/zz-layer-shp-zzts/shpZztsRenderer.d.ts +96 -12
  17. package/dist/zz-layer/zz-layer-zzts/zztsRasterCacheUtils.d.ts +35 -0
  18. package/dist/zz-layer/zz-layer-zzts/zztsRasterPreviewPolling.d.ts +10 -0
  19. package/dist/zz-layer/zz-layer-zzts3dv2/index.vue.d.ts +1 -0
  20. package/dist/zz-layer/zz-layer-zzts3dv2/twinPreviewWorker.d.ts +1 -0
  21. package/dist/zz-layer-geojson-CtTpn_f9.js +867 -0
  22. package/dist/zz-layer-mvt-R1-GwSIW.js +609 -0
  23. package/dist/zz-layer-shp-zzts-D8BjI5tI.js +1323 -0
  24. package/dist/zz-layer-zzts3d-DqZmLdW3.js +835 -0
  25. package/dist/zz-layer-zzts3d-grid-CTHFZBpo.js +314 -0
  26. package/dist/zz-layer-zzts3d-las-hNa-nqxq.js +560 -0
  27. package/dist/zz-layer-zzts3d-point-DrB5Uuwa.js +750 -0
  28. package/dist/zz-layer-zzts3dtype-BRl3mCk9.js +493 -0
  29. package/dist/zz-layer-zzts3dv2-D5udnVGT.js +913 -0
  30. package/dist/zz-terrain-excavation-A2NXSQ5P.js +502 -0
  31. package/dist/zz-viewer/index.vue.d.ts +2 -2
  32. package/dist/zzts3dLayerSignature-Cnu6KIys.js +42 -0
  33. package/package.json +2 -2
@@ -0,0 +1,835 @@
1
+ import { a as e, r as t, u as n } from "./layerStack-CbiVJONn.js";
2
+ import { t as r } from "./pako.esm-D6zcBi67.js";
3
+ import { n as i, t as a } from "./esm-BXiGX6xE.js";
4
+ import { n as o, t as s } from "./zzts3dLayerSignature-Cnu6KIys.js";
5
+ import { computed as c, inject as l, onUnmounted as u, ref as d, watch as f } from "vue";
6
+ import { IndexedDBManager as p, httpService as m } from "@skzz/libs-base";
7
+ import h from "axios";
8
+ import { latlng as g } from "@skzz/libs-gis";
9
+ //#region src/zz-layer/zz-layer-zzts3d/entityGrid.js
10
+ function _(e) {
11
+ if (!e) return null;
12
+ let t = Number(e.longitudeWest ?? e.west), n = Number(e.latitudeSouth ?? e.south), r = Number(e.longitudeEast ?? e.east), i = Number(e.latitudeNorth ?? e.north);
13
+ return ![
14
+ t,
15
+ n,
16
+ r,
17
+ i
18
+ ].every(Number.isFinite) || t < -180 || r > 180 || n < -90 || i > 90 || t >= r || n >= i ? null : {
19
+ west: t,
20
+ south: n,
21
+ east: r,
22
+ north: i
23
+ };
24
+ }
25
+ function v(e, t) {
26
+ if (!e || !t) return null;
27
+ let n = {
28
+ west: Math.max(e.west, t.west),
29
+ south: Math.max(e.south, t.south),
30
+ east: Math.min(e.east, t.east),
31
+ north: Math.min(e.north, t.north)
32
+ };
33
+ return n.west < n.east && n.south < n.north ? n : null;
34
+ }
35
+ var y = class {
36
+ constructor(e, t = !1, n = null, r = "255,255,255", i = "", a = 1, o = {}) {
37
+ this.id = e, this.dataLayerId = o.dataLayerId || e, this.isStatic = t, this.loadedTiles = /* @__PURE__ */ new Map(), this.currentTileIds = /* @__PURE__ */ new Set(), this.currentNewLevel = d(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.serviceType = i, this.opacity = this.normalizeOpacity(a), this.layerOpacity = this.normalizeOpacity(o.layerOpacity ?? 1), this.displayRange = _(o.displayRange), this.lodCalculationRange = _(o.lodCalculationRange), this.fixedLevel = n, this.destroyed = !1, this.requestVersion = 0, this.tileBatchVersion = 0, this.fallbackRenderLevel = null, this.initTimer = null, this.initPromise = null, this.dictCode = o.dictCode || "", this.serviceName = o.serviceName || "", this.enableServiceColor = o.enableServiceColor !== !1, this.modelColorUrl = o.modelColorUrl || "/v1/zzts/style/render/modelColors", this.stackIndex = o.stackIndex ?? -1, this.subStackIndex = o.subStackIndex ?? 0, this.groupKey = o.groupKey || String(this.id), this.modelColorCache = /* @__PURE__ */ new Map(), this.levels_add = window.levels_add_plus || 0, this.tileColor = r, this.tileSleepTime = window.tileSleepTime || 400;
38
+ }
39
+ normalizeOpacity(e) {
40
+ let t = Number(e);
41
+ return Number.isFinite(t) ? Math.max(0, Math.min(1, t)) : 1;
42
+ }
43
+ applyLayerOpacity(e) {
44
+ return new Cesium.Color(e.red, e.green, e.blue, this.normalizeOpacity(e.alpha * this.layerOpacity));
45
+ }
46
+ async init() {
47
+ let e = this.isStatic ? "_static" : "", t = new p(`gridDbs_${this.id}${e}_${this.serviceType}`, 1);
48
+ if (this.gridDb = t, await t.openDatabase("gridEntity", "id"), this.destroyed) {
49
+ t.closeDatabase(), this.gridDb === t && (this.gridDb = null);
50
+ return;
51
+ }
52
+ this.initTimer = setTimeout(() => {
53
+ this.destroyed || (this.isStatic || this.initHandler(), this.getViewportInfo());
54
+ }, 400);
55
+ }
56
+ getCurrentLevel() {
57
+ return this.currentNewLevel.value;
58
+ }
59
+ remove() {
60
+ this.destroyed = !0, this.initTimer &&= (clearTimeout(this.initTimer), null), this.requestController &&= (this.requestController.abort(), null), this.destroyHandler(), this.gridDb?.closeDatabase(), this.gridDb = null, this.modelColorCache.clear();
61
+ }
62
+ removeTilesOnly() {
63
+ this.clearAllTiles();
64
+ }
65
+ clearAllTiles() {
66
+ this.requestVersion += 1, this.fadeAnimations.forEach((e) => {
67
+ e.interval && clearInterval(e.interval);
68
+ }), this.fadeAnimations.clear(), this.pendingRequests.forEach((e) => {
69
+ e.cancel && e.cancel();
70
+ }), this.pendingRequests.clear(), this.currentTileIds = /* @__PURE__ */ new Set();
71
+ for (let [e, t] of this.loadedTiles) t.box && viewer.scene.primitives.contains(t.box) && viewer.scene.primitives.remove(t.box), t.line && viewer.scene.primitives.contains(t.line) && viewer.scene.primitives.remove(t.line);
72
+ this.loadedTiles.clear();
73
+ }
74
+ initHandler1() {
75
+ if (this.getViewportInfo(), this.handlers) try {
76
+ viewer.camera.moveEnd.removeEventListener(this.handlers);
77
+ } catch (e) {
78
+ console.warn("移除旧的事件监听器失败:", e);
79
+ }
80
+ this.handlers = () => {
81
+ this.getViewportInfo();
82
+ }, viewer.camera.moveEnd.addEventListener(this.handlers);
83
+ }
84
+ initHandler() {
85
+ if (this.getViewportInfo(), this.handlers) try {
86
+ viewer.camera.changed.removeEventListener(this.handlers);
87
+ } catch (e) {
88
+ console.warn("移除旧的事件监听器失败:", e);
89
+ }
90
+ let e = null, t = () => {
91
+ clearTimeout(e), e = setTimeout(() => {
92
+ this.getViewportInfo();
93
+ }, 250);
94
+ };
95
+ viewer.camera.changed.addEventListener(t), this.handlers = t;
96
+ }
97
+ getViewportInfo() {
98
+ if (this.destroyed) return;
99
+ this.requestController && this.requestController.abort(), this.requestController = new AbortController(), this.entityNum = 0;
100
+ let e = g.getFrustumGroundIntersectionPoints(viewer), t = g.getCenter(viewer), n = g.getCameraView(viewer);
101
+ if (n.pitch > -18) return;
102
+ let r;
103
+ if (this.isStatic && this.fixedLevel) r = this.fixedLevel + this.levels_add;
104
+ else {
105
+ let i = Cesium.Cartesian3.distance(Cesium.Cartesian3.fromDegrees(t.x, t.y, 0), Cesium.Cartesian3.fromDegrees(n.x, n.y, n.z)), a = g.entityGridLevels.filter((e) => e.max >= i && e.min <= i);
106
+ if (!a[0] || e.length < 4) return;
107
+ r = a[0].level + this.levels_add;
108
+ }
109
+ if (this.currentNewLevel.value = r, e.length < 4) return;
110
+ let o = a(i([
111
+ [e[0].x, e[0].y],
112
+ [e[1].x, e[1].y],
113
+ [e[2].x, e[2].y],
114
+ [e[3].x, e[3].y]
115
+ ])), s = {
116
+ west: o[0],
117
+ south: o[1],
118
+ east: o[2],
119
+ north: o[3]
120
+ }, c = this.displayRange ? v(s, this.displayRange) : s;
121
+ if (!c) {
122
+ this.clearAllTiles();
123
+ return;
124
+ }
125
+ let l = this.lodCalculationRange || c, u = [
126
+ l.west,
127
+ l.south,
128
+ l.east,
129
+ l.north
130
+ ];
131
+ this.getEntityData(u, r, e, c, this.requestController.signal);
132
+ }
133
+ showDebugPoints(e) {
134
+ viewer.entities.values.filter((e) => e.id && e.id.startsWith(`debug_${this.id}_`)).forEach((e) => viewer.entities.remove(e)), e.forEach((e, t) => {
135
+ this.showPoint(e.x, e.y, 1, t);
136
+ });
137
+ }
138
+ async getEntityData(e, t, n, r, i) {
139
+ let a = viewer.scene.canvas, o = a.clientWidth, s = a.clientHeight, c = Number(e[2]) - Number(e[0]), l = Number(e[3]) - Number(e[1]);
140
+ if (!(c > 20 || l > 20)) try {
141
+ let t = await m.request({
142
+ method: "GET",
143
+ url: `/v1/zzts/layer/3d/calTiles?region=${e[0]},${e[1]},0,${e[2]},${e[3]},10&width=${o}&height=${s}`,
144
+ timeout: 6e4,
145
+ signal: i
146
+ });
147
+ !i.aborted && !this.destroyed && this.render3DFaces(t.tiles, t.lodLevel, r);
148
+ } catch (e) {
149
+ e.name !== "AbortError" && console.error(`图层 ${this.id} 获取实体数据出错:`, e);
150
+ }
151
+ }
152
+ render3DFaces(e, t, n = null) {
153
+ if (this.destroyed) return;
154
+ let r = ++this.tileBatchVersion;
155
+ t === 17 && this.fallbackRenderLevel === 16 && (e = this.collapseLevel17TilesToParents(e), t = 16), this.lastTime = (/* @__PURE__ */ new Date()).getTime();
156
+ let i = g.getCameraView(viewer);
157
+ e.forEach((e) => {
158
+ if (this.isStatic && this.fixedLevel) e.geoSot = e.geoSot, e.level = t;
159
+ else {
160
+ let n = Cesium.Cartesian3.distance(Cesium.Cartesian3.fromDegrees((e.xmax + e.xmin) / 2, (e.ymax + e.ymin) / 2, 0), Cesium.Cartesian3.fromDegrees(i.x, i.y, i.z));
161
+ g.entityGridLevels.filter((e) => e.max >= n && e.min <= n), e.geoSot = e.geoSot, e.level = t;
162
+ }
163
+ });
164
+ let a = (Array.isArray(e) ? e : []).filter((e) => n ? !!v({
165
+ west: Number(e?.xmin),
166
+ south: Number(e?.ymin),
167
+ east: Number(e?.xmax),
168
+ north: Number(e?.ymax)
169
+ }, n) : !0), o = new Set(a.map((e) => e.geoSot)), s = [], c = [];
170
+ this.currentTileIds.forEach((e) => {
171
+ o.has(e) || c.push(e);
172
+ }), o.forEach((e) => {
173
+ if (!this.currentTileIds.has(e)) {
174
+ let t = a.find((t) => e === t.geoSot);
175
+ t && s.push(t);
176
+ }
177
+ });
178
+ let l = this.requestVersion, u = s.map((e) => this.addTile(e, e.level, l));
179
+ t === 17 && u.length > 0 && this.fallbackRenderLevel !== 16 && Promise.all(u).then((t) => {
180
+ !this.isActiveRequest(l) || this.tileBatchVersion !== r || this.fallbackRenderLevel === 16 || !a.some((e) => this.loadedTiles.has(e.geoSot)) && t.every((e) => e === "empty") && (this.fallbackRenderLevel = 16, this.render3DFaces(e, 17, n));
181
+ }), c.forEach((e) => {
182
+ let t = this.loadedTiles.get(e);
183
+ t && this.fadeOut(t, e);
184
+ }), this.currentTileIds = o;
185
+ }
186
+ collapseLevel17TilesToParents(e) {
187
+ let t = /* @__PURE__ */ new Map();
188
+ for (let n of Array.isArray(e) ? e : []) {
189
+ let e = this.getParentGeoSot(n?.geoSot);
190
+ if (!e) continue;
191
+ let r = t.get(e);
192
+ if (!r) {
193
+ t.set(e, {
194
+ ...n,
195
+ geoSot: e,
196
+ level: 16
197
+ });
198
+ continue;
199
+ }
200
+ r.xmin = Math.min(Number(r.xmin), Number(n.xmin)), r.ymin = Math.min(Number(r.ymin), Number(n.ymin)), r.xmax = Math.max(Number(r.xmax), Number(n.xmax)), r.ymax = Math.max(Number(r.ymax), Number(n.ymax));
201
+ }
202
+ return Array.from(t.values());
203
+ }
204
+ getParentGeoSot(e) {
205
+ let t = String(e || "").replaceAll("-", "");
206
+ if (!/^G[0-3]{17}$/.test(t)) return null;
207
+ let n = t.slice(1, -1);
208
+ return `G${n.slice(0, 9)}-${n.slice(9, 15)}-${n.slice(15)}`;
209
+ }
210
+ fadeOut(e, t) {
211
+ if (this.fadeAnimations.has(t)) {
212
+ let e = this.fadeAnimations.get(t);
213
+ e.interval && clearInterval(e.interval);
214
+ }
215
+ let n = 0, r = this.tileSleepTime / 100, i = setInterval(() => {
216
+ if (n < r) e.box && e.box.appearance, n++;
217
+ else {
218
+ if (clearInterval(i), this.fadeAnimations.delete(t), this.currentTileIds && this.currentTileIds.has(t)) return;
219
+ e.box && viewer.scene.primitives.contains(e.box) && viewer.scene.primitives.remove(e.box), e.line && viewer.scene.primitives.contains(e.line) && viewer.scene.primitives.remove(e.line), this.loadedTiles.delete(t);
220
+ }
221
+ }, 100);
222
+ this.fadeAnimations.set(t, { interval: i });
223
+ }
224
+ isActiveRequest(e, t) {
225
+ return !this.destroyed && this.requestVersion === e && !t?.token?.reason;
226
+ }
227
+ async addTile(e, t, n = this.requestVersion) {
228
+ if (!this.isActiveRequest(n)) return "cancelled";
229
+ let r = e.geoSot;
230
+ if (this.pendingRequests.has(r)) {
231
+ let e = this.pendingRequests.get(r);
232
+ e.cancel && e.cancel();
233
+ }
234
+ let i = h.CancelToken.source(), a = () => i.cancel("请求被取消");
235
+ this.pendingRequests.set(r, { cancel: a });
236
+ try {
237
+ let a = `v2_${r}_${t}`, o = await this.gridDb.getDataById("gridEntity", a);
238
+ if (!this.isActiveRequest(n, i)) return "cancelled";
239
+ if (o) return o.data.byteLength > 47 ? (await this.addGridToMap(e, this.parseCompressedMeshData(o.data, e.level), e.level, n, i), "hit") : "empty";
240
+ if (!o) {
241
+ let t = await m.request({
242
+ method: "GET",
243
+ url: `/v1/zzts/layer/3d/getTileNew?layerId=${this.dataLayerId}&level=${e.level}&geosot=${e.geoSot}`,
244
+ headers: { Accept: "application/octet-stream" },
245
+ responseType: "arraybuffer",
246
+ timeout: 6e4,
247
+ cancelToken: i.token
248
+ });
249
+ return this.isActiveRequest(n, i) && t.data.byteLength > 47 ? (await this.gridDb.addData("gridEntity", {
250
+ id: a,
251
+ data: t.data
252
+ }), this.isActiveRequest(n, i) ? (await this.addGridToMap(e, this.parseCompressedMeshData(t.data, e.level), e.level, n, i), "hit") : "cancelled") : this.isActiveRequest(n, i) ? "empty" : "cancelled";
253
+ }
254
+ } catch (e) {
255
+ return h.isCancel(e) ? "cancelled" : (console.error(`图层 ${this.id} 获取瓦片数据出错:`, e), "error");
256
+ } finally {
257
+ this.pendingRequests.get(r)?.cancel === a && this.pendingRequests.delete(r);
258
+ }
259
+ }
260
+ createUniqueVertices(e, t) {
261
+ let n = e instanceof Float64Array ? e : new Float64Array(e), r = t.length, i = new Float64Array(r * 3), a = new Uint32Array(r);
262
+ for (let e = 0; e < t.length; e++) {
263
+ let r = t[e] * 3;
264
+ i[e * 3] = n[r], i[e * 3 + 1] = n[r + 1], i[e * 3 + 2] = n[r + 2], a[e] = e;
265
+ }
266
+ return {
267
+ positions: i,
268
+ indices: a
269
+ };
270
+ }
271
+ calculateFlatNormalsForUniqueVertices(e, t) {
272
+ let n = new Float32Array(e.length);
273
+ for (let r = 0; r < t.length; r += 3) {
274
+ let i = t[r] * 3, a = t[r + 1] * 3, o = t[r + 2] * 3, s = [
275
+ e[i],
276
+ e[i + 1],
277
+ e[i + 2]
278
+ ], c = [
279
+ e[a],
280
+ e[a + 1],
281
+ e[a + 2]
282
+ ], l = [
283
+ e[o],
284
+ e[o + 1],
285
+ e[o + 2]
286
+ ], u = [
287
+ c[0] - s[0],
288
+ c[1] - s[1],
289
+ c[2] - s[2]
290
+ ], d = [
291
+ l[0] - s[0],
292
+ l[1] - s[1],
293
+ l[2] - s[2]
294
+ ], f = [
295
+ u[1] * d[2] - u[2] * d[1],
296
+ u[2] * d[0] - u[0] * d[2],
297
+ u[0] * d[1] - u[1] * d[0]
298
+ ], p = Math.sqrt(f[0] * f[0] + f[1] * f[1] + f[2] * f[2]), m;
299
+ m = p > 1e-10 && !isNaN(f[0]) && !isNaN(f[1]) && !isNaN(f[2]) && isFinite(f[0]) && isFinite(f[1]) && isFinite(f[2]) ? [
300
+ f[0] / p,
301
+ f[1] / p,
302
+ f[2] / p
303
+ ] : [
304
+ 0,
305
+ 0,
306
+ 1
307
+ ], 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];
308
+ }
309
+ return n;
310
+ }
311
+ async addGridToMap(e, n, r, i, a) {
312
+ if (!this.isActiveRequest(i, a)) return null;
313
+ if (!n || n.length === 0) return console.warn("没有几何数据可渲染"), null;
314
+ let o = [...new Set(n.map((e) => String(e.modelId || "").trim()).filter((e) => e))], s = await this.loadModelColorsByIds(o);
315
+ if (!this.isActiveRequest(i, a)) return null;
316
+ this.styleDebug("开始渲染瓦片颜色", {
317
+ geoSot: e.geoSot,
318
+ level: r,
319
+ geometriesCount: n.length,
320
+ serviceColorEnabled: this.isServiceColorEnabled(),
321
+ serviceColorMapSize: s.size
322
+ });
323
+ let c = n.map((t) => {
324
+ if (!t.positions || t.positions.length === 0) return console.warn("跳过无效的几何体:缺少顶点数据"), null;
325
+ if (!t.indices || t.indices.length === 0) return console.warn("跳过无效的几何体:缺少索引数据"), null;
326
+ let n, i, a;
327
+ r > 14 ? (i = this.createUniqueVertices(t.positions, t.indices).positions, a = this.createUniqueVertices(t.positions, t.indices).indices, n = this.calculateFlatNormalsForUniqueVertices(i, a)) : (n = this.calculateFlatNormalsForUniqueVertices(t.positions, t.indices), i = new Float64Array(t.positions), a = new Uint32Array(t.indices));
328
+ let o = i.length / 3, c = new Float32Array(o * 2);
329
+ for (let e = 0; e < o; e++) c[e * 2] = 0, c[e * 2 + 1] = 0;
330
+ let l = new Cesium.Geometry({
331
+ attributes: {
332
+ position: new Cesium.GeometryAttribute({
333
+ componentDatatype: Cesium.ComponentDatatype.DOUBLE,
334
+ componentsPerAttribute: 3,
335
+ values: i,
336
+ normalize: !1
337
+ }),
338
+ st: new Cesium.GeometryAttribute({
339
+ componentDatatype: Cesium.ComponentDatatype.FLOAT,
340
+ componentsPerAttribute: 2,
341
+ values: c
342
+ }),
343
+ normal: new Cesium.GeometryAttribute({
344
+ componentDatatype: Cesium.ComponentDatatype.FLOAT,
345
+ componentsPerAttribute: 3,
346
+ values: n,
347
+ normalize: !1
348
+ })
349
+ },
350
+ indices: a,
351
+ primitiveType: Cesium.PrimitiveType.TRIANGLES,
352
+ boundingSphere: Cesium.BoundingSphere.fromVertices(i)
353
+ });
354
+ if (l.modelId = t.modelId ? String(t.modelId).trim() : "", this.isServiceColorEnabled() && l.modelId) {
355
+ let n = s.get(l.modelId);
356
+ n ? l.color = n : (console.warn("[zzts-style] 当前模型没有匹配到服务颜色,使用原始颜色", {
357
+ serviceName: this.serviceName,
358
+ dictCode: this.dictCode,
359
+ modelId: l.modelId,
360
+ geoSot: e.geoSot,
361
+ level: r
362
+ }), l.color = t.color);
363
+ } else l.color = t.color;
364
+ return l;
365
+ }).filter((e) => e !== null).map((e) => {
366
+ let t = e.color, n = null;
367
+ if (!t || t === "#C2D6E2FF" || t === "#00000000") n = `rgba(${this.tileColor}, ${this.opacity})`;
368
+ else if (typeof t == "string" && (t.startsWith("rgba(") || t.startsWith("rgb("))) n = t;
369
+ else try {
370
+ n = this.hexToRgba(t);
371
+ } catch {
372
+ n = "rgba(255,255,255, 1)";
373
+ }
374
+ n ||= "rgba(255,255,255, 1)";
375
+ let r = Cesium.Color.fromCssColorString(`${n}`);
376
+ return {
377
+ geometry: e,
378
+ color: this.applyLayerOpacity(r || Cesium.Color.fromCssColorString("rgba(255,255,255, 1)"))
379
+ };
380
+ }), l = c.some((e) => e.color.alpha < .999), u = l ? {
381
+ depthTest: {
382
+ enabled: !0,
383
+ func: Cesium.DepthFunction.LESS_OR_EQUAL
384
+ },
385
+ blending: Cesium.BlendingState.ALPHA_BLEND
386
+ } : { depthTest: {
387
+ enabled: !0,
388
+ func: Cesium.DepthFunction.LESS_OR_EQUAL
389
+ } }, d = c.map(({ geometry: t, color: n }, r) => new Cesium.GeometryInstance({
390
+ geometry: t,
391
+ id: t.modelId || `${e.geoSot}_${r}`,
392
+ attributes: {
393
+ color: Cesium.ColorGeometryInstanceAttribute.fromColor(n),
394
+ show: new Cesium.ShowGeometryInstanceAttribute(!0)
395
+ }
396
+ }));
397
+ if (!this.isActiveRequest(i, a)) return null;
398
+ let f = new Cesium.Primitive({
399
+ geometryInstances: d,
400
+ asynchronous: !1,
401
+ compressVertices: !1,
402
+ releaseGeometryInstances: !1,
403
+ appearance: new Cesium.PerInstanceColorAppearance({
404
+ vertexFormat: Cesium.VertexFormat.POSITION_AND_NORMAL,
405
+ flat: !1,
406
+ translucent: l,
407
+ renderState: u
408
+ })
409
+ });
410
+ if (f.layerId = this.id, f.geoSot = e.geoSot, t(viewer, f, this.stackIndex, 0, {
411
+ layerType: "zzts3d",
412
+ groupKey: this.groupKey || String(this.id),
413
+ subStackIndex: this.subStackIndex ?? 0,
414
+ tileOrder: this.loadedTiles.size
415
+ }), !this.isActiveRequest(i, a)) return viewer.scene.primitives.remove(f), null;
416
+ let p = 0, m = this.tileSleepTime / 100, h = setInterval(() => {
417
+ if (!this.isActiveRequest(i, a)) {
418
+ clearInterval(h);
419
+ return;
420
+ }
421
+ p <= m * this.opacity ? (f && f.appearance, p++) : (clearInterval(h), this.fadeAnimations.has(e.geoSot) && this.fadeAnimations.delete(e.geoSot), this.removeOldEntities(e.geoSot));
422
+ }, 100);
423
+ if (!this.isActiveRequest(i, a)) return clearInterval(h), viewer.scene.primitives.remove(f), null;
424
+ this.fadeAnimations.set(e.geoSot, { interval: h }), this.loadedTiles.set(e.geoSot, { box: f });
425
+ }
426
+ updateOptions(e = {}) {
427
+ e.color && (this.tileColor = e.color), e.opacity !== void 0 && e.opacity !== null && (this.opacity = this.normalizeOpacity(e.opacity)), e.layerOpacity !== void 0 && e.layerOpacity !== null && (this.layerOpacity = this.normalizeOpacity(e.layerOpacity)), e.level !== void 0 && (this.fixedLevel = e.level, e.level && (this.currentNewLevel.value = e.level)), e.displayRange !== void 0 && (this.displayRange = _(e.displayRange)), e.dataLayerId !== void 0 && (this.dataLayerId = e.dataLayerId || this.id), e.lodCalculationRange !== void 0 && (this.lodCalculationRange = _(e.lodCalculationRange)), e.serviceType !== void 0 && (this.serviceType = e.serviceType), this.dictCode = e.dictCode || this.dictCode || "", this.serviceName = e.serviceName || this.serviceName || "", e.enableServiceColor !== void 0 && (this.enableServiceColor = !!e.enableServiceColor), this.modelColorUrl = e.modelColorUrl || this.modelColorUrl || "/v1/zzts/style/render/modelColors", this.modelColorCache.clear(), e.stackIndex !== void 0 && (this.stackIndex = e.stackIndex), e.subStackIndex !== void 0 && (this.subStackIndex = e.subStackIndex), e.groupKey !== void 0 && (this.groupKey = e.groupKey), this.applyStackIndex();
428
+ }
429
+ applyStackIndex() {
430
+ if (this.stackIndex < 0 || !viewer) return;
431
+ let t = 0;
432
+ this.loadedTiles.forEach((n) => {
433
+ n?.box && e(viewer, n.box, this.stackIndex, {
434
+ layerType: "zzts3d",
435
+ groupKey: this.groupKey || String(this.id),
436
+ subStackIndex: this.subStackIndex ?? 0,
437
+ tileOrder: t++
438
+ });
439
+ }), n(viewer);
440
+ }
441
+ styleDebug(...e) {
442
+ window.__ZZTS_STYLE_DEBUG__ && console.log("[zzts-style]", ...e);
443
+ }
444
+ unwrapResponseData(e) {
445
+ return e?.data?.data === void 0 ? e?.data === void 0 ? e : e.data : e.data.data;
446
+ }
447
+ isServiceColorEnabled() {
448
+ let e = !!(this.enableServiceColor && this.serviceName && this.dictCode && this.modelColorUrl);
449
+ return e || this.styleDebug("服务颜色渲染未启用", {
450
+ enableServiceColor: this.enableServiceColor,
451
+ serviceName: this.serviceName,
452
+ dictCode: this.dictCode,
453
+ modelColorUrl: this.modelColorUrl
454
+ }), e;
455
+ }
456
+ async loadModelColorsByIds(e = []) {
457
+ if (!this.isServiceColorEnabled()) return /* @__PURE__ */ new Map();
458
+ let t = [...new Set(e.map((e) => String(e || "").trim()).filter((e) => e))];
459
+ if (t.length === 0) return /* @__PURE__ */ new Map();
460
+ let n = /* @__PURE__ */ new Map(), r = [];
461
+ if (t.forEach((e) => {
462
+ this.modelColorCache.has(e) ? n.set(e, this.modelColorCache.get(e)) : r.push(e);
463
+ }), r.length === 0) return n;
464
+ for (let e = 0; e < r.length; e += 800) {
465
+ let t = r.slice(e, e + 800);
466
+ try {
467
+ let e = await m.request({
468
+ method: "POST",
469
+ url: this.modelColorUrl,
470
+ data: {
471
+ serviceName: this.serviceName,
472
+ dictCode: this.dictCode,
473
+ modelIds: t
474
+ },
475
+ timeout: 6e4
476
+ }), r = this.unwrapResponseData(e)?.rows || [];
477
+ r.forEach((e) => {
478
+ let t = String(e.modelId || e.model_id || "").trim(), r = e.color;
479
+ t && r && (this.modelColorCache.set(t, r), n.set(t, r));
480
+ });
481
+ let i = new Set(r.map((e) => String(e.modelId || e.model_id || "").trim()).filter(Boolean)), a = t.filter((e) => !i.has(e));
482
+ a.length > 0 && console.warn("[zzts-style] 部分模型没有查询到颜色", {
483
+ serviceName: this.serviceName,
484
+ dictCode: this.dictCode,
485
+ requestCount: t.length,
486
+ hitCount: r.length,
487
+ missingCount: a.length,
488
+ missingSample: a.slice(0, 20)
489
+ });
490
+ } catch (e) {
491
+ console.error("[zzts-style] 查询模型颜色失败", {
492
+ serviceName: this.serviceName,
493
+ dictCode: this.dictCode,
494
+ requestCount: t.length,
495
+ sample: t.slice(0, 20),
496
+ error: e
497
+ });
498
+ }
499
+ }
500
+ return n;
501
+ }
502
+ hexToRgba(e) {
503
+ e = e.replace("#", "");
504
+ let t = 1;
505
+ if (e.length === 8) t = parseInt(e.slice(6, 8), 16) / 255;
506
+ else if (e.length !== 6) return console.error("无效的十六进制颜色格式"), null;
507
+ return `rgba(${parseInt(e.slice(0, 2), 16)}, ${parseInt(e.slice(2, 4), 16)}, ${parseInt(e.slice(4, 6), 16)}, ${t})`;
508
+ }
509
+ removeOldEntities(e) {
510
+ let t = this.currentTileIds, n = viewer?.scene?.primitives?._primitives, r = e?.length, i = [];
511
+ if (Array.isArray(n)) for (let e = 0; e < n.length; e++) {
512
+ let a = n[e];
513
+ !a || !a.geoSot || a.layerId !== this.id || t && t.has(a.geoSot) || r != null && a.geoSot.length === r || i.push(a);
514
+ }
515
+ for (let e = 0; e < i.length; e++) {
516
+ let t = i[e];
517
+ viewer.scene.primitives.remove(t);
518
+ }
519
+ }
520
+ destroyHandler() {
521
+ this.handlers &&= (viewer.camera.changed.removeEventListener(this.handlers), null), this.clearAllTiles(), this.requestController &&= (this.requestController.abort(), null);
522
+ }
523
+ parseCompressedMeshData1(e) {
524
+ if (!(e instanceof ArrayBuffer)) return console.error("输入数据不是 ArrayBuffer"), null;
525
+ let t;
526
+ try {
527
+ t = r.inflate(e);
528
+ } catch {
529
+ return null;
530
+ }
531
+ let n = new DataView(t.buffer), i = 0, a = n.getInt32(i, !1);
532
+ i += 4;
533
+ let o = [];
534
+ for (let e = 0; e < a; e++) {
535
+ let e = n.getBigInt64(i, !1).toString();
536
+ i += 8;
537
+ let t = n.getInt32(i, !1);
538
+ i += 4;
539
+ let r = n.getInt32(i, !1);
540
+ i += 4;
541
+ let a = t / 8, s = a / 3, c = r / 4;
542
+ if (!Number.isInteger(a) || !Number.isInteger(s)) return console.error(` 坐标数量: ${a}, 顶点数量: ${s}`), null;
543
+ let l = new Float64Array(a);
544
+ for (let e = 0; e < a; e++) l[e] = n.getFloat64(i, !1), i += 8;
545
+ let u = new Uint32Array(c);
546
+ for (let e = 0; e < c; e++) u[e] = n.getUint32(i, !1), i += 4;
547
+ let d = {
548
+ positions: l,
549
+ indices: u,
550
+ vertexCount: s,
551
+ indexCount: c,
552
+ modelId: e
553
+ };
554
+ o.push(d);
555
+ }
556
+ return o;
557
+ }
558
+ parseCompressedMeshData(e, t) {
559
+ let n = [], i = new DataView(e);
560
+ if (t <= 14) {
561
+ let a = 0, o = i.getInt32(a, !0);
562
+ a += 4;
563
+ for (let s = 0; s < o; s++) {
564
+ let o = i.getInt32(a, !0);
565
+ a += 4;
566
+ let s = new Uint8Array(e, a, o);
567
+ a += o;
568
+ let c = r.inflate(s), l = new DataView(c.buffer, c.byteOffset), u = 0, d = l.getBigInt64(u, !0);
569
+ u += 8;
570
+ let f = l.getInt32(u, !0);
571
+ u += 4;
572
+ let p = l.getInt32(u, !0);
573
+ u += 4;
574
+ let m = f / 4, h = m / 3, g = p / 4, _ = new Float64Array(m);
575
+ for (let e = 0; e < m; e++) _[e] = l.getInt32(u, !0), u += 4;
576
+ let v = new Int32Array(g);
577
+ for (let e = 0; e < g; e++) v[e] = l.getInt32(u, !0), u += 4;
578
+ n.push({
579
+ positions: _,
580
+ indices: v,
581
+ vertexCount: h,
582
+ indexCount: g,
583
+ modelId: d.toString(),
584
+ lodLevel: t
585
+ });
586
+ }
587
+ } else if (t < 18) {
588
+ let a = 0, o = i.getInt32(a, !0);
589
+ a += 4;
590
+ for (let s = 0; s < o; s++) {
591
+ let o = i.getInt32(a, !0);
592
+ a += 4;
593
+ let s = new Uint8Array(e, a, o);
594
+ a += o;
595
+ let c = r.inflate(s), l = new DataView(c.buffer, c.byteOffset), u = 0, d = l.getInt32(u, !0);
596
+ u += 4;
597
+ for (let e = 0; e < d; e++) {
598
+ let e = l.getBigInt64(u, !0);
599
+ u += 8;
600
+ let r = l.getInt32(u, !0);
601
+ u += 4;
602
+ let i = l.getInt32(u, !0);
603
+ u += 4;
604
+ let a = r, o = new Float64Array(a);
605
+ for (let e = 0; e < a; e++) o[e] = l.getInt32(u, !0) / 100, u += 4;
606
+ let s = new Uint32Array(i);
607
+ for (let e = 0; e < i; e++) s[e] = l.getInt32(u, !0), u += 4;
608
+ n.push({
609
+ positions: o,
610
+ indices: s,
611
+ vertexCount: r,
612
+ indexCount: i,
613
+ modelId: e.toString(),
614
+ lodLevel: t
615
+ });
616
+ }
617
+ }
618
+ } else {
619
+ let a = 0, o = i.getInt32(a, !0);
620
+ a += 4;
621
+ for (let s = 0; s < o; s++) {
622
+ let o = i.getInt32(a, !0);
623
+ a += 4;
624
+ let s = new Uint8Array(e, a, o);
625
+ a += o;
626
+ let c = r.inflate(s), l = new DataView(c.buffer, c.byteOffset), u = 0, d = l.getBigInt64(u, !0);
627
+ u += 8;
628
+ let f = l.getInt32(u, !0);
629
+ u += 4;
630
+ let p = l.getInt32(u, !0);
631
+ u += 4;
632
+ let m = f / 4, h = p / 4, g = new Float64Array(m);
633
+ for (let e = 0; e < m; e++) g[e] = l.getInt32(u, !0) / 100, u += 4;
634
+ let _ = new Uint32Array(h);
635
+ for (let e = 0; e < h; e++) _[e] = l.getUint32(u, !0), u += 4;
636
+ n.push({
637
+ positions: g,
638
+ indices: _,
639
+ positionCount: m,
640
+ indexCount: h,
641
+ modelId: d.toString(),
642
+ lodLevel: t
643
+ });
644
+ }
645
+ }
646
+ return n;
647
+ }
648
+ showPoint(e, t, n, r) {
649
+ viewer.entities.add({
650
+ position: Cesium.Cartesian3.fromDegrees(e, t, n),
651
+ point: {
652
+ pixelSize: 5,
653
+ color: Cesium.Color.RED,
654
+ outlineColor: Cesium.Color.WHITE,
655
+ outlineWidth: 2
656
+ },
657
+ id: `debug_${this.id}_${r}`,
658
+ label: {
659
+ text: r + "",
660
+ font: "14pt monospace",
661
+ outlineWidth: 2,
662
+ horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
663
+ pixelOffset: new Cesium.Cartesian2(10, 0)
664
+ }
665
+ });
666
+ }
667
+ }, b = new class {
668
+ constructor() {
669
+ this.layers = /* @__PURE__ */ new Map();
670
+ }
671
+ async createLayer(e) {
672
+ let t = typeof e == "string" ? e : e?.layerId || e?.id, n = typeof e == "object" ? e?.color : void 0, r = e?.level, i = e?.isStatic, a = e?.serviceType, c = e?.opacity, l = e?.layerOpacity;
673
+ if (!t) return console.error("创建图层失败:缺少id参数"), null;
674
+ if (this.layers.has(t)) {
675
+ console.warn(`图层 ${t} 已存在,更新图层配置`);
676
+ let n = this.layers.get(t);
677
+ if (n.initPromise && await n.initPromise, n.destroyed) return this.layers.get(t) === n && this.layers.delete(t), this.createLayer(e);
678
+ if (this.layers.get(t) !== n) return this.createLayer(e);
679
+ let r = o(n.renderSignature, e || {});
680
+ return typeof n.updateOptions == "function" && (r ? n.updateOptions(e || {}) : n.updateOptions({
681
+ stackIndex: e?.stackIndex,
682
+ subStackIndex: e?.subStackIndex,
683
+ groupKey: e?.groupKey
684
+ })), r && (n.renderSignature = s(e || {}), n.removeTilesOnly(), n.getViewportInfo()), n;
685
+ }
686
+ let u = new y(t, i, r, n, a, c, {
687
+ ...e || {},
688
+ layerOpacity: l
689
+ });
690
+ u.renderSignature = s(e || {}), u.initPromise = u.init(), this.layers.set(t, u);
691
+ try {
692
+ return await u.initPromise, u.destroyed ? (this.layers.get(t) === u && this.layers.delete(t), null) : u;
693
+ } catch (e) {
694
+ throw this.layers.get(t) === u && this.layers.delete(t), u.remove(), e;
695
+ }
696
+ }
697
+ removeLayer(e) {
698
+ let t = this.layers.get(e);
699
+ t && (t.remove(), this.layers.delete(e));
700
+ }
701
+ removeAllLayers() {
702
+ this.layers.forEach((e) => e.remove()), this.layers.clear();
703
+ }
704
+ getLayer(e) {
705
+ return this.layers.get(e);
706
+ }
707
+ getLayerIds() {
708
+ return Array.from(this.layers.keys());
709
+ }
710
+ removeTilesByLayerId(e) {
711
+ let t = this.layers.get(e);
712
+ t && t.removeTilesOnly();
713
+ }
714
+ refreshLayer(e) {
715
+ let t = this.layers.get(e);
716
+ t && t.getViewportInfo();
717
+ }
718
+ }(), x = async (e) => b.createLayer(e, !1), S = (e) => {
719
+ b.removeLayer(e);
720
+ }, C = (e) => b.getLayer(e);
721
+ c(() => {
722
+ let e = b.getLayerIds();
723
+ if (e.length > 0) {
724
+ let t = b.getLayer(e[0]);
725
+ return t ? t.getCurrentLevel() : 15;
726
+ }
727
+ return 15;
728
+ });
729
+ //#endregion
730
+ //#region src/zz-layer/zz-layer-zzts3d/index.vue
731
+ var w = {
732
+ __name: "index",
733
+ props: {
734
+ config: {
735
+ type: Object,
736
+ default: () => ({})
737
+ },
738
+ stackIndex: {
739
+ type: Number,
740
+ default: -1
741
+ },
742
+ subStackIndex: {
743
+ type: Number,
744
+ default: 0
745
+ },
746
+ groupKey: {
747
+ type: String,
748
+ default: ""
749
+ }
750
+ },
751
+ setup(e) {
752
+ l("cesiumViewer");
753
+ let t = e, n = {
754
+ layerId: "",
755
+ dataLayerId: "",
756
+ color: "255,255,255",
757
+ isStatic: !1,
758
+ level: null,
759
+ serviceType: "",
760
+ opacity: 1,
761
+ layerOpacity: 1,
762
+ dictCode: "",
763
+ serviceName: "",
764
+ enableServiceColor: !0,
765
+ modelColorUrl: "/v1/zzts/style/render/modelColors",
766
+ displayRange: null,
767
+ lodCalculationRange: null
768
+ }, r = c(() => ({
769
+ ...n,
770
+ ...t.config
771
+ })), i = "";
772
+ function a(e) {
773
+ let n = e.level ? !0 : e.isStatic;
774
+ return {
775
+ layerId: e.layerId,
776
+ dataLayerId: e.dataLayerId,
777
+ color: e.color,
778
+ isStatic: n,
779
+ level: e.level,
780
+ serviceType: e.serviceType,
781
+ opacity: e.opacity,
782
+ layerOpacity: e.layerOpacity,
783
+ dictCode: e.dictCode,
784
+ serviceName: e.serviceName,
785
+ enableServiceColor: e.enableServiceColor,
786
+ modelColorUrl: e.modelColorUrl,
787
+ displayRange: e.displayRange,
788
+ lodCalculationRange: e.lodCalculationRange,
789
+ stackIndex: t.stackIndex,
790
+ subStackIndex: t.subStackIndex,
791
+ groupKey: t.groupKey || e.layerId
792
+ };
793
+ }
794
+ let s = async () => {
795
+ let e = r.value;
796
+ if (!e.layerId) {
797
+ console.warn("[zzLayerZzts3d] 缺少 layerId,跳过初始化", e);
798
+ return;
799
+ }
800
+ let t = a(e), n = C(e.layerId);
801
+ if (n && !o(n.renderSignature, t)) {
802
+ typeof n.updateOptions == "function" && n.updateOptions(t), i = e.layerId;
803
+ return;
804
+ }
805
+ await x(t), i = e.layerId;
806
+ }, d = () => {
807
+ S(r.value.layerId);
808
+ };
809
+ return f(() => t.config, async () => {
810
+ await s();
811
+ }, {
812
+ deep: !0,
813
+ immediate: !0
814
+ }), f(() => [
815
+ t.stackIndex,
816
+ t.subStackIndex,
817
+ t.groupKey
818
+ ], () => {
819
+ let e = r.value, n = C(e.layerId);
820
+ if (n && typeof n.updateOptions == "function") {
821
+ n.updateOptions({
822
+ stackIndex: t.stackIndex,
823
+ subStackIndex: t.subStackIndex,
824
+ groupKey: t.groupKey || e.layerId
825
+ });
826
+ return;
827
+ }
828
+ s();
829
+ }), u(() => {
830
+ i ? S(i) : d();
831
+ }), (e, t) => null;
832
+ }
833
+ };
834
+ //#endregion
835
+ export { w as default };