@skzz/components-gis 0.1.5 → 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 (37) hide show
  1. package/dist/assets/twinPreviewWorker-DvpSZYqE.js +3 -0
  2. package/dist/assets/twinTextureMipWorker-BWoFEUdX.js +3 -0
  3. package/dist/index.d.ts +5 -4
  4. package/dist/index.es.js +380 -360
  5. package/dist/index.umd.js +209 -5
  6. package/dist/tw2Parser-Dxs5xGvB.js +115 -0
  7. package/dist/zz-layer/zz-layer-shp-zzts/shpZztsBounds.d.ts +19 -0
  8. package/dist/zz-layer/zz-layer-shp-zzts/shpZztsGeometry.d.ts +27 -0
  9. package/dist/zz-layer/zz-layer-shp-zzts/shpZztsGeometryWorker.d.ts +1 -0
  10. package/dist/zz-layer/zz-layer-shp-zzts/shpZztsPreviewBudget.d.ts +78 -0
  11. package/dist/zz-layer/zz-layer-shp-zzts/shpZztsRenderer.d.ts +217 -22
  12. package/dist/zz-layer/zz-layer-shp-zzts/shpZztsViewState.d.ts +20 -0
  13. package/dist/zz-layer/zz-layer-zzts3dv2/entityGridV2.d.ts +277 -0
  14. package/dist/zz-layer/zz-layer-zzts3dv2/index.vue.d.ts +1 -1
  15. package/dist/zz-layer/zz-layer-zzts3dv2/tw2Parser.d.ts +7 -0
  16. package/dist/zz-layer/zz-layer-zzts3dv2/twinAdaptiveMesh.d.ts +3 -0
  17. package/dist/zz-layer/zz-layer-zzts3dv2/twinCoarseLod.d.ts +4 -0
  18. package/dist/zz-layer/zz-layer-zzts3dv2/twinEnvironmentLighting.d.ts +16 -0
  19. package/dist/zz-layer/zz-layer-zzts3dv2/twinImagePixels.d.ts +6 -0
  20. package/dist/zz-layer/zz-layer-zzts3dv2/twinPagedIndex.d.ts +8 -0
  21. package/dist/zz-layer/zz-layer-zzts3dv2/twinParsePool.d.ts +10 -0
  22. package/dist/zz-layer/zz-layer-zzts3dv2/twinPreviewWorker.d.ts +1 -1
  23. package/dist/zz-layer/zz-layer-zzts3dv2/twinRegionalIndex.d.ts +23 -0
  24. package/dist/zz-layer/zz-layer-zzts3dv2/twinResourceBatch.d.ts +34 -0
  25. package/dist/zz-layer/zz-layer-zzts3dv2/twinTextureAppearance.d.ts +89 -0
  26. package/dist/zz-layer/zz-layer-zzts3dv2/twinTextureMipWorker.d.ts +1 -0
  27. package/dist/zz-layer/zz-layer-zzts3dv2/twinVisualRuntime.d.ts +107 -0
  28. package/dist/zz-layer-shp-zzts-Dr3Gxeba.js +1881 -0
  29. package/dist/{zz-layer-zzts3d-DqZmLdW3.js → zz-layer-zzts3d-CsIWse3P.js} +1 -1
  30. package/dist/{zz-layer-zzts3d-las-hNa-nqxq.js → zz-layer-zzts3d-las-D3w01aGe.js} +6 -5
  31. package/dist/{zz-layer-zzts3d-point-DrB5Uuwa.js → zz-layer-zzts3d-point-BjaTPTqj.js} +6 -4
  32. package/dist/zz-layer-zzts3dv2-DFXCOaMe.js +4019 -0
  33. package/dist/{zzts3dLayerSignature-Cnu6KIys.js → zzts3dLayerSignature-DzrPeJTd.js} +2 -0
  34. package/package.json +4 -3
  35. package/dist/assets/twinPreviewWorker-COILIqOa.js +0 -1
  36. package/dist/zz-layer-shp-zzts-D8BjI5tI.js +0 -1323
  37. package/dist/zz-layer-zzts3dv2-D5udnVGT.js +0 -913
@@ -1,1323 +0,0 @@
1
- import { computed as e, inject as t, onMounted as n, onUnmounted as r, watch as i } from "vue";
2
- import * as a from "cesium";
3
- import { IndexedDBManager as o, httpService as s } from "@skzz/libs-base";
4
- var c = "vectorTile";
5
- function l(e) {
6
- return `shpZzts_${String(e || "")}`;
7
- }
8
- function u(e, t) {
9
- return `${e}|${t}`;
10
- }
11
- function d(e, t) {
12
- return `v6_${e}_${t}`;
13
- }
14
- function f(e) {
15
- return `v6_bulk_${e}`;
16
- }
17
- function p(e, t) {
18
- let n = (t || []).map((e) => String(e?.geoSot || "").trim()).filter(Boolean).sort();
19
- return `${Number(e)}|${n.join(",")}`;
20
- }
21
- function m({ tileSetKey: e, lastTileSetKey: t, currentLod: n, lodLevel: r, hasPrimitives: i } = {}) {
22
- return !e || !t || e !== t || Number(n) !== Number(r) ? !1 : !!i;
23
- }
24
- function h(e, t) {
25
- if (!e || !e.has(t)) return;
26
- let n = e.get(t);
27
- return e.delete(t), e.set(t, n), n;
28
- }
29
- function g(e, t, n, r) {
30
- if (!e) return n;
31
- e.set(t, n);
32
- let i = Number(r);
33
- if (Number.isFinite(i) && i > 0) for (; e.size > i;) e.delete(e.keys().next().value);
34
- return n;
35
- }
36
- function _(e) {
37
- return e instanceof ArrayBuffer && e.byteLength > 8;
38
- }
39
- function v(e, t = !1) {
40
- return t ? !1 : e instanceof ArrayBuffer;
41
- }
42
- function y(e = []) {
43
- return [...new Set((e || []).map((e) => String(e?.featureId ?? "").trim()).filter(Boolean))];
44
- }
45
- function b(e) {
46
- let t = null, n = !1, r = [];
47
- function i() {
48
- let e = r;
49
- r = [];
50
- for (let t of e) t();
51
- }
52
- async function a() {
53
- if (!n) {
54
- n = !0;
55
- try {
56
- for (; t;) {
57
- let n = t;
58
- t = null;
59
- try {
60
- await e(n);
61
- } catch {}
62
- }
63
- } finally {
64
- n = !1, t ? await a() : i();
65
- }
66
- }
67
- }
68
- function o(e) {
69
- !Array.isArray(e) || e.length === 0 || (t = e, n || a());
70
- }
71
- function s() {
72
- return !n && !t ? Promise.resolve() : new Promise((e) => r.push(e));
73
- }
74
- return {
75
- schedule: o,
76
- whenIdle: s
77
- };
78
- }
79
- function x({ cache: e, postBatch: t, batchSize: n = 800, coalesceMs: r = 48, postConcurrency: i = 2, delay: a = (e) => new Promise((t) => setTimeout(t, e)) } = {}) {
80
- let o = /* @__PURE__ */ new Set(), s = null;
81
- function c() {
82
- let t = [];
83
- for (let r of [...o]) if (o.delete(r), !e?.has(r) && (t.push(r), t.length >= n)) break;
84
- return t;
85
- }
86
- async function l(n) {
87
- if (n.length === 0) return;
88
- let r = [];
89
- try {
90
- r = await t(n) || [];
91
- } catch {
92
- return;
93
- }
94
- let i = /* @__PURE__ */ new Map();
95
- for (let e of r) {
96
- let t = String(e?.modelId || e?.model_id || "").trim();
97
- t && e?.color && i.set(t, e.color);
98
- }
99
- for (let t of n) e.set(t, i.get(t) ?? null);
100
- }
101
- async function u() {
102
- let e = o.size >= n ? 0 : r;
103
- e > 0 && await a(e);
104
- try {
105
- for (; o.size > 0;) {
106
- let e = [], t = Math.max(1, Number(i) || 1);
107
- for (; o.size > 0 && e.length < t;) {
108
- let t = c();
109
- if (t.length === 0) break;
110
- e.push(t);
111
- }
112
- if (e.length === 0) break;
113
- await Promise.all(e.map((e) => l(e)));
114
- }
115
- } finally {
116
- s = null;
117
- }
118
- }
119
- async function d(t = []) {
120
- let n = [...new Set((t || []).map((e) => String(e ?? "").trim()).filter(Boolean))];
121
- if (n.length === 0) return;
122
- let r = 0;
123
- for (; n.some((t) => !e.has(t)) && r < 3;) {
124
- for (let t of n) e.has(t) || o.add(t);
125
- s ||= u(), await s, r += 1;
126
- }
127
- }
128
- function f() {
129
- o.clear();
130
- }
131
- return {
132
- ensure: d,
133
- reset: f
134
- };
135
- }
136
- //#endregion
137
- //#region src/zz-layer/zz-layer-shp-zzts/shpZztsRenderer.js
138
- function S(e) {
139
- if (e == null) return "";
140
- let t = String(e).trim();
141
- if (!t) return "";
142
- let n = t.match(/^#([0-9a-f]{6})(?:[0-9a-f]{2})?$/i);
143
- if (n) return [
144
- 0,
145
- 2,
146
- 4
147
- ].map((e) => parseInt(n[1].slice(e, e + 2), 16)).join(",");
148
- let r = t.match(/^rgba?\(\s*(\d{1,3})[,\s]+(\d{1,3})[,\s]+(\d{1,3})/i);
149
- return r ? `${Number(r[1])},${Number(r[2])},${Number(r[3])}` : /^\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}$/.test(t) ? t.split(",").map((e) => Math.max(0, Math.min(255, Math.round(Number(e.trim()))))).join(",") : "";
150
- }
151
- function C(e) {
152
- if (!e) return "";
153
- let t = (e) => Math.max(0, Math.min(255, Math.round(Number(e) * 255)));
154
- return `${t(e.red)},${t(e.green)},${t(e.blue)}`;
155
- }
156
- function w(e) {
157
- if (!e) return null;
158
- 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);
159
- return ![
160
- t,
161
- n,
162
- r,
163
- i
164
- ].every(Number.isFinite) || t < -180 || r > 180 || n < -90 || i > 90 || t >= r || n >= i ? null : {
165
- west: t,
166
- south: n,
167
- east: r,
168
- north: i
169
- };
170
- }
171
- function T(e) {
172
- return e ? typeof e.isDestroyed == "function" ? e.isDestroyed() : !1 : !0;
173
- }
174
- function E(e, t) {
175
- if (!e || !t) return null;
176
- let n = {
177
- west: Math.max(e.west, t.west),
178
- south: Math.max(e.south, t.south),
179
- east: Math.min(e.east, t.east),
180
- north: Math.min(e.north, t.north)
181
- };
182
- return n.west < n.east && n.south < n.north ? n : null;
183
- }
184
- function D(e) {
185
- if (!e || typeof e != "object" || e.visible === !1) return null;
186
- let t = Number(e.width), n = e.color || e.outlineColor;
187
- return !n || !Number.isFinite(t) || t <= 0 ? null : {
188
- color: String(n),
189
- width: t
190
- };
191
- }
192
- function O(e, t) {
193
- return !e && !t ? !0 : !e || !t ? !1 : e.color === t.color && e.width === t.width;
194
- }
195
- function k(e, t) {
196
- let n = /* @__PURE__ */ new Map(), r = (e, r) => {
197
- if (e === r) return;
198
- let i = e < r ? e * t + r : r * t + e;
199
- n.set(i, (n.get(i) || 0) + 1);
200
- };
201
- for (let t = 0; t + 2 < e.length; t += 3) r(e[t], e[t + 1]), r(e[t + 1], e[t + 2]), r(e[t + 2], e[t]);
202
- let i = /* @__PURE__ */ new Map(), a = [];
203
- for (let [e, r] of n) {
204
- if (r !== 1) continue;
205
- let n = Math.floor(e / t), o = e % t;
206
- a.push([n, o]), i.has(n) || i.set(n, []), i.has(o) || i.set(o, []), i.get(n).push(o), i.get(o).push(n);
207
- }
208
- if (a.length === 0) return [];
209
- let o = /* @__PURE__ */ new Set(), s = (e, n) => e < n ? e * t + n : n * t + e, c = [];
210
- for (let [e, t] of a) {
211
- if (o.has(s(e, t))) continue;
212
- o.add(s(e, t));
213
- let n = [e, t], r = t;
214
- for (;;) {
215
- let t = (i.get(r) || []).find((e) => !o.has(s(r, e)));
216
- if (t === void 0 || (o.add(s(r, t)), n.push(t), t === e)) break;
217
- r = t;
218
- }
219
- let a = e;
220
- for (;;) {
221
- let e = (i.get(a) || []).find((e) => !o.has(s(a, e)));
222
- if (e === void 0 || (o.add(s(a, e)), n.unshift(e), e === t)) break;
223
- a = e;
224
- }
225
- n.length >= 2 && c.push(n);
226
- }
227
- return c;
228
- }
229
- function A(e) {
230
- let t = performance.now(), n = [], r = new DataView(e), i = new TextDecoder(), a = r.getInt32(0, !0);
231
- if (a <= 0 || a > 1e5) return console.warn(`[ShpZzts] tileCount 异常: ${a},跳过解析`), n;
232
- console.log(`[ShpZzts] 瓦片数量: ${a}`);
233
- let o = 4;
234
- for (let t = 0; t < a; t++) {
235
- let a = r.getInt32(o, !0);
236
- if (o += 4, a <= 0 || a > 100 * 1024 * 1024) {
237
- console.error(`[ShpZzts] dataLen 异常: ${a},跳过瓦片 ${t}`), o += Math.max(0, a);
238
- continue;
239
- }
240
- let s = new Uint8Array(e, o, a), c = new DataView(s.buffer, s.byteOffset, s.byteLength);
241
- o += a;
242
- let l = 0, u = String(t), d = 0, f = c.getInt32(0, !0), p = !1;
243
- if (f > 0 && f <= 256 && a >= 4 + f + 8) {
244
- let e = f, t = s.slice(4, 4 + e), n = i.decode(t), r = 4 + e, o = !1;
245
- if (a >= r + 1 + 8) {
246
- let e = r + 1, t = c.getInt32(e, !0);
247
- if (t >= 24 && t % 24 == 0 && t <= a - e - 4) {
248
- let i = e + 4, s = c.getInt32(i, !0);
249
- r + 1 + 8 + t + s === a && s >= 0 && s % 4 == 0 && (u = n, d = c.getUint8(r), l = e, p = !0, o = !0);
250
- }
251
- }
252
- if (!o) {
253
- let t = r, i = c.getInt32(t, !0);
254
- if (i >= 24 && i % 24 == 0 && i <= a - t - 4) {
255
- let r = t + 4, o = c.getInt32(r, !0);
256
- 4 + e + 8 + i + o === a && o >= 0 && o % 4 == 0 && (u = n, l = t, p = !0);
257
- }
258
- }
259
- }
260
- p || (l = 0);
261
- let m = c.getInt32(l, !0);
262
- l += 4;
263
- let h = c.getInt32(l, !0);
264
- if (l += 4, m <= 0 || m % 24 != 0) {
265
- console.error(`[ShpZzts] positionsByteLen 非法: ${m},跳过瓦片 ${t}`);
266
- continue;
267
- }
268
- if (h < 0 || h % 4 != 0) {
269
- console.error(`[ShpZzts] indicesByteLen 非法: ${h},跳过瓦片 ${t}`);
270
- continue;
271
- }
272
- let g = s.byteLength - l;
273
- if (m + h > g) {
274
- console.error(`[ShpZzts] 数据长度溢出: pos=${m} + idx=${h} > remaining=${g},跳过瓦片 ${t}`);
275
- continue;
276
- }
277
- let _ = m / 8 / 3, v = s.slice(l, l + m), y = new Float64Array(v.buffer, v.byteOffset, _ * 3);
278
- l += m;
279
- let b = h / 4;
280
- if (b > 1e8) {
281
- console.error(`[ShpZzts] indexCount 异常巨大: ${b},跳过瓦片 ${t}`);
282
- continue;
283
- }
284
- let x = s.slice(l, l + h), S = new Uint32Array(x.buffer, x.byteOffset, b);
285
- l += h;
286
- let C = !1;
287
- for (let e = 0; e < y.length && !C; e++) isFinite(y[e]) || (C = !0);
288
- if (C) {
289
- console.error(`[ShpZzts] NaN/Inf 坐标 tile=${t},跳过`);
290
- continue;
291
- }
292
- let w = 0;
293
- for (let e = 0; e < S.length; e++) S[e] > w && (w = S[e]);
294
- if (w >= _) {
295
- console.error(`[ShpZzts] 索引越界 tile=${t} maxIdx=${w} vertexCount=${_},跳过`);
296
- continue;
297
- }
298
- n.push({
299
- positions: y,
300
- indices: S,
301
- vertexCount: _,
302
- indexCount: b,
303
- featureId: u,
304
- geometryKind: d,
305
- fidTrusted: p
306
- });
307
- }
308
- let s = (performance.now() - t).toFixed(1);
309
- return console.log(`[ShpZzts] 解析完成: ${n.length} 要素, ${s}ms`), n;
310
- }
311
- async function j(e, t, n) {
312
- let r = 0, i = Math.max(1, Math.min(t, e.length)), a = [];
313
- for (let t = 0; t < i; t++) a.push((async () => {
314
- for (; r < e.length;) {
315
- let t = e[r++];
316
- await n(t);
317
- }
318
- })());
319
- await Promise.all(a);
320
- }
321
- var M = 512, N = 2, P = class {
322
- constructor(e, t = {}) {
323
- this.viewer = e, this.id = t.layerId || "", this.calTilesUrl = t.calTilesUrl || "/v1/zzts/layer/shp/calTiles", this.tileUrl = t.tileUrl || "/v1/zzts/layer/3d/getVectorTile", this.layerDataUrl = t.layerDataUrl || "/v1/zzts/layer/3d/getVectorLayerData", this.opacity = this._normOpacity(t.opacity), this.batchSize = t.batchSize || 2e3, this.transitionDuration = t.transitionDuration || 50, this.fetchConcurrency = Number(t.fetchConcurrency) > 0 ? Number(t.fetchConcurrency) : 12, this.bulkTileThreshold = Number(t.bulkTileThreshold) > 0 ? Number(t.bulkTileThreshold) : 48, this.pointSize = t.pointSize || 8, this.displayRange = w(t.displayRange);
324
- let n = Number(t.pointSize);
325
- this.pointSize = Number.isFinite(n) && n > 0 ? n : 5, this._userColor = t.color || null, this.outline = D(t.outline);
326
- let r = Number(t.outlineHeightOffset);
327
- this.outlineHeightOffset = Number.isFinite(r) && r > 0 ? r : .8, this.dictCode = t.dictCode || "", this.serviceName = t.serviceName || "", this.enableServiceColor = t.enableServiceColor !== !1, this.modelColorUrl = t.modelColorUrl || "/v1/zzts/style/render/modelColors", this.modelColorCache = /* @__PURE__ */ new Map(), this._colorDrain = null, this._colorAllReady = !1, this._colorAllPromise = null, this.hiddenColors = new Set((t.hiddenColors || []).map(S).filter(Boolean)), this.currentLod = -1, this.lodPrimitives = /* @__PURE__ */ new Map(), this.transitionAnimId = null, this.tileCache = /* @__PURE__ */ new Map(), this.bulkCache = /* @__PURE__ */ new Map(), this.activeAbort = null, this.renderRequestToken = 0, this.debounceTimer = null, this.destroyed = !1, this.globalInstanceId = 0, this.stackIndex = t.stackIndex ?? -1, this.subStackIndex = t.subStackIndex ?? 0, this.groupKey = t.groupKey || String(this.id), this._moveHandler = null, this._lastViewData = null, this._hiddenRebuildPending = !1, this._hiddenRebuildQueued = !1, this._lastTileSetKey = "", this.enableIndexedDb = t.enableIndexedDb !== !1, this.gridDb = null;
328
- }
329
- _normOpacity(e) {
330
- let t = Number(e);
331
- return Number.isFinite(t) ? Math.max(0, Math.min(1, t)) : 1;
332
- }
333
- _normAlpha(e) {
334
- let t = Number(e);
335
- return Number.isFinite(t) ? t > 1 ? Math.max(0, Math.min(1, t > 100 ? t / 255 : t / 100)) : Math.max(0, Math.min(1, t)) : 1;
336
- }
337
- _resolveColor() {
338
- if (!this._userColor) return a.Color.fromCssColorString("#4A90D9");
339
- try {
340
- if (typeof this._userColor == "string") return a.Color.fromCssColorString(this._userColor);
341
- if (typeof this._userColor == "object" && this._userColor.r !== void 0) return new a.Color(Number(this._userColor.r) / 255, Number(this._userColor.g) / 255, Number(this._userColor.b) / 255, this._normAlpha(this._userColor.a));
342
- } catch {
343
- console.warn("[ShpZzts] 颜色解析失败,回退默认淡蓝色:", this._userColor);
344
- }
345
- return a.Color.fromCssColorString("#4A90D9");
346
- }
347
- isServiceColorEnabled() {
348
- return !!(this.enableServiceColor && this.serviceName && this.dictCode && this.modelColorUrl);
349
- }
350
- _collectFeatureIds(e = []) {
351
- return y(e);
352
- }
353
- _colorMapFromCache(e = []) {
354
- let t = /* @__PURE__ */ new Map();
355
- if (!this.isServiceColorEnabled()) return t;
356
- for (let n of this._collectFeatureIds(e)) {
357
- let e = this.modelColorCache.get(n);
358
- e && t.set(n, e);
359
- }
360
- return t;
361
- }
362
- _ingestModelColorRows(e = []) {
363
- let t = 0;
364
- for (let n of e || []) {
365
- let e = String(n.modelId || n.model_id || "").trim(), r = n.color;
366
- e && r && (this.modelColorCache.set(e, r), t += 1);
367
- }
368
- return t;
369
- }
370
- _resetServiceColorIndex() {
371
- this.modelColorCache.clear(), this._colorDrain?.reset(), this._colorAllReady = !1, this._colorAllPromise = null;
372
- }
373
- async _fetchAllServiceColors() {
374
- let e = await s.request({
375
- method: "POST",
376
- url: this.modelColorUrl,
377
- data: {
378
- serviceName: this.serviceName,
379
- dictCode: this.dictCode,
380
- fetchAll: !0
381
- },
382
- timeout: 6e4
383
- }), t = (e?.data ?? e)?.rows || [], n = this._ingestModelColorRows(t);
384
- return this._colorAllReady = !0, console.log(`[ShpZzts] 服务配色全量命中: ${n}/${t.length}`), n;
385
- }
386
- _ensureServiceColorIndex() {
387
- return !this.isServiceColorEnabled() || this._colorAllReady ? Promise.resolve() : (this._colorAllPromise ||= this._fetchAllServiceColors().catch((e) => {
388
- throw this._colorAllPromise = null, console.warn("[ShpZzts] 全量配色失败,回退按 id 查询:", e?.message || e), e;
389
- }), this._colorAllPromise);
390
- }
391
- _cssToCesiumColor(e) {
392
- if (!e) return null;
393
- try {
394
- return a.Color.fromCssColorString(e) || null;
395
- } catch {
396
- return null;
397
- }
398
- }
399
- _applyServiceColorsInPlace() {
400
- let e = this.lodPrimitives.get(this.currentLod);
401
- if (!e || !this.isServiceColorEnabled()) return;
402
- let t = this.opacity;
403
- for (let n of e) {
404
- let e = n.instanceFeatureIds;
405
- if (!(!e || !e.length)) {
406
- if (n.pointPrimitives && n.pointPrimitives.length > 0) {
407
- for (let r = 0; r < n.pointPrimitives.length; r++) {
408
- let i = this._cssToCesiumColor(this.modelColorCache.get(e[r]));
409
- if (!i) continue;
410
- n.instanceColors && (n.instanceColors[r] = i), n.pointColors && (n.pointColors[r] = i), n.pointBaseColors && (n.pointBaseColors[r] = i);
411
- let o = n.pointPrimitives[r];
412
- o && !T(o) && (o.color = new a.Color(i.red, i.green, i.blue, t * this._normAlpha(i.alpha)));
413
- }
414
- continue;
415
- }
416
- if (!T(n.primitive)) for (let r = 0; r < n.instanceIds.length; r++) {
417
- let i = this._cssToCesiumColor(this.modelColorCache.get(e[r]));
418
- if (i) {
419
- n.instanceColors[r] = i;
420
- try {
421
- let e = n.primitive.getGeometryInstanceAttributes(n.instanceIds[r]);
422
- e?.color && (e.color = a.ColorGeometryInstanceAttribute.toValue(new a.Color(i.red, i.green, i.blue, t * this._normAlpha(i.alpha))));
423
- } catch {}
424
- }
425
- }
426
- }
427
- }
428
- this._lastViewData?.geometries && (this._lastViewData.colorMap = this._colorMapFromCache(this._lastViewData.geometries));
429
- }
430
- _getColorDrain() {
431
- return this._colorDrain ||= x({
432
- cache: this.modelColorCache,
433
- postBatch: (e) => this._postModelColorBatch(e)
434
- }), this._colorDrain;
435
- }
436
- async _postModelColorBatch(e) {
437
- try {
438
- let t = await s.request({
439
- method: "POST",
440
- url: this.modelColorUrl,
441
- data: {
442
- serviceName: this.serviceName,
443
- dictCode: this.dictCode,
444
- modelIds: e
445
- },
446
- timeout: 6e4
447
- }), n = (t?.data ?? t)?.rows || [], r = new Set(n.map((e) => String(e.modelId || e.model_id || "").trim()).filter(Boolean)), i = e.filter((e) => !r.has(e));
448
- return i.length > 0 && console.warn("[ShpZzts] 部分要素没有查询到颜色", {
449
- serviceName: this.serviceName,
450
- dictCode: this.dictCode,
451
- requestCount: e.length,
452
- hitCount: n.length,
453
- missingCount: i.length,
454
- missingSample: i.slice(0, 20)
455
- }), n;
456
- } catch (e) {
457
- throw console.warn("[ShpZzts] 查询服务配色失败(本批回退默认色):", e), e;
458
- }
459
- }
460
- async loadModelColorsByIds(e = []) {
461
- if (!this.isServiceColorEnabled()) return /* @__PURE__ */ new Map();
462
- let t = [...new Set(e.map((e) => String(e ?? "").trim()).filter((e) => e))];
463
- if (t.length === 0) return /* @__PURE__ */ new Map();
464
- this._colorAllReady || await this._getColorDrain().ensure(t);
465
- let n = /* @__PURE__ */ new Map();
466
- for (let e of t) {
467
- let t = this.modelColorCache.get(e);
468
- t && n.set(e, t);
469
- }
470
- return n;
471
- }
472
- _resolveFeatureColor(e, t) {
473
- if (t && e.featureId !== void 0 && e.featureId !== null) {
474
- let n = t.get(String(e.featureId));
475
- if (n) try {
476
- let e = a.Color.fromCssColorString(n);
477
- if (e) return e;
478
- } catch {}
479
- }
480
- return this._resolveColor();
481
- }
482
- _resolveOutlineColor() {
483
- let e = this.outline?.color || "#FFC107";
484
- try {
485
- let t = a.Color.fromCssColorString(e);
486
- if (t) return t;
487
- } catch {
488
- console.warn("[ShpZzts] 边线颜色解析失败,回退默认色:", e);
489
- }
490
- return a.Color.fromCssColorString("#FFC107");
491
- }
492
- _getScreenBounds() {
493
- try {
494
- let e = this.viewer?.scene?.canvas, t = this.viewer?.camera?.computeViewRectangle?.();
495
- if (!e || !t) return null;
496
- let n = {
497
- west: a.Math.toDegrees(t.west),
498
- south: a.Math.toDegrees(t.south),
499
- east: a.Math.toDegrees(t.east),
500
- north: a.Math.toDegrees(t.north)
501
- }, r = this.displayRange ? E(n, this.displayRange) : n;
502
- return {
503
- requestBounds: r,
504
- region: [
505
- r?.west,
506
- r?.south,
507
- 0,
508
- r?.east,
509
- r?.north,
510
- 10
511
- ],
512
- width: e.clientWidth,
513
- height: e.clientHeight
514
- };
515
- } catch {
516
- return null;
517
- }
518
- }
519
- async _waitForScreenBounds(e = 2e3) {
520
- let t = performance.now();
521
- for (; !this.destroyed;) {
522
- if (this._getScreenBounds()) return !0;
523
- if (performance.now() - t >= e) return !1;
524
- await new Promise((e) => requestAnimationFrame(e));
525
- }
526
- return !1;
527
- }
528
- _updatePrimitiveAlpha(e, t) {
529
- if (!e) return;
530
- let n = this._normOpacity(t), r = (e) => n * this._normAlpha(e?.alpha);
531
- for (let t of e) try {
532
- if (T(t.primitive)) continue;
533
- if (t.pointPrimitives && t.pointPrimitives.length > 0) {
534
- for (let e = 0; e < t.pointPrimitives.length; e++) {
535
- let n = t.pointPrimitives[e], i = t.pointBaseColors[e];
536
- T(n) || !i || (n.color = new a.Color(i.red, i.green, i.blue, r(i)));
537
- }
538
- continue;
539
- }
540
- if (t.polylines && t.polylines.length > 0) {
541
- let e = t.baseOutlineColor;
542
- for (let n of t.polylines) {
543
- if (T(n)) continue;
544
- let t = n.material?.uniforms;
545
- t?.color && (t.color = new a.Color(e.red, e.green, e.blue, r(e)));
546
- }
547
- continue;
548
- }
549
- let e = t.instanceIds || [];
550
- for (let n = 0; n < e.length; n++) {
551
- let i = t.instanceColors[n], o = new a.Color(i.red, i.green, i.blue, r(i));
552
- try {
553
- let r = t.primitive.getGeometryInstanceAttributes(e[n]);
554
- r?.color && (r.color = a.ColorGeometryInstanceAttribute.toValue(o));
555
- } catch {}
556
- }
557
- } catch {}
558
- }
559
- _applyLayerOpacity() {
560
- if (this.transitionAnimId !== null) {
561
- cancelAnimationFrame(this.transitionAnimId), this.transitionAnimId = null;
562
- for (let e of [...this.lodPrimitives.keys()]) e !== this.currentLod && this._destroyLodPrimitives(e);
563
- }
564
- let e = this.lodPrimitives.get(this.currentLod);
565
- e && this._updatePrimitiveAlpha(e, this.opacity);
566
- }
567
- _destroyLodPrimitives(e) {
568
- let t = this.lodPrimitives.get(e);
569
- if (t) {
570
- for (let e of t) T(e.primitive) || this.viewer.scene.primitives.remove(e.primitive);
571
- this.lodPrimitives.delete(e);
572
- }
573
- }
574
- _discardPrimitiveEntries(e) {
575
- for (let t of e || []) {
576
- let e = t?.primitive;
577
- if (!T(e)) try {
578
- e.destroy?.();
579
- } catch {}
580
- }
581
- }
582
- _swapFirstPaintGeoms(e, t, n) {
583
- return new Promise((r) => {
584
- try {
585
- let i = this._colorMapFromCache(e);
586
- if (this._lastViewData = {
587
- lodLevel: t,
588
- geometries: e,
589
- colorMap: i
590
- }, this.currentLod === -1 && !this.lodPrimitives.has(t)) {
591
- console.log(`[ShpZzts] 首屏流式上屏: ${e.length} 要素 / 批次 400`), this._renderBatched(e, t, 1, () => {
592
- if (typeof n == "function" && !n()) {
593
- r(!1);
594
- return;
595
- }
596
- this.currentLod = t, r(!0);
597
- }, i, null, { batchSize: 400 });
598
- return;
599
- }
600
- this._renderBatched(e, t, 1, null, i, null, {
601
- deferScene: !0,
602
- onComplete: (e) => {
603
- r(this._swapLodPrimitives(t, e, n));
604
- }
605
- });
606
- } catch (e) {
607
- console.warn("[ShpZzts] 首屏换挂失败:", e?.message || e), r(!1);
608
- }
609
- });
610
- }
611
- _swapLodPrimitives(e, t, n) {
612
- if (typeof n == "function" && !n()) return this._discardPrimitiveEntries(t), !1;
613
- this._destroyLodPrimitives(e);
614
- for (let e of t || []) T(e.primitive) || this.viewer.scene.primitives.add(e.primitive);
615
- return this.lodPrimitives.set(e, t || []), this.currentLod = e, !0;
616
- }
617
- _clearRenderedPrimitives() {
618
- for (let e of [...this.lodPrimitives.keys()]) this._destroyLodPrimitives(e);
619
- this.currentLod = -1, this._lastTileSetKey = "";
620
- }
621
- async _openTileDb() {
622
- if (!(!this.enableIndexedDb || typeof indexedDB > "u")) try {
623
- let e = new o(l(this.id), 1);
624
- if (await e.openDatabase(c, "id"), this.destroyed) {
625
- e.closeDatabase();
626
- return;
627
- }
628
- this.gridDb = e;
629
- } catch (e) {
630
- console.warn("[ShpZzts] IndexedDB 打开失败,回退内存缓存:", e?.message || e), this.gridDb = null;
631
- }
632
- }
633
- async _readIdbBuffer(e) {
634
- if (!(!this.gridDb || this.destroyed)) try {
635
- let t = (await this.gridDb.getDataById(c, e))?.data;
636
- return t instanceof ArrayBuffer ? t : ArrayBuffer.isView(t) ? t.buffer.slice(t.byteOffset, t.byteOffset + t.byteLength) : void 0;
637
- } catch {
638
- return;
639
- }
640
- }
641
- _writeIdbBuffer(e, t) {
642
- !this.gridDb || this.destroyed || t instanceof ArrayBuffer && this.gridDb.updateData(c, {
643
- id: e,
644
- data: t
645
- }).catch(() => {});
646
- }
647
- _parseTileBuffer(e) {
648
- return _(e) && A(e) || [];
649
- }
650
- _rebuildForHiddenColors() {
651
- if (this.destroyed) return;
652
- let e = this._lastViewData;
653
- if (!e) {
654
- this.loadAndRender();
655
- return;
656
- }
657
- if (!e.geometries.length) return;
658
- if (this._hiddenRebuildPending) {
659
- this._hiddenRebuildQueued = !0;
660
- return;
661
- }
662
- this._hiddenRebuildPending = !0;
663
- let t = this.renderRequestToken;
664
- this._renderBatched(e.geometries, e.lodLevel, 1, null, e.colorMap, null, {
665
- deferScene: !0,
666
- onComplete: (n) => {
667
- if (this._hiddenRebuildPending = !1, this.destroyed || t !== this.renderRequestToken) {
668
- this._finishHiddenRebuild();
669
- return;
670
- }
671
- let r = this.currentLod;
672
- r !== -1 && this._destroyLodPrimitives(r);
673
- for (let e of n) T(e.primitive) || this.viewer.scene.primitives.add(e.primitive);
674
- this.lodPrimitives.set(e.lodLevel, n), this.currentLod = e.lodLevel, this._updatePrimitiveAlpha(n, this.opacity), this._finishHiddenRebuild();
675
- }
676
- });
677
- }
678
- _finishHiddenRebuild() {
679
- this._hiddenRebuildQueued && (this._hiddenRebuildQueued = !1, this._rebuildForHiddenColors());
680
- }
681
- _crossFadeLod(e, t, n) {
682
- this.transitionAnimId !== null && (cancelAnimationFrame(this.transitionAnimId), this.transitionAnimId = null);
683
- let r = this.lodPrimitives.get(e) ?? void 0, i = this.lodPrimitives.get(t);
684
- if (!i) return;
685
- let a = this.opacity, o = () => {
686
- if (r) {
687
- for (let e of r) T(e.primitive) || this.viewer.scene.primitives.remove(e.primitive);
688
- this.lodPrimitives.delete(e);
689
- }
690
- this.transitionAnimId = null;
691
- }, s = () => {
692
- try {
693
- this._updatePrimitiveAlpha(i, a);
694
- } catch {}
695
- o();
696
- };
697
- try {
698
- this._updatePrimitiveAlpha(i, 0);
699
- } catch (e) {
700
- console.warn("[ShpZzts] 交叉淡化初始化失败,直接切新层:", e?.message || e), s();
701
- return;
702
- }
703
- let c = performance.now(), l = this.transitionDuration, u = () => {
704
- if (this.destroyed || typeof n == "function" && !n()) {
705
- this.transitionAnimId = null;
706
- return;
707
- }
708
- try {
709
- let e = Math.min((performance.now() - c) / l, 1);
710
- this._updatePrimitiveAlpha(i, e * a), r && this._updatePrimitiveAlpha(r, (1 - e) * a), e < 1 ? this.transitionAnimId = requestAnimationFrame(u) : o();
711
- } catch (e) {
712
- console.warn("[ShpZzts] 交叉淡化中断,直接切新层:", e?.message || e), s();
713
- }
714
- };
715
- this.transitionAnimId = requestAnimationFrame(u);
716
- }
717
- _renderBatched(e, t, n, r, i, o, s = {}) {
718
- let c = o || [], l = s.deferScene === !0, u = Number(s.batchSize) > 0 ? Number(s.batchSize) : this.batchSize, d = () => {
719
- if (l) {
720
- typeof s.onComplete == "function" && s.onComplete(c);
721
- return;
722
- }
723
- this.lodPrimitives.set(t, c), r && requestAnimationFrame(() => r());
724
- };
725
- this.hiddenColors?.size && (e = e.filter((e) => {
726
- let t = this._resolveFeatureColor(e, i);
727
- return !this.hiddenColors.has(C(t));
728
- }));
729
- let f = [], p = [];
730
- for (let t of e) t.geometryKind === 2 && (!t.indices || t.indexCount === 0) ? f.push(t) : p.push(t);
731
- if (f.length > 0) {
732
- let e = new a.PointPrimitiveCollection(), r = [], o = [], s = [], u = [], d = [], p = this._normOpacity(n) * this.opacity;
733
- for (let t of f) {
734
- let n = this.globalInstanceId++, c = this._resolveFeatureColor(t, i), l = String(t.featureId ?? "");
735
- s.push(n), u.push(c);
736
- let f = new a.Color(c.red, c.green, c.blue, p * this._normAlpha(c.alpha));
737
- for (let i = 0; i < t.vertexCount; i++) r.push(e.add({
738
- position: a.Cartesian3.fromArray(t.positions, i * 3),
739
- pixelSize: this.pointSize,
740
- color: f,
741
- id: n
742
- })), o.push(c), d.push(l);
743
- }
744
- l || this.viewer.scene.primitives.add(e), c.push({
745
- primitive: e,
746
- instanceIds: s,
747
- instanceColors: u,
748
- instanceFeatureIds: d,
749
- pointPrimitives: r,
750
- pointColors: o
751
- }), console.log(`[ShpZzts] LOD ${t} 原生点渲染完成: ${f.length} 要素 / ${r.length} 点`);
752
- }
753
- let m = [];
754
- for (let e = 0; e < p.length; e += u) m.push(p.slice(e, e + u));
755
- let h = 0, g = (r) => {
756
- if (r >= m.length) {
757
- d();
758
- return;
759
- }
760
- let o = m[r], s = [], u = [];
761
- for (let e of o) e.geometryKind === 2 && e.indexCount === 0 ? s.push(e) : u.push(e);
762
- let f = 0, p = [], _ = [], v = [], y = [];
763
- for (let e of u) {
764
- let t = this.globalInstanceId++;
765
- p.push(t), v.push(String(e.featureId ?? ""));
766
- let r = this._resolveFeatureColor(e, i);
767
- _.push(r);
768
- let o = new a.Color(r.red, r.green, r.blue, this._normOpacity(n) * this.opacity * this._normAlpha(r.alpha));
769
- try {
770
- y.push(new a.GeometryInstance({
771
- geometry: new a.Geometry({
772
- attributes: { position: new a.GeometryAttribute({
773
- componentDatatype: a.ComponentDatatype.DOUBLE,
774
- componentsPerAttribute: 3,
775
- values: e.positions,
776
- normalize: !1
777
- }) },
778
- indices: e.indices,
779
- primitiveType: a.PrimitiveType.TRIANGLES,
780
- boundingSphere: a.BoundingSphere.fromVertices(e.positions)
781
- }),
782
- id: t,
783
- attributes: { color: a.ColorGeometryInstanceAttribute.fromColor(o) }
784
- }));
785
- } catch (e) {
786
- console.error(`[ShpZzts] Geometry 创建失败 instanceId=${t}`, e), p.pop(), _.pop(), v.pop();
787
- }
788
- }
789
- if (y.length > 0) {
790
- let e = new a.Primitive({
791
- geometryInstances: y,
792
- appearance: new a.PerInstanceColorAppearance({
793
- flat: !0,
794
- translucent: !0
795
- }),
796
- asynchronous: !1,
797
- compressVertices: !1,
798
- releaseGeometryInstances: !0
799
- });
800
- l || this.viewer.scene.primitives.add(e), c.push({
801
- primitive: e,
802
- instanceIds: p,
803
- instanceColors: _,
804
- instanceFeatureIds: v
805
- }), f++;
806
- }
807
- if (this.outline) {
808
- let e = new a.PolylineCollection(), r = this._resolveOutlineColor(), i = this._normOpacity(n) * this.opacity * this._normAlpha(r.alpha), o = new a.Color(r.red, r.green, r.blue, i), s = [], d = new a.Cartesian3(), p = new a.Cartesian3();
809
- for (let t of u) {
810
- if (t.geometryKind !== 0 || !t.indices || t.indexCount === 0) continue;
811
- let n = k(t.indices, t.vertexCount);
812
- for (let r of n) {
813
- let n = Array(r.length);
814
- for (let e = 0; e < r.length; e++) {
815
- let i = a.Cartesian3.fromArray(t.positions, r[e] * 3);
816
- a.Cartesian3.normalize(i, d), a.Cartesian3.multiplyByScalar(d, this.outlineHeightOffset, p), n[e] = a.Cartesian3.add(i, p, new a.Cartesian3());
817
- }
818
- s.push(e.add({
819
- positions: n,
820
- width: this.outline.width,
821
- material: a.Material.fromType("Color", { color: o })
822
- }));
823
- }
824
- }
825
- s.length > 0 ? (l || this.viewer.scene.primitives.add(e), c.push({
826
- primitive: e,
827
- polylines: s,
828
- baseOutlineColor: r
829
- }), f++, console.log(`[ShpZzts] LOD ${t} 边线渲染完成: ${s.length} 条`)) : e.destroy?.();
830
- }
831
- if (s.length > 0) {
832
- let e = new a.PointPrimitiveCollection(), t = [], r = [], o = [], u = this._normOpacity(n) * this.opacity;
833
- for (let n of s) {
834
- if (!n.positions || n.positions.length < 3) continue;
835
- let s = this._resolveFeatureColor(n, i);
836
- r.push(s), o.push(String(n.featureId ?? ""));
837
- let c = e.add({
838
- position: new a.Cartesian3(n.positions[0], n.positions[1], n.positions[2]),
839
- color: new a.Color(s.red, s.green, s.blue, u * this._normAlpha(s.alpha)),
840
- pixelSize: this.pointSize,
841
- disableDepthTestDistance: Infinity
842
- });
843
- t.push(c);
844
- }
845
- t.length > 0 ? (l || this.viewer.scene.primitives.add(e), c.push({
846
- primitive: e,
847
- pointPrimitives: t,
848
- pointBaseColors: r,
849
- instanceFeatureIds: o
850
- }), f++) : e.destroy?.();
851
- }
852
- if (f === 0) {
853
- h++, h < m.length ? requestAnimationFrame(() => g(r + 1)) : d();
854
- return;
855
- }
856
- h++, h < m.length ? requestAnimationFrame(() => g(r + 1)) : (console.log(`[ShpZzts] LOD ${t} 渲染完成: ${e.length} 要素 / ${m.length} 批(点 ${s.length} 个)`), d());
857
- };
858
- return g(0), c;
859
- }
860
- async _getVectorTileData(e, t, n) {
861
- let r = await s.request({
862
- method: "GET",
863
- url: this.tileUrl,
864
- headers: { Accept: "application/octet-stream" },
865
- params: {
866
- layerId: this.id,
867
- geosot: e,
868
- level: t
869
- },
870
- responseType: "arraybuffer",
871
- timeout: 6e4,
872
- signal: n
873
- }), i = r?.data ?? r;
874
- if (!i) throw Error("Response data is empty");
875
- return {
876
- geosot: e,
877
- data: i
878
- };
879
- }
880
- async _fetchTileGeometries(e, t, n) {
881
- let r = u(t, e), i = h(this.tileCache, r);
882
- if (i) return i;
883
- let a = d(t, e), o = await this._readIdbBuffer(a);
884
- if (n?.aborted) {
885
- let e = /* @__PURE__ */ Error("Aborted");
886
- throw e.name = "AbortError", e;
887
- }
888
- if (o !== void 0) return g(this.tileCache, r, this._parseTileBuffer(o), M);
889
- let { data: s } = await this._getVectorTileData(e, t, n);
890
- if (n?.aborted) {
891
- let e = /* @__PURE__ */ Error("Aborted");
892
- throw e.name = "AbortError", e;
893
- }
894
- if (!v(s, !1)) throw Error("Response data is empty");
895
- let c = this._parseTileBuffer(s);
896
- return g(this.tileCache, r, c, M), this._writeIdbBuffer(a, s), c;
897
- }
898
- async _getLayerGeometries(e, t) {
899
- let n = h(this.bulkCache, e);
900
- if (n) return n;
901
- let r = f(e), i = await this._readIdbBuffer(r);
902
- if (t?.aborted) {
903
- let e = /* @__PURE__ */ Error("Aborted");
904
- throw e.name = "AbortError", e;
905
- }
906
- if (_(i)) {
907
- let t = this._parseTileBuffer(i);
908
- if (t.length > 0) return g(this.bulkCache, e, t, N);
909
- }
910
- let a = await s.request({
911
- method: "GET",
912
- url: this.layerDataUrl,
913
- headers: { Accept: "application/octet-stream" },
914
- params: {
915
- layerId: this.id,
916
- level: e
917
- },
918
- responseType: "arraybuffer",
919
- timeout: 12e4,
920
- signal: t
921
- }), o = a?.data ?? a, c = this._parseTileBuffer(o);
922
- return c.length > 0 && (g(this.bulkCache, e, c, N), o instanceof ArrayBuffer && this._writeIdbBuffer(r, o)), c;
923
- }
924
- async loadAndRender() {
925
- let e = this._getScreenBounds();
926
- if (!e) return;
927
- let t = ++this.renderRequestToken;
928
- if (this.activeAbort) try {
929
- this.activeAbort.abort();
930
- } catch {}
931
- let n = new AbortController();
932
- this.activeAbort = n;
933
- let r = () => t === this.renderRequestToken && !this.destroyed;
934
- if (this.displayRange && !e.requestBounds) {
935
- this.renderRequestToken += 1, this._lastViewData = null, this._clearRenderedPrimitives(), console.log("[ShpZzts] 当前视窗与真实胶囊显示范围无交集,跳过瓦片请求");
936
- return;
937
- }
938
- let i = Math.abs(e.region[3] - e.region[0]), a = Math.abs(e.region[4] - e.region[1]);
939
- if (i > 20 || a > 20) {
940
- console.warn(`[ShpZzts] 视窗范围过大,跳过请求 (lonSpan=${i.toFixed(2)}°, latSpan=${a.toFixed(2)}°, 限制=20°)`);
941
- return;
942
- }
943
- let o = performance.now();
944
- try {
945
- this.transitionAnimId !== null && (cancelAnimationFrame(this.transitionAnimId), this.transitionAnimId = null);
946
- let t = this._ensureServiceColorIndex(), i = await s.request({
947
- method: "GET",
948
- url: this.calTilesUrl,
949
- params: {
950
- region: e.region.join(","),
951
- height: e.height,
952
- width: e.width
953
- },
954
- signal: n.signal
955
- });
956
- if (!r()) return;
957
- let { lodLevel: a = -1, tiles: c = [] } = i?.data ?? i ?? {};
958
- if (console.log(`[ShpZzts] LOD ${a} | 瓦片数: ${c.length}`), !c || c.length === 0) {
959
- console.warn("[ShpZzts] 没有需要加载的瓦片"), this._clearRenderedPrimitives();
960
- return;
961
- }
962
- let l = p(a, c);
963
- if (m({
964
- tileSetKey: l,
965
- lastTileSetKey: this._lastTileSetKey,
966
- currentLod: this.currentLod,
967
- lodLevel: a,
968
- hasPrimitives: this.lodPrimitives.has(a)
969
- })) {
970
- console.log(`[ShpZzts] 瓦片集合未变,跳过重建 LOD ${a} | ${c.length} 瓦片`);
971
- return;
972
- }
973
- let d = this.currentLod, f = d !== -1 && d !== a, g = d === -1, _ = () => {
974
- r() && (this._lastTileSetKey = l);
975
- }, v = [], y = /* @__PURE__ */ new Set(), x = (e) => {
976
- let t = v.length;
977
- for (let t of e || []) {
978
- if (t.fidTrusted) {
979
- let e = String(t.featureId);
980
- if (y.has(e)) continue;
981
- y.add(e);
982
- }
983
- v.push(t);
984
- }
985
- return v.length > t;
986
- }, S = async () => {
987
- if (!this.isServiceColorEnabled() || v.length === 0) return this._colorMapFromCache(v);
988
- try {
989
- await t;
990
- } catch {}
991
- return !r() || this._colorAllReady ? this._colorMapFromCache(v) : this.loadModelColorsByIds(this._collectFeatureIds(v));
992
- }, C = (e) => {
993
- this.isServiceColorEnabled() && S().then((t) => {
994
- r() && (this._lastViewData = {
995
- lodLevel: a,
996
- geometries: e,
997
- colorMap: t
998
- }, this._applyServiceColorsInPlace(), console.log(`[ShpZzts] 首屏配色已套用: ${t.size}`));
999
- }).catch(() => {});
1000
- }, w = !1;
1001
- if (c.length >= this.bulkTileThreshold && a !== 12 && a !== 13) try {
1002
- let e = await this._getLayerGeometries(a, n.signal);
1003
- if (!r()) return;
1004
- e.length > 0 && (x(e), w = !0, console.log(`[ShpZzts] LOD ${a} 整图层拉取完成: ${e.length} 要素`));
1005
- } catch (e) {
1006
- if (n.signal.aborted) return;
1007
- console.warn("[ShpZzts] 整图层拉取失败,回退逐瓦片加载:", e?.message || e);
1008
- }
1009
- let T = !1, E = null;
1010
- if (!w) {
1011
- g && (E = b(async (e) => {
1012
- !r() || !e.length || await this._swapFirstPaintGeoms(e, a, r) && this._colorAllReady && (this._lastViewData = {
1013
- lodLevel: a,
1014
- geometries: e,
1015
- colorMap: this._colorMapFromCache(e)
1016
- }, this._applyServiceColorsInPlace());
1017
- }));
1018
- let e = [];
1019
- for (let t of c) {
1020
- let n = u(a, t.geoSot), r = h(this.tileCache, n);
1021
- r ? x(r) : e.push(t);
1022
- }
1023
- if (e.length === 0 && v.length === 0) {
1024
- if (f || this.currentLod !== -1) {
1025
- console.warn("[ShpZzts] 新 LOD 瓦片均为空(缓存命中),保留旧层");
1026
- return;
1027
- }
1028
- this._clearRenderedPrimitives(), console.log("[ShpZzts] 全部瓦片为空(缓存命中),清空渲染");
1029
- return;
1030
- }
1031
- if (E?.schedule(v.slice()), e.length > 0) {
1032
- let t = f ? "切 LOD 保留旧层" : g ? "首屏渐进换挂" : "同 LOD 双缓冲";
1033
- console.log(`[ShpZzts] 开始并发加载 ${e.length} 个瓦片(并发 ${this.fetchConcurrency},${t})...`), await j(e, this.fetchConcurrency, async (e) => {
1034
- if (r()) try {
1035
- let t = await this._fetchTileGeometries(e.geoSot, a, n.signal);
1036
- if (!r()) return;
1037
- x(t) && E?.schedule(v.slice());
1038
- } catch (t) {
1039
- if (n.signal.aborted || !r()) return;
1040
- console.warn(`[ShpZzts] 瓦片 ${e.geoSot} 加载失败,300ms 后重试一次:`, t?.message || t);
1041
- try {
1042
- if (await new Promise((e) => setTimeout(e, 300)), !r()) return;
1043
- let t = await this._fetchTileGeometries(e.geoSot, a, n.signal);
1044
- if (!r()) return;
1045
- x(t) && E?.schedule(v.slice());
1046
- } catch (t) {
1047
- if (n.signal.aborted || !r()) return;
1048
- T = !0, console.error(`[ShpZzts] 瓦片 ${e.geoSot} 重试仍失败:`, t?.message || t);
1049
- }
1050
- }
1051
- });
1052
- }
1053
- if (E) {
1054
- if (await E.whenIdle(), !r()) return;
1055
- v.length > 0 ? (T || _(), C(v)) : this._clearRenderedPrimitives();
1056
- }
1057
- }
1058
- if (!r()) return;
1059
- if (E) {
1060
- let e = (performance.now() - o).toFixed(0);
1061
- console.log(`[ShpZzts] 加载+渲染完成: ${v.length} 要素, ${e}ms`);
1062
- return;
1063
- }
1064
- let D = this._colorMapFromCache(v);
1065
- if (!g) {
1066
- if (D = await S(), !r()) return;
1067
- console.log(`[ShpZzts] 服务配色命中: ${D.size}/${this._collectFeatureIds(v).length}`);
1068
- }
1069
- if (this._lastViewData = {
1070
- lodLevel: a,
1071
- geometries: v,
1072
- colorMap: D
1073
- }, v.length > 0) {
1074
- if (f && T) {
1075
- console.warn("[ShpZzts] 部分瓦片失败,保留旧层,不切换 LOD");
1076
- return;
1077
- }
1078
- if (f) {
1079
- console.log(`[ShpZzts-SILOD] LOD 变化: ${d} → ${a}`);
1080
- for (let e of [...this.lodPrimitives.keys()]) e !== d && e !== a && this._destroyLodPrimitives(e);
1081
- this._destroyLodPrimitives(a), this._renderBatched(v, a, 0, () => {
1082
- if (!r()) {
1083
- this._destroyLodPrimitives(a);
1084
- return;
1085
- }
1086
- console.log(`[ShpZzts-SILOD] 新 LOD ${a} 分批渲染完成,启动交叉淡化`), this.currentLod = a, T || _(), this._crossFadeLod(d, a, r);
1087
- }, D);
1088
- } else this._renderBatched(v, a, 1, null, D, null, {
1089
- deferScene: !0,
1090
- onComplete: (e) => {
1091
- this._swapLodPrimitives(a, e, r) && (T || _(), g && this.isServiceColorEnabled() && C(v));
1092
- }
1093
- });
1094
- } else f ? console.warn("[ShpZzts] 新 LOD 无几何体,保留旧层") : this._clearRenderedPrimitives();
1095
- let O = (performance.now() - o).toFixed(0);
1096
- console.log(`[ShpZzts] 加载+渲染完成: ${v.length} 要素, ${O}ms`);
1097
- } catch (e) {
1098
- if (n.signal.aborted || e?.code === "ERR_CANCELED") return;
1099
- console.error("[ShpZzts] 加载失败:", e);
1100
- } finally {
1101
- this.activeAbort === n && (this.activeAbort = null);
1102
- }
1103
- }
1104
- _onCameraMoveEnd() {
1105
- this.debounceTimer && clearTimeout(this.debounceTimer), this.debounceTimer = setTimeout(() => {
1106
- this.destroyed || (console.log("[ShpZzts] 地图移动/缩放结束,重新加载瓦片"), this.loadAndRender());
1107
- }, 300);
1108
- }
1109
- _setupMoveHandler() {
1110
- this._moveHandler = () => this._onCameraMoveEnd(), this.viewer.camera.moveEnd.addEventListener(this._moveHandler);
1111
- }
1112
- _teardownMoveHandler() {
1113
- if (this._moveHandler) {
1114
- try {
1115
- this.viewer.camera.moveEnd.removeEventListener(this._moveHandler);
1116
- } catch {}
1117
- this._moveHandler = null;
1118
- }
1119
- }
1120
- async init() {
1121
- this.destroyed || (this._setupMoveHandler(), await this._openTileDb(), await this._waitForScreenBounds(), this.destroyed || this.loadAndRender(), console.log(`[ShpZzts] 图层 ${this.id} 初始化完成`));
1122
- }
1123
- remove() {
1124
- if (this.destroyed = !0, this.renderRequestToken += 1, this._lastViewData = null, this._lastTileSetKey = "", this._hiddenRebuildQueued = !1, this.activeAbort) {
1125
- try {
1126
- this.activeAbort.abort();
1127
- } catch {}
1128
- this.activeAbort = null;
1129
- }
1130
- this.tileCache.clear(), this.bulkCache.clear(), this.transitionAnimId !== null && (cancelAnimationFrame(this.transitionAnimId), this.transitionAnimId = null), this.debounceTimer &&= (clearTimeout(this.debounceTimer), null), this._teardownMoveHandler(), this.modelColorCache.clear(), this._colorDrain?.reset(), this._colorAllReady = !1, this._colorAllPromise = null;
1131
- for (let e of this.lodPrimitives.keys()) this._destroyLodPrimitives(e);
1132
- try {
1133
- this.gridDb?.closeDatabase();
1134
- } catch {}
1135
- this.gridDb = null, console.log(`[ShpZzts] 图层 ${this.id} 已移除`);
1136
- }
1137
- updateOptions(e = {}) {
1138
- let t = !1;
1139
- if (e.opacity !== void 0) {
1140
- let n = this._normOpacity(e.opacity);
1141
- n !== this.opacity && (this.opacity = n, t = !0);
1142
- }
1143
- if (e.stackIndex !== void 0 && (this.stackIndex = e.stackIndex), e.subStackIndex !== void 0 && (this.subStackIndex = e.subStackIndex), e.groupKey !== void 0 && (this.groupKey = e.groupKey), e.color !== void 0 && (this._userColor = e.color || null), e.pointSize !== void 0) {
1144
- let t = Number(e.pointSize);
1145
- if (Number.isFinite(t) && t > 0 && t !== this.pointSize) {
1146
- this.pointSize = t;
1147
- let e = this.lodPrimitives.get(this.currentLod);
1148
- if (e) {
1149
- for (let n of e) if (n.pointPrimitives) for (let e of n.pointPrimitives) T(e) || (e.pixelSize = t);
1150
- }
1151
- }
1152
- }
1153
- if (e.displayRange !== void 0 && (this.displayRange = w(e.displayRange)), e.outline !== void 0) {
1154
- let t = D(e.outline);
1155
- if (!O(this.outline, t)) {
1156
- let e = !!this.outline != !!t;
1157
- if (this.outline = t, e) this._clearRenderedPrimitives(), this.loadAndRender();
1158
- else {
1159
- let e = this.lodPrimitives.get(this.currentLod);
1160
- if (e) {
1161
- let t = this._resolveOutlineColor();
1162
- for (let n of e) if (n.polylines) for (let e of n.polylines) {
1163
- if (T(e)) continue;
1164
- e.width = this.outline.width;
1165
- let n = e.material?.uniforms;
1166
- n?.color && (n.color = new a.Color(t.red, t.green, t.blue, this.opacity * this._normAlpha(t.alpha)));
1167
- }
1168
- }
1169
- }
1170
- }
1171
- }
1172
- let n = !1;
1173
- if (e.dictCode !== void 0 && e.dictCode !== this.dictCode && (this.dictCode = e.dictCode || "", n = !0), e.serviceName !== void 0 && e.serviceName !== this.serviceName && (this.serviceName = e.serviceName || "", n = !0), e.enableServiceColor !== void 0 && !!e.enableServiceColor !== this.enableServiceColor && (this.enableServiceColor = !!e.enableServiceColor, n = !0), e.modelColorUrl !== void 0 && e.modelColorUrl !== this.modelColorUrl && (this.modelColorUrl = e.modelColorUrl || "/v1/zzts/style/render/modelColors", n = !0), n && this._resetServiceColorIndex(), e.hiddenColors !== void 0) {
1174
- let t = new Set((e.hiddenColors || []).map(S).filter(Boolean)), n = t.size !== this.hiddenColors.size || [...t].some((e) => !this.hiddenColors.has(e));
1175
- this.hiddenColors = t, n && this._rebuildForHiddenColors();
1176
- }
1177
- t && this._applyLayerOpacity(), console.log(`[ShpZzts] 图层 ${this.id} 配置已更新`, {
1178
- opacity: this.opacity,
1179
- stackIndex: this.stackIndex
1180
- });
1181
- }
1182
- };
1183
- function F(e, t) {
1184
- return !e && !t ? !0 : !e || !t ? !1 : e.west === t.west && e.south === t.south && e.east === t.east && e.north === t.north;
1185
- }
1186
- function I(e, t = {}) {
1187
- if (!e || e.destroyed) return !1;
1188
- let n = t.layerId || t.id;
1189
- return !(!n || e.id !== n || t.calTilesUrl && t.calTilesUrl !== e.calTilesUrl || t.tileUrl && t.tileUrl !== e.tileUrl || t.layerDataUrl && t.layerDataUrl !== e.layerDataUrl || t.dictCode !== void 0 && (t.dictCode || "") !== (e.dictCode || "") || t.serviceName !== void 0 && (t.serviceName || "") !== (e.serviceName || "") || t.enableServiceColor !== void 0 && !!t.enableServiceColor !== e.enableServiceColor || t.modelColorUrl && t.modelColorUrl !== e.modelColorUrl || t.color !== void 0 && (t.color || null) !== (e._userColor || null) || t.outline !== void 0 && !O(D(t.outline), e.outline) || t.displayRange !== void 0 && !F(e.displayRange, w(t.displayRange)));
1190
- }
1191
- var L = new class {
1192
- constructor() {
1193
- this.layers = /* @__PURE__ */ new Map();
1194
- }
1195
- async createLayer(e, t = {}) {
1196
- let n = t?.layerId || t?.id;
1197
- if (!n) return console.error("[ShpZzts] 创建图层失败:缺少 layerId"), null;
1198
- this.layers.has(n) && (console.warn(`[ShpZzts] 图层 ${n} 已存在,移除旧图层后重建`), this.removeLayer(n));
1199
- let r = new P(e, t);
1200
- return await r.init(), this.layers.set(n, r), r;
1201
- }
1202
- removeLayer(e) {
1203
- let t = this.layers.get(e);
1204
- t && (t.remove(), this.layers.delete(e), console.log(`[ShpZzts] 图层 ${e} 已移除`));
1205
- }
1206
- getLayer(e) {
1207
- return this.layers.get(e);
1208
- }
1209
- removeAllLayers() {
1210
- this.layers.forEach((e) => e.remove()), this.layers.clear();
1211
- }
1212
- }(), R = async (e, t) => L.createLayer(e, t), z = (e) => {
1213
- L.removeLayer(e);
1214
- }, B = (e) => L.getLayer(e), V = {
1215
- __name: "index",
1216
- props: {
1217
- config: {
1218
- type: Object,
1219
- default: () => ({})
1220
- },
1221
- stackIndex: {
1222
- type: Number,
1223
- default: -1
1224
- },
1225
- subStackIndex: {
1226
- type: Number,
1227
- default: 0
1228
- },
1229
- groupKey: {
1230
- type: String,
1231
- default: ""
1232
- }
1233
- },
1234
- setup(a) {
1235
- let o = t("cesiumViewer"), s = a, c = {
1236
- layerId: "",
1237
- calTilesUrl: "/v1/zzts/layer/shp/calTiles",
1238
- tileUrl: "/v1/zzts/layer/3d/getVectorTile",
1239
- layerDataUrl: "/v1/zzts/layer/3d/getVectorLayerData",
1240
- displayRange: null,
1241
- opacity: 1,
1242
- batchSize: 2e3,
1243
- transitionDuration: 50,
1244
- hiddenColors: []
1245
- }, l = e(() => ({
1246
- ...c,
1247
- ...s.config
1248
- })), u = "";
1249
- function d(e) {
1250
- return {
1251
- layerId: e.layerId,
1252
- calTilesUrl: e.calTilesUrl,
1253
- tileUrl: e.tileUrl,
1254
- layerDataUrl: e.layerDataUrl,
1255
- displayRange: e.displayRange,
1256
- opacity: e.opacity,
1257
- batchSize: e.batchSize,
1258
- transitionDuration: e.transitionDuration,
1259
- color: e.color,
1260
- pointSize: e.pointSize,
1261
- outline: e.outline,
1262
- outlineHeightOffset: e.outlineHeightOffset,
1263
- dictCode: e.dictCode,
1264
- serviceName: e.serviceName,
1265
- enableServiceColor: e.enableServiceColor,
1266
- modelColorUrl: e.modelColorUrl,
1267
- hiddenColors: e.hiddenColors,
1268
- stackIndex: s.stackIndex,
1269
- subStackIndex: s.subStackIndex,
1270
- groupKey: s.groupKey || e.layerId
1271
- };
1272
- }
1273
- let f = async () => {
1274
- let e = l.value;
1275
- if (!e.layerId) {
1276
- console.warn("[zzLayerShpZzts] 缺少 layerId,跳过初始化", e);
1277
- return;
1278
- }
1279
- let t = d(e);
1280
- u && u !== e.layerId && z(u);
1281
- let n = B(e.layerId);
1282
- if (n && I(n, t)) {
1283
- n.updateOptions(t), u = e.layerId;
1284
- return;
1285
- }
1286
- console.log("[zzLayerShpZzts] initLayer 入参 =", {
1287
- layerId: t.layerId,
1288
- calTilesUrl: t.calTilesUrl,
1289
- tileUrl: t.tileUrl,
1290
- opacity: t.opacity
1291
- }), await R(o.value, t), u = e.layerId;
1292
- }, p = () => {
1293
- z(l.value.layerId);
1294
- };
1295
- return i(() => s.config, async () => {
1296
- console.log("[zzLayerShpZzts] props.config changed =", JSON.parse(JSON.stringify(s.config || {}))), await f();
1297
- }, {
1298
- deep: !0,
1299
- immediate: !0
1300
- }), i(() => [
1301
- s.stackIndex,
1302
- s.subStackIndex,
1303
- s.groupKey
1304
- ], () => {
1305
- let e = l.value, t = B(e.layerId);
1306
- if (t && typeof t.updateOptions == "function") {
1307
- t.updateOptions({
1308
- stackIndex: s.stackIndex,
1309
- subStackIndex: s.subStackIndex,
1310
- groupKey: s.groupKey || e.layerId
1311
- });
1312
- return;
1313
- }
1314
- f();
1315
- }), n(() => {
1316
- console.log("[zzLayerShpZzts] 组件挂载");
1317
- }), r(() => {
1318
- console.log("[zzLayerShpZzts] 组件卸载,开始清理资源..."), u ? z(u) : p();
1319
- }), (e, t) => null;
1320
- }
1321
- };
1322
- //#endregion
1323
- export { V as default };