@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,1881 @@
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
+ //#region src/zz-layer/zz-layer-shp-zzts/shpZztsGeometryWorker.js?worker&inline
5
+ var c = "(function(){function e(e,t){let n=new Map,r=(e,r)=>{if(e===r)return;let i=e<r?e*t+r:r*t+e;n.set(i,(n.get(i)||0)+1)};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]);let i=new Map,a=[];for(let[e,r]of n){if(r!==1)continue;let n=Math.floor(e/t),o=e%t;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)}if(a.length===0)return[];let o=new Set,s=(e,n)=>e<n?e*t+n:n*t+e,c=[];for(let[e,t]of a){if(o.has(s(e,t)))continue;o.add(s(e,t));let n=[e,t],r=t;for(;;){let t=(i.get(r)||[]).find(e=>!o.has(s(r,e)));if(t===void 0||(o.add(s(r,t)),n.push(t),t===e))break;r=t}let a=e;for(;;){let e=(i.get(a)||[]).find(e=>!o.has(s(a,e)));if(e===void 0||(o.add(s(a,e)),n.unshift(e),e===t))break;a=e}n.length>=2&&c.push(n)}return c}function t(e){let t=performance.now(),n=[],r=new DataView(e),i=new TextDecoder,a=r.getInt32(0,!0);if(a<=0||a>1e5)return console.warn(`[ShpZzts] tileCount 异常: ${a},跳过解析`),n;console.log(`[ShpZzts] 瓦片数量: ${a}`);let o=4;for(let t=0;t<a;t++){let a=r.getInt32(o,!0);if(o+=4,a<=0||a>100*1024*1024){console.error(`[ShpZzts] dataLen 异常: ${a},跳过瓦片 ${t}`),o+=Math.max(0,a);continue}let s=new Uint8Array(e,o,a),c=new DataView(s.buffer,s.byteOffset,s.byteLength);o+=a;let l=0,u=String(t),d=0,f=c.getInt32(0,!0),p=!1;if(f>0&&f<=256&&a>=4+f+8){let e=f,t=s.slice(4,4+e),n=i.decode(t),r=4+e,o=!1;if(a>=r+1+8){let e=r+1,t=c.getInt32(e,!0);if(t>=24&&t%24==0&&t<=a-e-4){let i=e+4,s=c.getInt32(i,!0);r+1+8+t+s===a&&s>=0&&s%4==0&&(u=n,d=c.getUint8(r),l=e,p=!0,o=!0)}}if(!o){let t=r,i=c.getInt32(t,!0);if(i>=24&&i%24==0&&i<=a-t-4){let r=t+4,o=c.getInt32(r,!0);4+e+8+i+o===a&&o>=0&&o%4==0&&(u=n,l=t,p=!0)}}}p||(l=0);let m=c.getInt32(l,!0);l+=4;let h=c.getInt32(l,!0);if(l+=4,m<=0||m%24!=0){console.error(`[ShpZzts] positionsByteLen 非法: ${m},跳过瓦片 ${t}`);continue}if(h<0||h%4!=0){console.error(`[ShpZzts] indicesByteLen 非法: ${h},跳过瓦片 ${t}`);continue}let g=s.byteLength-l;if(m+h>g){console.error(`[ShpZzts] 数据长度溢出: pos=${m} + idx=${h} > remaining=${g},跳过瓦片 ${t}`);continue}let _=m/8/3,v=s.slice(l,l+m),y=new Float64Array(v.buffer,v.byteOffset,_*3);l+=m;let b=h/4;if(b>1e8){console.error(`[ShpZzts] indexCount 异常巨大: ${b},跳过瓦片 ${t}`);continue}let x=s.slice(l,l+h),S=new Uint32Array(x.buffer,x.byteOffset,b);l+=h;let C=!1;for(let e=0;e<y.length&&!C;e++)isFinite(y[e])||(C=!0);if(C){console.error(`[ShpZzts] NaN/Inf 坐标 tile=${t},跳过`);continue}let w=0;for(let e=0;e<S.length;e++)S[e]>w&&(w=S[e]);if(w>=_){console.error(`[ShpZzts] 索引越界 tile=${t} maxIdx=${w} vertexCount=${_},跳过`);continue}n.push({positions:y,indices:S,vertexCount:_,indexCount:b,featureId:u,geometryKind:d,fidTrusted:p})}let s=(performance.now()-t).toFixed(1);return console.log(`[ShpZzts] 解析完成: ${n.length} 要素, ${s}ms`),n}function n(e){if(!(e instanceof ArrayBuffer))throw Error(`瓦片响应不是二进制数据`);if(e.byteLength===0)return[];let n=new DataView(e);if(e.byteLength<4)throw Error(`瓦片信封不完整`);let r=n.getInt32(0,!0);if(r===0&&e.byteLength===4)return[];if(r<1||r>5e3)throw Error(`瓦片要素数量无效`);let i=4;for(let t=0;t<r;t++){if(i+4>e.byteLength)throw Error(`瓦片信封不完整`);let t=n.getInt32(i,!0);if(i+=4,t<8||i+t>e.byteLength)throw Error(`瓦片内容不完整`);i+=t}if(i!==e.byteLength)throw Error(`瓦片尾部长度无效`);let a=t(e);if(a.length!==r)throw Error(`瓦片包含无效要素`);return a}self.onmessage=({data:{id:t,buffer:r}})=>{try{let i=n(r),a=[];for(let t of i)t.boundaryRings=t.geometryKind===0?e(t.indices,t.vertexCount).map(e=>Uint32Array.from(e)):[],a.push(t.positions.buffer,t.indices.buffer,...t.boundaryRings.map(e=>e.buffer));self.postMessage({id:t,geometries:i},a)}catch(e){self.postMessage({id:t,error:e.message})}}})();", l = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", c], { type: "text/javascript;charset=utf-8" });
6
+ function u(e) {
7
+ let t;
8
+ try {
9
+ if (t = l && (self.URL || self.webkitURL).createObjectURL(l), !t) throw "";
10
+ let n = new Worker(t, { name: e?.name });
11
+ return n.addEventListener("error", () => {
12
+ (self.URL || self.webkitURL).revokeObjectURL(t);
13
+ }), n;
14
+ } catch {
15
+ return new Worker("data:text/javascript;charset=utf-8," + encodeURIComponent(c), { name: e?.name });
16
+ }
17
+ }
18
+ //#endregion
19
+ //#region src/zz-layer/zz-layer-shp-zzts/shpZztsGeometry.js
20
+ function d(e, t) {
21
+ let n = /* @__PURE__ */ new Map(), r = (e, r) => {
22
+ if (e === r) return;
23
+ let i = e < r ? e * t + r : r * t + e;
24
+ n.set(i, (n.get(i) || 0) + 1);
25
+ };
26
+ 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]);
27
+ let i = /* @__PURE__ */ new Map(), a = [];
28
+ for (let [e, r] of n) {
29
+ if (r !== 1) continue;
30
+ let n = Math.floor(e / t), o = e % t;
31
+ 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);
32
+ }
33
+ if (a.length === 0) return [];
34
+ let o = /* @__PURE__ */ new Set(), s = (e, n) => e < n ? e * t + n : n * t + e, c = [];
35
+ for (let [e, t] of a) {
36
+ if (o.has(s(e, t))) continue;
37
+ o.add(s(e, t));
38
+ let n = [e, t], r = t;
39
+ for (;;) {
40
+ let t = (i.get(r) || []).find((e) => !o.has(s(r, e)));
41
+ if (t === void 0 || (o.add(s(r, t)), n.push(t), t === e)) break;
42
+ r = t;
43
+ }
44
+ let a = e;
45
+ for (;;) {
46
+ let e = (i.get(a) || []).find((e) => !o.has(s(a, e)));
47
+ if (e === void 0 || (o.add(s(a, e)), n.unshift(e), e === t)) break;
48
+ a = e;
49
+ }
50
+ n.length >= 2 && c.push(n);
51
+ }
52
+ return c;
53
+ }
54
+ function f(e) {
55
+ let t = performance.now(), n = [], r = new DataView(e), i = new TextDecoder(), a = r.getInt32(0, !0);
56
+ if (a <= 0 || a > 1e5) return console.warn(`[ShpZzts] tileCount 异常: ${a},跳过解析`), n;
57
+ console.log(`[ShpZzts] 瓦片数量: ${a}`);
58
+ let o = 4;
59
+ for (let t = 0; t < a; t++) {
60
+ let a = r.getInt32(o, !0);
61
+ if (o += 4, a <= 0 || a > 100 * 1024 * 1024) {
62
+ console.error(`[ShpZzts] dataLen 异常: ${a},跳过瓦片 ${t}`), o += Math.max(0, a);
63
+ continue;
64
+ }
65
+ let s = new Uint8Array(e, o, a), c = new DataView(s.buffer, s.byteOffset, s.byteLength);
66
+ o += a;
67
+ let l = 0, u = String(t), d = 0, f = c.getInt32(0, !0), p = !1;
68
+ if (f > 0 && f <= 256 && a >= 4 + f + 8) {
69
+ let e = f, t = s.slice(4, 4 + e), n = i.decode(t), r = 4 + e, o = !1;
70
+ if (a >= r + 1 + 8) {
71
+ let e = r + 1, t = c.getInt32(e, !0);
72
+ if (t >= 24 && t % 24 == 0 && t <= a - e - 4) {
73
+ let i = e + 4, s = c.getInt32(i, !0);
74
+ r + 1 + 8 + t + s === a && s >= 0 && s % 4 == 0 && (u = n, d = c.getUint8(r), l = e, p = !0, o = !0);
75
+ }
76
+ }
77
+ if (!o) {
78
+ let t = r, i = c.getInt32(t, !0);
79
+ if (i >= 24 && i % 24 == 0 && i <= a - t - 4) {
80
+ let r = t + 4, o = c.getInt32(r, !0);
81
+ 4 + e + 8 + i + o === a && o >= 0 && o % 4 == 0 && (u = n, l = t, p = !0);
82
+ }
83
+ }
84
+ }
85
+ p || (l = 0);
86
+ let m = c.getInt32(l, !0);
87
+ l += 4;
88
+ let h = c.getInt32(l, !0);
89
+ if (l += 4, m <= 0 || m % 24 != 0) {
90
+ console.error(`[ShpZzts] positionsByteLen 非法: ${m},跳过瓦片 ${t}`);
91
+ continue;
92
+ }
93
+ if (h < 0 || h % 4 != 0) {
94
+ console.error(`[ShpZzts] indicesByteLen 非法: ${h},跳过瓦片 ${t}`);
95
+ continue;
96
+ }
97
+ let g = s.byteLength - l;
98
+ if (m + h > g) {
99
+ console.error(`[ShpZzts] 数据长度溢出: pos=${m} + idx=${h} > remaining=${g},跳过瓦片 ${t}`);
100
+ continue;
101
+ }
102
+ let _ = m / 8 / 3, v = s.slice(l, l + m), y = new Float64Array(v.buffer, v.byteOffset, _ * 3);
103
+ l += m;
104
+ let b = h / 4;
105
+ if (b > 1e8) {
106
+ console.error(`[ShpZzts] indexCount 异常巨大: ${b},跳过瓦片 ${t}`);
107
+ continue;
108
+ }
109
+ let x = s.slice(l, l + h), S = new Uint32Array(x.buffer, x.byteOffset, b);
110
+ l += h;
111
+ let C = !1;
112
+ for (let e = 0; e < y.length && !C; e++) isFinite(y[e]) || (C = !0);
113
+ if (C) {
114
+ console.error(`[ShpZzts] NaN/Inf 坐标 tile=${t},跳过`);
115
+ continue;
116
+ }
117
+ let w = 0;
118
+ for (let e = 0; e < S.length; e++) S[e] > w && (w = S[e]);
119
+ if (w >= _) {
120
+ console.error(`[ShpZzts] 索引越界 tile=${t} maxIdx=${w} vertexCount=${_},跳过`);
121
+ continue;
122
+ }
123
+ n.push({
124
+ positions: y,
125
+ indices: S,
126
+ vertexCount: _,
127
+ indexCount: b,
128
+ featureId: u,
129
+ geometryKind: d,
130
+ fidTrusted: p
131
+ });
132
+ }
133
+ let s = (performance.now() - t).toFixed(1);
134
+ return console.log(`[ShpZzts] 解析完成: ${n.length} 要素, ${s}ms`), n;
135
+ }
136
+ function p(e) {
137
+ let { indices: t, positions: n } = e;
138
+ if (e.geometryKind !== 1 || !t?.length || t.length % 6 || !n?.length) return [];
139
+ let r = [], i = null, a = -1, o = (e, t) => [
140
+ 0,
141
+ 1,
142
+ 2
143
+ ].map((r) => (n[e * 3 + r] + n[t * 3 + r]) / 2);
144
+ for (let e = 0; e < t.length; e += 6) {
145
+ let [s, c, l, u, d, f] = Array.from(t.slice(e, e + 6));
146
+ if (c !== s + 1 || d !== l + 1 || u !== c || f !== l || s * 3 + 2 >= n.length || d * 3 + 2 >= n.length) return [];
147
+ a !== s && (i = [o(s, c)], r.push(i)), i.push(o(l, d)), a = l;
148
+ }
149
+ return r;
150
+ }
151
+ function m(e) {
152
+ if (!(e instanceof ArrayBuffer)) throw Error("瓦片响应不是二进制数据");
153
+ if (e.byteLength === 0) return [];
154
+ let t = new DataView(e);
155
+ if (e.byteLength < 4) throw Error("瓦片信封不完整");
156
+ let n = t.getInt32(0, !0);
157
+ if (n === 0 && e.byteLength === 4) return [];
158
+ if (n < 1 || n > 5e3) throw Error("瓦片要素数量无效");
159
+ let r = 4;
160
+ for (let i = 0; i < n; i++) {
161
+ if (r + 4 > e.byteLength) throw Error("瓦片信封不完整");
162
+ let n = t.getInt32(r, !0);
163
+ if (r += 4, n < 8 || r + n > e.byteLength) throw Error("瓦片内容不完整");
164
+ r += n;
165
+ }
166
+ if (r !== e.byteLength) throw Error("瓦片尾部长度无效");
167
+ let i = f(e);
168
+ if (i.length !== n) throw Error("瓦片包含无效要素");
169
+ return i;
170
+ }
171
+ function h(e, t = 2e3) {
172
+ let n = [], r = [], i = 0, a = 0;
173
+ for (let o of e) {
174
+ let e = o.vertexCount, s = o.indexCount / 3;
175
+ r.length && (r.length >= t || i + e > 4e4 || a + s > 4e4) && (n.push(r), r = [], i = 0, a = 0), r.push(o), i += e, a += s;
176
+ }
177
+ return r.length && n.push(r), n;
178
+ }
179
+ //#endregion
180
+ //#region src/zz-layer/zz-layer-shp-zzts/shpZztsViewState.js
181
+ var g = 128 * 1024 * 1024, _ = 3e6;
182
+ function v(e) {
183
+ if (!e || typeof e != "object") return null;
184
+ let t = Array.isArray(e) ? e.slice(0, 4) : [
185
+ e.west ?? e.longitudeWest,
186
+ e.south ?? e.latitudeSouth,
187
+ e.east ?? e.longitudeEast,
188
+ e.north ?? e.latitudeNorth
189
+ ];
190
+ if (t.length !== 4 || t.some((e) => e == null || e === "")) return null;
191
+ let [n, r, i, a] = t.map(Number);
192
+ if (![
193
+ n,
194
+ r,
195
+ i,
196
+ a
197
+ ].every(Number.isFinite) || r < -90 || a > 90 || r >= a) return null;
198
+ let o = i - n;
199
+ if (Math.abs(o) >= 360) return [{
200
+ west: -180,
201
+ south: r,
202
+ east: 180,
203
+ north: a
204
+ }];
205
+ let s = (o % 360 + 360) % 360;
206
+ if (s === 0) return null;
207
+ let c = ((n + 180) % 360 + 360) % 360 - 180, l = c + s;
208
+ return l <= 180 ? [{
209
+ west: c,
210
+ south: r,
211
+ east: l,
212
+ north: a
213
+ }] : [{
214
+ west: c,
215
+ south: r,
216
+ east: 180,
217
+ north: a
218
+ }, {
219
+ west: -180,
220
+ south: r,
221
+ east: l - 360,
222
+ north: a
223
+ }];
224
+ }
225
+ function y(e, t) {
226
+ let n = v(e), r = v(t);
227
+ return !n || !r ? !0 : n.some((e) => r.some((t) => e.west < t.east && e.east > t.west && e.south < t.north && e.north > t.south));
228
+ }
229
+ function b(e, t, n = []) {
230
+ let r = Array.isArray(e) ? e.filter(Boolean) : [], i = Array.isArray(t) ? t.filter(Boolean) : [], a = Array.isArray(n) ? n.filter(Boolean) : [], o = i.length === 0 ? [] : a.filter((e) => i.some((t) => y(e.tile?.bounds, t.bounds))), s = [...r, ...o], c = [], l = /* @__PURE__ */ new Set();
231
+ for (let e of s) if (Array.isArray(e.geometries)) {
232
+ for (let t of e.geometries) if (t) {
233
+ if (t.fidTrusted) {
234
+ let e = String(t.featureId ?? "").trim();
235
+ if (e) {
236
+ if (l.has(e)) continue;
237
+ l.add(e);
238
+ }
239
+ }
240
+ c.push(t);
241
+ }
242
+ }
243
+ return {
244
+ records: s,
245
+ geometries: c
246
+ };
247
+ }
248
+ function x(e, t, n, r) {
249
+ let i = /* @__PURE__ */ Error(`Preview geometry exceeds resource budget (${e} bytes, ${t} triangles)`);
250
+ return i.code = "PREVIEW_RESOURCE_LIMIT", i.bytes = e, i.triangles = t, i.maxBytes = n, i.maxTriangles = r, i;
251
+ }
252
+ function S(e, { maxBytes: t = g, maxTriangles: n = _ } = {}) {
253
+ if (![t, n].every((e) => Number.isFinite(e) && e >= 0)) throw RangeError("Preview resource limits must be finite nonnegative numbers");
254
+ if (!Array.isArray(e)) throw TypeError("Preview geometries must be an array");
255
+ let r = 0, i = 0;
256
+ for (let a of e) {
257
+ let e = a?.positions?.byteLength ?? 0, o = a?.indices?.byteLength ?? 0, s = a?.indices?.length ?? 0;
258
+ if (![
259
+ e,
260
+ o,
261
+ s
262
+ ].every((e) => Number.isSafeInteger(e) && e >= 0) || a?.positions && !Number.isFinite(a.positions.byteLength) || a?.indices && !Number.isFinite(a.indices.byteLength)) throw x(Infinity, Infinity, t, n);
263
+ if (r += e + o, i += s / 3, r > t || i > n) throw x(r, i, t, n);
264
+ }
265
+ return {
266
+ bytes: r,
267
+ triangles: i
268
+ };
269
+ }
270
+ //#endregion
271
+ //#region src/zz-layer/zz-layer-shp-zzts/shpZztsBounds.js
272
+ function C(e) {
273
+ if (!e || typeof e != "object") return null;
274
+ let t = [
275
+ e.longitudeWest ?? e.west,
276
+ e.latitudeSouth ?? e.south,
277
+ e.longitudeEast ?? e.east,
278
+ e.latitudeNorth ?? e.north
279
+ ];
280
+ if (t.some((e) => e == null || e === "")) return null;
281
+ let [n, r, i, a] = t.map(Number);
282
+ return ![
283
+ n,
284
+ r,
285
+ i,
286
+ a
287
+ ].every(Number.isFinite) || n < -180 || n > 180 || i < -180 || i > 180 || r < -90 || a > 90 || n === i || r >= a || n > i && 360 - n + i <= 0 ? null : {
288
+ west: n,
289
+ south: r,
290
+ east: i,
291
+ north: a
292
+ };
293
+ }
294
+ function w(e) {
295
+ return e.west < e.east ? [[e.west, e.east]] : [[e.west, 180], [-180, e.east]].filter(([e, t]) => e < t);
296
+ }
297
+ function ee(e, t) {
298
+ if (e = C(e), t = C(t), !e || !t) return null;
299
+ let n = Math.max(e.south, t.south), r = Math.min(e.north, t.north);
300
+ if (n >= r) return null;
301
+ let i = [];
302
+ for (let [n, r] of w(e)) for (let [e, a] of w(t)) {
303
+ let t = Math.max(n, e), o = Math.min(r, a);
304
+ t < o && i.push([t, o]);
305
+ }
306
+ i.sort((e, t) => e[0] - t[0]);
307
+ let a = [];
308
+ for (let e of i) {
309
+ let t = a.at(-1);
310
+ t && e[0] <= t[1] ? t[1] = Math.max(t[1], e[1]) : a.push(e.slice());
311
+ }
312
+ if (a.length === 0) return null;
313
+ if (a.length === 1) return {
314
+ west: a[0][0],
315
+ south: n,
316
+ east: a[0][1],
317
+ north: r
318
+ };
319
+ let o = -1, s = 0;
320
+ for (let e = 0; e < a.length; e++) {
321
+ let t = (e + 1 < a.length ? a[e + 1][0] : a[0][0] + 360) - a[e][1];
322
+ t > o && (o = t, s = e);
323
+ }
324
+ return {
325
+ west: a[(s + 1) % a.length][0],
326
+ south: n,
327
+ east: a[s][1],
328
+ north: r
329
+ };
330
+ }
331
+ var T = [
332
+ "plan",
333
+ "tile",
334
+ "color",
335
+ "retry"
336
+ ];
337
+ function E(e, t) {
338
+ let n = Error(t);
339
+ return n.code = e, n;
340
+ }
341
+ function D(e) {
342
+ let t = E("ABORT_ERR", "Preview request was cancelled");
343
+ return t.name = "AbortError", e?.reason !== void 0 && (t.cause = e.reason), t;
344
+ }
345
+ function O(e) {
346
+ if (e?.aborted) throw D(e);
347
+ }
348
+ function k(e, t, n, r) {
349
+ if (!Number.isSafeInteger(e) || e < n || e > r) throw RangeError(`${t} must be an integer between ${n} and ${r}`);
350
+ return e;
351
+ }
352
+ function A(e) {
353
+ if (!T.includes(e)) throw TypeError(`Unknown preview request kind: ${e}`);
354
+ }
355
+ function j({ maxRequests: e = 20, reserve: t = {} } = {}) {
356
+ k(e, "maxRequests", 1, 20);
357
+ let n = t.plan ?? 1, r = t.color ?? Math.min(2, Math.max(0, e - n)), i = t.retry ?? Math.min(2, Math.max(0, e - n - r));
358
+ for (let [t, a] of Object.entries({
359
+ plan: n,
360
+ color: r,
361
+ retry: i
362
+ })) k(a, `reserve.${t}`, 0, e);
363
+ if (n + r + i > e) throw RangeError("Reserved requests exceed maxRequests");
364
+ let a = Object.freeze({
365
+ plan: n,
366
+ color: r,
367
+ tile: e - n - r - i,
368
+ retry: e
369
+ }), o = {
370
+ plan: n,
371
+ color: r,
372
+ tile: a.tile,
373
+ retry: i
374
+ }, s = {
375
+ plan: 0,
376
+ tile: 0,
377
+ color: 0,
378
+ retry: 0
379
+ }, c = new AbortController(), l = 0, u = {
380
+ maxRequests: e,
381
+ limits: a,
382
+ signal: c.signal,
383
+ get used() {
384
+ return l;
385
+ },
386
+ get remaining() {
387
+ return e - l;
388
+ },
389
+ get usedByKind() {
390
+ return { ...s };
391
+ },
392
+ available(t = "tile") {
393
+ if (A(t), c.signal.aborted) return 0;
394
+ let n = 0;
395
+ for (let e of T) e !== t && (n += Math.max(0, o[e] - s[e]));
396
+ return Math.max(0, Math.min(a[t] - s[t], e - l - n));
397
+ },
398
+ consume(e = "tile") {
399
+ if (O(c.signal), u.available(e) <= 0) throw E("PREVIEW_BUDGET_EXHAUSTED", `Preview ${e} request budget exhausted`);
400
+ l += 1, s[e] += 1;
401
+ },
402
+ releaseReserved(e) {
403
+ A(e), o[e] = Math.min(o[e], s[e]);
404
+ },
405
+ cancel(e) {
406
+ c.abort(e);
407
+ }
408
+ };
409
+ return u;
410
+ }
411
+ function M({ concurrency: e = 4, maxQueued: t = 128 } = {}) {
412
+ k(e, "concurrency", 1, 64), k(t, "maxQueued", 0, 1e4);
413
+ let n = [], r = 0;
414
+ function i() {
415
+ for (; r < e && n.length;) a(n.shift());
416
+ }
417
+ function a(e) {
418
+ if (e.removeAbortListener(), e.signal?.aborted) {
419
+ e.reject(D(e.signal));
420
+ return;
421
+ }
422
+ r += 1;
423
+ let t = () => {
424
+ --r, i();
425
+ };
426
+ Promise.resolve().then(() => (O(e.signal), e.task(e.signal))).then((n) => {
427
+ t(), e.resolve(n);
428
+ }, (n) => {
429
+ t(), e.reject(n);
430
+ });
431
+ }
432
+ return {
433
+ concurrency: e,
434
+ maxQueued: t,
435
+ get active() {
436
+ return r;
437
+ },
438
+ get queued() {
439
+ return n.length;
440
+ },
441
+ run(o, { signal: s } = {}) {
442
+ return typeof o == "function" ? s?.aborted ? Promise.reject(D(s)) : r >= e && n.length >= t ? Promise.reject(E("PREVIEW_QUEUE_FULL", "Preview request queue is full")) : new Promise((t, c) => {
443
+ let l = {
444
+ task: o,
445
+ signal: s,
446
+ resolve: t,
447
+ reject: c,
448
+ removeAbortListener: () => {}
449
+ };
450
+ if (r < e && n.length === 0) {
451
+ a(l);
452
+ return;
453
+ }
454
+ let u = () => {
455
+ let e = n.indexOf(l);
456
+ e < 0 || (n.splice(e, 1), l.removeAbortListener(), c(D(s)), i());
457
+ };
458
+ l.removeAbortListener = () => s?.removeEventListener("abort", u), s?.addEventListener("abort", u, { once: !0 }), n.push(l);
459
+ }) : Promise.reject(/* @__PURE__ */ TypeError("Preview task must be a function"));
460
+ }
461
+ };
462
+ }
463
+ var N = M();
464
+ function te(e) {
465
+ let t = new AbortController(), n = [];
466
+ for (let r of new Set(e.filter(Boolean))) {
467
+ if (r.aborted) {
468
+ t.abort(r.reason);
469
+ break;
470
+ }
471
+ let e = () => t.abort(r.reason);
472
+ r.addEventListener("abort", e, { once: !0 }), n.push(() => r.removeEventListener("abort", e));
473
+ }
474
+ return {
475
+ signal: t.signal,
476
+ cleanup: () => n.forEach((e) => e())
477
+ };
478
+ }
479
+ async function ne({ budget: e, signal: t }, n, { kind: r = "tile", pool: i = N } = {}) {
480
+ if (!e || typeof e.consume != "function") throw TypeError("A preview budget is required");
481
+ if (typeof n != "function") throw TypeError("Preview task must be a function");
482
+ A(r);
483
+ let a = te([e.signal, t]);
484
+ try {
485
+ if (O(a.signal), e.available(r) <= 0) throw E("PREVIEW_BUDGET_EXHAUSTED", `Preview ${r} request budget exhausted`);
486
+ return await i.run(() => (O(a.signal), e.consume(r), n(a.signal)), { signal: a.signal });
487
+ } finally {
488
+ a.cleanup();
489
+ }
490
+ }
491
+ function re(e) {
492
+ let t = e?.data ?? e;
493
+ if (!t || typeof t != "object") return "failed";
494
+ let n = String(t.status ?? t.state ?? "").toUpperCase().replace(/-/g, "_");
495
+ return n === "NO_DATA" || n === "EMPTY" ? Array.isArray(t.tiles) && t.tiles.length > 0 ? "failed" : "no-data" : [
496
+ "FAILED",
497
+ "ERROR",
498
+ "INVALID"
499
+ ].includes(n) ? "failed" : [
500
+ "BUSY",
501
+ "DEFERRED",
502
+ "BUDGET_EXCEEDED",
503
+ "UNAVAILABLE"
504
+ ].includes(n) ? "deferred" : Array.isArray(t.tiles) && t.tiles.length > 0 ? "ready" : "deferred";
505
+ }
506
+ var P = "vectorTile";
507
+ function ie(e) {
508
+ return `shpZzts_${String(e || "")}`;
509
+ }
510
+ function ae(e, t) {
511
+ return `${e}|${t}`;
512
+ }
513
+ function oe(e, t) {
514
+ return `v6_${e}_${t}`;
515
+ }
516
+ function se(e) {
517
+ return `v6_bulk_${e}`;
518
+ }
519
+ function F(e, t) {
520
+ let n = (t || []).map((e) => String(e?.geoSot || "").trim()).filter(Boolean).sort();
521
+ return `${Number(e)}|${n.join(",")}`;
522
+ }
523
+ function I({ tileSetKey: e, lastTileSetKey: t, currentLod: n, lodLevel: r, hasPrimitives: i } = {}) {
524
+ return !e || !t || e !== t || Number(n) !== Number(r) ? !1 : !!i;
525
+ }
526
+ function L(e, t) {
527
+ if (!e || !e.has(t)) return;
528
+ let n = e.get(t);
529
+ return e.delete(t), e.set(t, n), n;
530
+ }
531
+ function R(e, t, n, r) {
532
+ if (!e) return n;
533
+ e.set(t, n);
534
+ let i = Number(r);
535
+ if (Number.isFinite(i) && i > 0) for (; e.size > i;) e.delete(e.keys().next().value);
536
+ return n;
537
+ }
538
+ function z(e) {
539
+ return e instanceof ArrayBuffer && e.byteLength > 8;
540
+ }
541
+ function B(e, t = !1) {
542
+ return t ? !1 : e instanceof ArrayBuffer;
543
+ }
544
+ function V(e = []) {
545
+ return [...new Set((e || []).map((e) => String(e?.featureId ?? "").trim()).filter(Boolean))];
546
+ }
547
+ function H(e) {
548
+ let t = null, n = !1, r = [];
549
+ function i() {
550
+ let e = r;
551
+ r = [];
552
+ for (let t of e) t();
553
+ }
554
+ async function a() {
555
+ if (!n) {
556
+ n = !0;
557
+ try {
558
+ for (; t;) {
559
+ let n = t;
560
+ t = null;
561
+ try {
562
+ await e(n);
563
+ } catch {}
564
+ }
565
+ } finally {
566
+ n = !1, t ? await a() : i();
567
+ }
568
+ }
569
+ }
570
+ function o(e) {
571
+ !Array.isArray(e) || e.length === 0 || (t = e, n || a());
572
+ }
573
+ function s() {
574
+ return !n && !t ? Promise.resolve() : new Promise((e) => r.push(e));
575
+ }
576
+ return {
577
+ schedule: o,
578
+ whenIdle: s
579
+ };
580
+ }
581
+ function U({ cache: e, postBatch: t, batchSize: n = 800, coalesceMs: r = 48, postConcurrency: i = 2, delay: a = (e) => new Promise((t) => setTimeout(t, e)) } = {}) {
582
+ let o = /* @__PURE__ */ new Set(), s = null;
583
+ function c() {
584
+ let t = [];
585
+ for (let r of [...o]) if (o.delete(r), !e?.has(r) && (t.push(r), t.length >= n)) break;
586
+ return t;
587
+ }
588
+ async function l(n) {
589
+ if (n.length === 0) return;
590
+ let r = [];
591
+ try {
592
+ r = await t(n) || [];
593
+ } catch {
594
+ return;
595
+ }
596
+ let i = /* @__PURE__ */ new Map();
597
+ for (let e of r) {
598
+ let t = String(e?.modelId || e?.model_id || "").trim();
599
+ t && e?.color && i.set(t, e.color);
600
+ }
601
+ for (let t of n) e.set(t, i.get(t) ?? null);
602
+ }
603
+ async function u() {
604
+ let e = o.size >= n ? 0 : r;
605
+ e > 0 && await a(e);
606
+ try {
607
+ for (; o.size > 0;) {
608
+ let e = [], t = Math.max(1, Number(i) || 1);
609
+ for (; o.size > 0 && e.length < t;) {
610
+ let t = c();
611
+ if (t.length === 0) break;
612
+ e.push(t);
613
+ }
614
+ if (e.length === 0) break;
615
+ await Promise.all(e.map((e) => l(e)));
616
+ }
617
+ } finally {
618
+ s = null;
619
+ }
620
+ }
621
+ async function d(t = []) {
622
+ let n = [...new Set((t || []).map((e) => String(e ?? "").trim()).filter(Boolean))];
623
+ if (n.length === 0) return;
624
+ let r = 0;
625
+ for (; n.some((t) => !e.has(t)) && r < 3;) {
626
+ for (let t of n) e.has(t) || o.add(t);
627
+ s ||= u(), await s, r += 1;
628
+ }
629
+ }
630
+ function f() {
631
+ o.clear();
632
+ }
633
+ return {
634
+ ensure: d,
635
+ reset: f
636
+ };
637
+ }
638
+ //#endregion
639
+ //#region src/zz-layer/zz-layer-shp-zzts/shpZztsRenderer.js
640
+ function W(e) {
641
+ if (e == null) return "";
642
+ let t = String(e).trim();
643
+ if (!t) return "";
644
+ let n = t.match(/^#([0-9a-f]{6})(?:[0-9a-f]{2})?$/i);
645
+ if (n) return [
646
+ 0,
647
+ 2,
648
+ 4
649
+ ].map((e) => parseInt(n[1].slice(e, e + 2), 16)).join(",");
650
+ let r = t.match(/^rgba?\(\s*(\d{1,3})[,\s]+(\d{1,3})[,\s]+(\d{1,3})/i);
651
+ 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(",") : "";
652
+ }
653
+ function G(e) {
654
+ if (!e) return "";
655
+ let t = (e) => Math.max(0, Math.min(255, Math.round(Number(e) * 255)));
656
+ return `${t(e.red)},${t(e.green)},${t(e.blue)}`;
657
+ }
658
+ function K(e) {
659
+ return C(e);
660
+ }
661
+ function q(e) {
662
+ return e ? typeof e.isDestroyed == "function" ? e.isDestroyed() : !1 : !0;
663
+ }
664
+ function ce(e, t) {
665
+ return ee(e, t);
666
+ }
667
+ function J(e) {
668
+ if (!e || typeof e != "object" || e.visible === !1) return null;
669
+ let t = Number(e.width), n = e.color || e.outlineColor;
670
+ return !n || !Number.isFinite(t) || t <= 0 ? null : {
671
+ color: String(n),
672
+ width: t
673
+ };
674
+ }
675
+ function Y(e, t) {
676
+ return !e && !t ? !0 : !e || !t ? !1 : e.color === t.color && e.width === t.width;
677
+ }
678
+ async function le(e, t, n) {
679
+ let r = 0, i = Math.max(1, Math.min(t, e.length)), a = [];
680
+ for (let t = 0; t < i; t++) a.push((async () => {
681
+ for (; r < e.length;) {
682
+ let t = e[r++];
683
+ await n(t);
684
+ }
685
+ })());
686
+ await Promise.all(a);
687
+ }
688
+ var X = 512, Z = 2, ue = class {
689
+ constructor(e, t = {}) {
690
+ 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.virtualLineStyle = t.virtualLineStyle || null, this.virtualPointStyle = t.virtualPointStyle || null, this.displayRange = K(t.displayRange);
691
+ let n = Number(t.pointSize);
692
+ this.pointSize = Number.isFinite(n) && n > 0 ? n : 5, this._userColor = t.color || null, this.outline = J(t.outline);
693
+ let r = Number(t.outlineHeightOffset);
694
+ 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(W).filter(Boolean)), this.currentLod = -1, this.lodPrimitives = /* @__PURE__ */ new Map(), this.transitionAnimId = null, this.tileCache = /* @__PURE__ */ new Map(), this.geometryWorker = null, this.geometryTasks = /* @__PURE__ */ new Map(), this.geometryTaskId = 0, this.bulkCache = /* @__PURE__ */ new Map(), this.activeAbort = null, this._previewContext = null, this._activePreviewLoad = null, this.previewStatus = {
695
+ state: "IDLE",
696
+ requests: 0
697
+ }, this._statusElement = null, this.onPreviewStatus = t.onPreviewStatus, 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;
698
+ }
699
+ _normOpacity(e) {
700
+ let t = Number(e);
701
+ return Number.isFinite(t) ? Math.max(0, Math.min(1, t)) : 1;
702
+ }
703
+ _normAlpha(e) {
704
+ let t = Number(e);
705
+ 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;
706
+ }
707
+ _resolveColor() {
708
+ if (!this._userColor) return a.Color.fromCssColorString("#4A90D9");
709
+ try {
710
+ if (typeof this._userColor == "string") return a.Color.fromCssColorString(this._userColor);
711
+ 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));
712
+ } catch {
713
+ console.warn("[ShpZzts] 颜色解析失败,回退默认淡蓝色:", this._userColor);
714
+ }
715
+ return a.Color.fromCssColorString("#4A90D9");
716
+ }
717
+ _setPreviewStatus(e, t = "", n = this._previewContext) {
718
+ if (this.destroyed || n && n !== this._previewContext) return;
719
+ this.previewStatus = {
720
+ state: e,
721
+ message: t,
722
+ requests: n?.budget?.used || 0
723
+ }, this.onPreviewStatus?.(this.previewStatus);
724
+ let r = this.viewer?.container;
725
+ if (!(!r || typeof document > "u")) {
726
+ if (!this._statusElement) {
727
+ let e = document.createElement("div");
728
+ e.className = "zzts-preview-status", e.setAttribute("role", "status"), e.setAttribute("aria-live", "polite"), Object.assign(e.style, {
729
+ position: "absolute",
730
+ right: "12px",
731
+ bottom: "52px",
732
+ zIndex: "10",
733
+ maxWidth: "calc(100% - 24px)",
734
+ padding: "7px 10px",
735
+ borderRadius: "4px",
736
+ color: "#fff",
737
+ background: "rgba(25, 35, 50, .82)",
738
+ fontSize: "12px",
739
+ pointerEvents: "none"
740
+ }), r.appendChild(e), this._statusElement = e;
741
+ }
742
+ this._statusElement.textContent = t, this._statusElement.hidden = !t;
743
+ }
744
+ }
745
+ _previewRequest(e, t = this._previewContext, n = "tile") {
746
+ if (!t) throw Error("预览请求缺少当前视野预算");
747
+ return ne(t, (t) => s.request({
748
+ ...e,
749
+ signal: t
750
+ }), { kind: n });
751
+ }
752
+ isServiceColorEnabled() {
753
+ return !!(this.enableServiceColor && this.serviceName && this.dictCode && this.modelColorUrl);
754
+ }
755
+ _collectFeatureIds(e = []) {
756
+ return V(e);
757
+ }
758
+ _colorMapFromCache(e = []) {
759
+ let t = /* @__PURE__ */ new Map();
760
+ if (!this.isServiceColorEnabled()) return t;
761
+ for (let n of this._collectFeatureIds(e)) {
762
+ let e = this.modelColorCache.get(n);
763
+ e && t.set(n, e);
764
+ }
765
+ return t;
766
+ }
767
+ _ingestModelColorRows(e = []) {
768
+ let t = 0;
769
+ for (let n of e || []) {
770
+ let e = String(n.modelId || n.model_id || "").trim(), r = n.color;
771
+ e && r && (this.modelColorCache.set(e, r), t += 1);
772
+ }
773
+ return t;
774
+ }
775
+ _resetServiceColorIndex() {
776
+ this.modelColorCache.clear(), this._colorDrain?.reset(), this._colorAllReady = !1, this._colorAllPromise = null;
777
+ }
778
+ async _fetchAllServiceColors(e = this._previewContext) {
779
+ let t = await this._previewRequest({
780
+ method: "POST",
781
+ url: this.modelColorUrl,
782
+ data: {
783
+ serviceName: this.serviceName,
784
+ dictCode: this.dictCode,
785
+ fetchAll: !0
786
+ },
787
+ timeout: 6e4
788
+ }, e, "color"), n = (t?.data ?? t)?.rows || [], r = this._ingestModelColorRows(n);
789
+ return this._colorAllReady = !0, console.log(`[ShpZzts] 服务配色全量命中: ${r}/${n.length}`), r;
790
+ }
791
+ _ensureServiceColorIndex(e = this._previewContext) {
792
+ return !this.isServiceColorEnabled() || this._colorAllReady ? Promise.resolve() : (this._colorAllPromise ||= this._fetchAllServiceColors(e).catch((e) => {
793
+ throw this._colorAllPromise = null, console.warn("[ShpZzts] 全量配色失败,回退按 id 查询:", e?.message || e), e;
794
+ }), this._colorAllPromise);
795
+ }
796
+ _cssToCesiumColor(e) {
797
+ if (!e) return null;
798
+ try {
799
+ return a.Color.fromCssColorString(e) || null;
800
+ } catch {
801
+ return null;
802
+ }
803
+ }
804
+ _applyServiceColorsInPlace() {
805
+ let e = this.lodPrimitives.get(this.currentLod);
806
+ if (!e || !this.isServiceColorEnabled()) return;
807
+ let t = this.opacity;
808
+ for (let n of e) {
809
+ let e = n.instanceFeatureIds;
810
+ if (!(!e || !e.length)) {
811
+ if (n.virtualLineColors) {
812
+ for (let r = 0; r < n.polylines.length; r++) {
813
+ let i = this._cssToCesiumColor(this.modelColorCache.get(e[r]));
814
+ if (!i) continue;
815
+ n.virtualLineColors[r] = i;
816
+ let o = n.polylines[r];
817
+ !q(o) && o.material?.uniforms && (o.material.uniforms.color = new a.Color(i.red, i.green, i.blue, t * this._normAlpha(i.alpha)));
818
+ }
819
+ continue;
820
+ }
821
+ if (n.pointPrimitives && n.pointPrimitives.length > 0) {
822
+ for (let r = 0; r < n.pointPrimitives.length; r++) {
823
+ let i = this._cssToCesiumColor(this.modelColorCache.get(e[r]));
824
+ if (!i) continue;
825
+ n.instanceColors && (n.instanceColors[r] = i), n.pointColors && (n.pointColors[r] = i), n.pointBaseColors && (n.pointBaseColors[r] = i);
826
+ let o = n.pointPrimitives[r];
827
+ o && !q(o) && (o.color = new a.Color(i.red, i.green, i.blue, t * this._normAlpha(i.alpha)));
828
+ }
829
+ continue;
830
+ }
831
+ if (!q(n.primitive)) for (let r = 0; r < n.instanceIds.length; r++) {
832
+ let i = this._cssToCesiumColor(this.modelColorCache.get(e[r]));
833
+ if (i) {
834
+ n.instanceColors[r] = i;
835
+ try {
836
+ let e = n.primitive.getGeometryInstanceAttributes(n.instanceIds[r]);
837
+ e?.color && (e.color = a.ColorGeometryInstanceAttribute.toValue(new a.Color(i.red, i.green, i.blue, t * this._normAlpha(i.alpha))));
838
+ } catch {}
839
+ }
840
+ }
841
+ }
842
+ }
843
+ this._lastViewData?.geometries && (this._lastViewData.colorMap = this._colorMapFromCache(this._lastViewData.geometries));
844
+ }
845
+ _getColorDrain() {
846
+ return this._colorDrain ||= U({
847
+ cache: this.modelColorCache,
848
+ postBatch: (e) => this._postModelColorBatch(e)
849
+ }), this._colorDrain;
850
+ }
851
+ async _postModelColorBatch(e) {
852
+ try {
853
+ let t = await this._previewRequest({
854
+ method: "POST",
855
+ url: this.modelColorUrl,
856
+ data: {
857
+ serviceName: this.serviceName,
858
+ dictCode: this.dictCode,
859
+ modelIds: e
860
+ },
861
+ timeout: 6e4
862
+ }, this._previewContext, "color"), 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));
863
+ return i.length > 0 && console.warn("[ShpZzts] 部分要素没有查询到颜色", {
864
+ serviceName: this.serviceName,
865
+ dictCode: this.dictCode,
866
+ requestCount: e.length,
867
+ hitCount: n.length,
868
+ missingCount: i.length,
869
+ missingSample: i.slice(0, 20)
870
+ }), n;
871
+ } catch (e) {
872
+ throw console.warn("[ShpZzts] 查询服务配色失败(本批回退默认色):", e), e;
873
+ }
874
+ }
875
+ async loadModelColorsByIds(e = []) {
876
+ if (!this.isServiceColorEnabled()) return /* @__PURE__ */ new Map();
877
+ let t = [...new Set(e.map((e) => String(e ?? "").trim()).filter((e) => e))];
878
+ if (t.length === 0) return /* @__PURE__ */ new Map();
879
+ this._colorAllReady || await this._getColorDrain().ensure(t);
880
+ let n = /* @__PURE__ */ new Map();
881
+ for (let e of t) {
882
+ let t = this.modelColorCache.get(e);
883
+ t && n.set(e, t);
884
+ }
885
+ return n;
886
+ }
887
+ _resolveFeatureColor(e, t) {
888
+ if (t && e.featureId !== void 0 && e.featureId !== null) {
889
+ let n = t.get(String(e.featureId));
890
+ if (n) try {
891
+ let e = a.Color.fromCssColorString(n);
892
+ if (e) return e;
893
+ } catch {}
894
+ }
895
+ return this._resolveColor();
896
+ }
897
+ _resolveOutlineColor() {
898
+ let e = this.outline?.color || "#FFC107";
899
+ try {
900
+ let t = a.Color.fromCssColorString(e);
901
+ if (t) return t;
902
+ } catch {
903
+ console.warn("[ShpZzts] 边线颜色解析失败,回退默认色:", e);
904
+ }
905
+ return a.Color.fromCssColorString("#FFC107");
906
+ }
907
+ _getScreenBounds() {
908
+ try {
909
+ let e = this.viewer?.scene?.canvas, t = this.viewer?.camera?.computeViewRectangle?.();
910
+ if (!e || !t) return null;
911
+ let n = {
912
+ west: a.Math.toDegrees(t.west),
913
+ south: a.Math.toDegrees(t.south),
914
+ east: a.Math.toDegrees(t.east),
915
+ north: a.Math.toDegrees(t.north)
916
+ }, r = this.displayRange ? ce(n, this.displayRange) : n;
917
+ return {
918
+ requestBounds: r,
919
+ region: [
920
+ r?.west,
921
+ r?.south,
922
+ 0,
923
+ r?.east,
924
+ r?.north,
925
+ 10
926
+ ],
927
+ width: e.clientWidth,
928
+ height: e.clientHeight
929
+ };
930
+ } catch {
931
+ return null;
932
+ }
933
+ }
934
+ async _waitForScreenBounds(e = 2e3) {
935
+ let t = performance.now();
936
+ for (; !this.destroyed;) {
937
+ if (this._getScreenBounds()) return !0;
938
+ if (performance.now() - t >= e) return !1;
939
+ await new Promise((e) => requestAnimationFrame(e));
940
+ }
941
+ return !1;
942
+ }
943
+ _updatePrimitiveAlpha(e, t) {
944
+ if (!e) return;
945
+ let n = this._normOpacity(t), r = (e) => n * this._normAlpha(e?.alpha);
946
+ for (let t of e) try {
947
+ if (q(t.primitive)) continue;
948
+ if (t.pointPrimitives && t.pointPrimitives.length > 0) {
949
+ for (let e = 0; e < t.pointPrimitives.length; e++) {
950
+ let n = t.pointPrimitives[e], i = t.pointBaseColors[e];
951
+ q(n) || !i || (n.color = new a.Color(i.red, i.green, i.blue, r(i)));
952
+ }
953
+ continue;
954
+ }
955
+ if (t.polylines && t.polylines.length > 0) {
956
+ let e = t.baseOutlineColor;
957
+ for (let [n, i] of t.polylines.entries()) {
958
+ if (q(i)) continue;
959
+ let o = i.material?.uniforms;
960
+ if (o?.color) {
961
+ let i = t.virtualLineColors?.[n] || e;
962
+ o.color = new a.Color(i.red, i.green, i.blue, r(i));
963
+ }
964
+ }
965
+ continue;
966
+ }
967
+ let e = t.instanceIds || [];
968
+ for (let n = 0; n < e.length; n++) {
969
+ let i = t.instanceColors[n], o = new a.Color(i.red, i.green, i.blue, r(i));
970
+ try {
971
+ let r = t.primitive.getGeometryInstanceAttributes(e[n]);
972
+ r?.color && (r.color = a.ColorGeometryInstanceAttribute.toValue(o));
973
+ } catch {}
974
+ }
975
+ } catch {}
976
+ }
977
+ _applyLayerOpacity() {
978
+ if (this.transitionAnimId !== null) {
979
+ cancelAnimationFrame(this.transitionAnimId), this.transitionAnimId = null;
980
+ for (let e of [...this.lodPrimitives.keys()]) e !== this.currentLod && this._destroyLodPrimitives(e);
981
+ }
982
+ let e = this.lodPrimitives.get(this.currentLod);
983
+ e && this._updatePrimitiveAlpha(e, this.opacity);
984
+ }
985
+ _destroyLodPrimitives(e) {
986
+ let t = this.lodPrimitives.get(e);
987
+ if (t) {
988
+ for (let e of t) q(e.primitive) || this.viewer.scene.primitives.remove(e.primitive);
989
+ this.lodPrimitives.delete(e);
990
+ }
991
+ }
992
+ _discardPrimitiveEntries(e) {
993
+ for (let t of e || []) {
994
+ let e = t?.primitive;
995
+ if (!q(e)) try {
996
+ this.viewer.scene.primitives.contains(e) ? this.viewer.scene.primitives.remove(e) : e.destroy?.();
997
+ } catch {}
998
+ }
999
+ }
1000
+ _swapFirstPaintGeoms(e, t, n) {
1001
+ return new Promise((r) => {
1002
+ try {
1003
+ let i = this._colorMapFromCache(e);
1004
+ if (this._lastViewData = {
1005
+ lodLevel: t,
1006
+ geometries: e,
1007
+ colorMap: i
1008
+ }, this.currentLod === -1 && !this.lodPrimitives.has(t)) {
1009
+ console.log(`[ShpZzts] 首屏流式上屏: ${e.length} 要素 / 批次 400`), this._renderBatched(e, t, 1, () => {
1010
+ if (typeof n == "function" && !n()) {
1011
+ r(!1);
1012
+ return;
1013
+ }
1014
+ this.currentLod = t, r(!0);
1015
+ }, i, null, { batchSize: 400 });
1016
+ return;
1017
+ }
1018
+ this._renderBatched(e, t, 1, null, i, null, {
1019
+ deferScene: !0,
1020
+ onComplete: (e) => {
1021
+ r(this._swapLodPrimitives(t, e, n));
1022
+ }
1023
+ });
1024
+ } catch (e) {
1025
+ console.warn("[ShpZzts] 首屏换挂失败:", e?.message || e), r(!1);
1026
+ }
1027
+ });
1028
+ }
1029
+ _swapLodPrimitives(e, t, n) {
1030
+ if (typeof n == "function" && !n()) return this._discardPrimitiveEntries(t), !1;
1031
+ this._destroyLodPrimitives(e);
1032
+ for (let e of t || []) q(e.primitive) || (this.viewer.scene.primitives.contains(e.primitive) || this.viewer.scene.primitives.add(e.primitive), e.primitive.show = !0);
1033
+ return this.lodPrimitives.set(e, t || []), this.currentLod = e, this._updatePrimitiveAlpha(t, this.opacity), !0;
1034
+ }
1035
+ _clearRenderedPrimitives() {
1036
+ for (let e of [...this.lodPrimitives.keys()]) this._destroyLodPrimitives(e);
1037
+ this.currentLod = -1, this._lastTileSetKey = "";
1038
+ }
1039
+ async _openTileDb() {
1040
+ if (!(!this.enableIndexedDb || typeof indexedDB > "u")) try {
1041
+ let e = new o(ie(this.id), 1);
1042
+ if (await e.openDatabase(P, "id"), this.destroyed) {
1043
+ e.closeDatabase();
1044
+ return;
1045
+ }
1046
+ this.gridDb = e;
1047
+ } catch (e) {
1048
+ console.warn("[ShpZzts] IndexedDB 打开失败,回退内存缓存:", e?.message || e), this.gridDb = null;
1049
+ }
1050
+ }
1051
+ async _readIdbBuffer(e) {
1052
+ if (!(!this.gridDb || this.destroyed)) try {
1053
+ let t = (await this.gridDb.getDataById(P, e))?.data;
1054
+ return t instanceof ArrayBuffer ? t : ArrayBuffer.isView(t) ? t.buffer.slice(t.byteOffset, t.byteOffset + t.byteLength) : void 0;
1055
+ } catch {
1056
+ return;
1057
+ }
1058
+ }
1059
+ _writeIdbBuffer(e, t) {
1060
+ !this.gridDb || this.destroyed || t instanceof ArrayBuffer && this.gridDb.updateData(P, {
1061
+ id: e,
1062
+ data: t
1063
+ }).catch(() => {});
1064
+ }
1065
+ _parseTileBuffer(e) {
1066
+ return m(e);
1067
+ }
1068
+ async _decodeTileAsync(e, t) {
1069
+ if (this.destroyed || t?.aborted) throw new DOMException("预览已取消", "AbortError");
1070
+ if (typeof Worker > "u") return this._parseTileBuffer(e);
1071
+ if (!this.geometryWorker) {
1072
+ let e = new u();
1073
+ e.onmessage = ({ data: e }) => {
1074
+ let t = this.geometryTasks.get(e.id);
1075
+ t && (this.geometryTasks.delete(e.id), t.cleanup(), e.error ? t.reject(Error(e.error)) : t.resolve(e.geometries));
1076
+ }, e.onerror = () => this._stopGeometryWorker(/* @__PURE__ */ Error("矢量预览后台处理失败")), this.geometryWorker = e;
1077
+ }
1078
+ return new Promise((n, r) => {
1079
+ let i = ++this.geometryTaskId, a = () => {
1080
+ this.geometryTasks.delete(i), o(), r(new DOMException("预览已取消", "AbortError"));
1081
+ }, o = () => t?.removeEventListener("abort", a);
1082
+ this.geometryTasks.set(i, {
1083
+ resolve: n,
1084
+ reject: r,
1085
+ cleanup: o
1086
+ }), t?.addEventListener("abort", a, { once: !0 });
1087
+ try {
1088
+ this.geometryWorker.postMessage({
1089
+ id: i,
1090
+ buffer: e
1091
+ });
1092
+ } catch (e) {
1093
+ this.geometryTasks.delete(i), o(), r(e);
1094
+ }
1095
+ });
1096
+ }
1097
+ _stopGeometryWorker(e) {
1098
+ this.geometryWorker?.terminate(), this.geometryWorker = null;
1099
+ for (let t of this.geometryTasks.values()) t.cleanup(), t.reject(e);
1100
+ this.geometryTasks.clear();
1101
+ }
1102
+ _rebuildForHiddenColors() {
1103
+ if (this.destroyed) return;
1104
+ let e = this._lastViewData;
1105
+ if (!e) {
1106
+ this.loadAndRender();
1107
+ return;
1108
+ }
1109
+ if (!e.geometries.length) return;
1110
+ if (this._hiddenRebuildPending) {
1111
+ this._hiddenRebuildQueued = !0;
1112
+ return;
1113
+ }
1114
+ this._hiddenRebuildPending = !0;
1115
+ let t = this.renderRequestToken;
1116
+ this._renderBatched(e.geometries, e.lodLevel, 1, null, e.colorMap, null, {
1117
+ deferScene: !0,
1118
+ isActive: () => !this.destroyed && t === this.renderRequestToken,
1119
+ onComplete: (n) => {
1120
+ if (this._hiddenRebuildPending = !1, this.destroyed || t !== this.renderRequestToken) {
1121
+ this._discardPrimitiveEntries(n), this._finishHiddenRebuild();
1122
+ return;
1123
+ }
1124
+ let r = this.currentLod;
1125
+ r !== -1 && this._destroyLodPrimitives(r);
1126
+ for (let e of n) q(e.primitive) || (this.viewer.scene.primitives.contains(e.primitive) || this.viewer.scene.primitives.add(e.primitive), e.primitive.show = !0);
1127
+ this.lodPrimitives.set(e.lodLevel, n), this.currentLod = e.lodLevel, this._updatePrimitiveAlpha(n, this.opacity), this._finishHiddenRebuild();
1128
+ }
1129
+ });
1130
+ }
1131
+ _finishHiddenRebuild() {
1132
+ this._hiddenRebuildQueued && (this._hiddenRebuildQueued = !1, this._rebuildForHiddenColors());
1133
+ }
1134
+ _crossFadeLod(e, t, n) {
1135
+ this.transitionAnimId !== null && (cancelAnimationFrame(this.transitionAnimId), this.transitionAnimId = null);
1136
+ let r = this.lodPrimitives.get(e) ?? void 0, i = this.lodPrimitives.get(t);
1137
+ if (!i) return;
1138
+ let a = this.opacity, o = () => {
1139
+ if (r) {
1140
+ for (let e of r) q(e.primitive) || this.viewer.scene.primitives.remove(e.primitive);
1141
+ this.lodPrimitives.delete(e);
1142
+ }
1143
+ this.transitionAnimId = null;
1144
+ }, s = () => {
1145
+ try {
1146
+ this._updatePrimitiveAlpha(i, a);
1147
+ } catch {}
1148
+ o();
1149
+ };
1150
+ try {
1151
+ this._updatePrimitiveAlpha(i, 0);
1152
+ } catch (e) {
1153
+ console.warn("[ShpZzts] 交叉淡化初始化失败,直接切新层:", e?.message || e), s();
1154
+ return;
1155
+ }
1156
+ let c = performance.now(), l = this.transitionDuration, u = () => {
1157
+ if (this.destroyed || typeof n == "function" && !n()) {
1158
+ this.transitionAnimId = null;
1159
+ return;
1160
+ }
1161
+ try {
1162
+ let e = Math.min((performance.now() - c) / l, 1);
1163
+ this._updatePrimitiveAlpha(i, e * a), r && this._updatePrimitiveAlpha(r, (1 - e) * a), e < 1 ? this.transitionAnimId = requestAnimationFrame(u) : o();
1164
+ } catch (e) {
1165
+ console.warn("[ShpZzts] 交叉淡化中断,直接切新层:", e?.message || e), s();
1166
+ }
1167
+ };
1168
+ this.transitionAnimId = requestAnimationFrame(u);
1169
+ }
1170
+ _renderBatched(e, t, n, r, i, o, s = {}) {
1171
+ let c = o || [], l = s.deferScene === !0, u = Number(s.batchSize) > 0 ? Number(s.batchSize) : this.batchSize, f = () => {
1172
+ if (l) {
1173
+ typeof s.onComplete == "function" && s.onComplete(c);
1174
+ return;
1175
+ }
1176
+ this.lodPrimitives.set(t, c), r && requestAnimationFrame(() => r());
1177
+ };
1178
+ this.hiddenColors?.size && (e = e.filter((e) => {
1179
+ let t = this._resolveFeatureColor(e, i);
1180
+ return !this.hiddenColors.has(G(t));
1181
+ }));
1182
+ let m = [], g = [], _ = [];
1183
+ for (let t of e) {
1184
+ let e = this.virtualLineStyle ? p(t) : [];
1185
+ e.length ? g.push({
1186
+ geom: t,
1187
+ paths: e
1188
+ }) : t.geometryKind === 2 && (!t.indices || t.indexCount === 0) ? m.push(t) : _.push(t);
1189
+ }
1190
+ if (g.length) {
1191
+ let e = new a.PolylineCollection(), t = [], r = [], o = [], s = [];
1192
+ for (let { geom: c, paths: l } of g) {
1193
+ let u = this._resolveFeatureColor(c, i);
1194
+ for (let i of l) {
1195
+ let l = this.globalInstanceId++, d = new a.Color(u.red, u.green, u.blue, this._normOpacity(n) * this.opacity * this._normAlpha(u.alpha)), f = this.virtualLineStyle.type === "dashed" ? a.Material.fromType("PolylineDash", {
1196
+ color: d,
1197
+ gapColor: a.Color.TRANSPARENT,
1198
+ dashLength: 16
1199
+ }) : a.Material.fromType("Color", { color: d });
1200
+ t.push(e.add({
1201
+ positions: i.map((e) => a.Cartesian3.fromArray(e)),
1202
+ width: this.virtualLineStyle.width,
1203
+ material: f,
1204
+ id: l
1205
+ })), r.push(u), o.push(l), s.push(String(c.featureId ?? ""));
1206
+ }
1207
+ }
1208
+ l || this.viewer.scene.primitives.add(e), c.push({
1209
+ primitive: e,
1210
+ polylines: t,
1211
+ virtualLineColors: r,
1212
+ baseOutlineColor: r[0],
1213
+ instanceIds: o,
1214
+ instanceFeatureIds: s
1215
+ });
1216
+ }
1217
+ if (m.length > 0) {
1218
+ let e = new a.PointPrimitiveCollection(), r = [], o = [], s = [], u = [], d = [], f = this._normOpacity(n) * this.opacity;
1219
+ for (let t of m) {
1220
+ let n = this.globalInstanceId++, c = this._resolveFeatureColor(t, i), l = String(t.featureId ?? "");
1221
+ s.push(n), u.push(c);
1222
+ let p = new a.Color(c.red, c.green, c.blue, f * this._normAlpha(c.alpha));
1223
+ for (let i = 0; i < t.vertexCount; i++) r.push(e.add({
1224
+ position: a.Cartesian3.fromArray(t.positions, i * 3),
1225
+ pixelSize: this.pointSize,
1226
+ ...this.virtualPointStyle ? {
1227
+ outlineColor: a.Color.fromCssColorString(this.virtualPointStyle.outlineColor),
1228
+ outlineWidth: this.virtualPointStyle.outlineWidth
1229
+ } : {},
1230
+ color: p,
1231
+ id: n
1232
+ })), o.push(c), d.push(l);
1233
+ }
1234
+ l || this.viewer.scene.primitives.add(e), c.push({
1235
+ primitive: e,
1236
+ instanceIds: s,
1237
+ instanceColors: u,
1238
+ instanceFeatureIds: d,
1239
+ pointPrimitives: r,
1240
+ pointColors: o,
1241
+ ...this.virtualPointStyle ? { pointBaseColors: o } : {}
1242
+ }), console.log(`[ShpZzts] LOD ${t} 原生点渲染完成: ${m.length} 要素 / ${r.length} 点`);
1243
+ }
1244
+ let v = h(_, u), y = 0, b = (e) => {
1245
+ if (this.destroyed || s.isActive && !s.isActive()) {
1246
+ this._discardPrimitiveEntries(c), f();
1247
+ return;
1248
+ }
1249
+ try {
1250
+ if (e >= v.length) {
1251
+ f();
1252
+ return;
1253
+ }
1254
+ let r = v[e], o = c.length, u = [], p = [];
1255
+ for (let e of r) e.geometryKind === 2 && e.indexCount === 0 ? u.push(e) : p.push(e);
1256
+ let m = 0, h = [], g = [], _ = [], x = [];
1257
+ for (let e of p) {
1258
+ let t = this.globalInstanceId++;
1259
+ h.push(t), _.push(String(e.featureId ?? ""));
1260
+ let r = this._resolveFeatureColor(e, i);
1261
+ g.push(r);
1262
+ let o = new a.Color(r.red, r.green, r.blue, this._normOpacity(n) * this.opacity * this._normAlpha(r.alpha));
1263
+ try {
1264
+ x.push(new a.GeometryInstance({
1265
+ geometry: new a.Geometry({
1266
+ attributes: { position: new a.GeometryAttribute({
1267
+ componentDatatype: a.ComponentDatatype.DOUBLE,
1268
+ componentsPerAttribute: 3,
1269
+ values: e.positions,
1270
+ normalize: !1
1271
+ }) },
1272
+ indices: e.indices,
1273
+ primitiveType: a.PrimitiveType.TRIANGLES,
1274
+ boundingSphere: a.BoundingSphere.fromVertices(e.positions)
1275
+ }),
1276
+ id: t,
1277
+ attributes: { color: a.ColorGeometryInstanceAttribute.fromColor(o) }
1278
+ }));
1279
+ } catch (e) {
1280
+ console.error(`[ShpZzts] Geometry 创建失败 instanceId=${t}`, e), h.pop(), g.pop(), _.pop();
1281
+ }
1282
+ }
1283
+ if (x.length > 0) {
1284
+ let e = new a.Primitive({
1285
+ geometryInstances: x,
1286
+ appearance: new a.PerInstanceColorAppearance({
1287
+ flat: !0,
1288
+ translucent: !0
1289
+ }),
1290
+ asynchronous: !1,
1291
+ compressVertices: !1,
1292
+ releaseGeometryInstances: !0
1293
+ });
1294
+ l || this.viewer.scene.primitives.add(e), c.push({
1295
+ primitive: e,
1296
+ instanceIds: h,
1297
+ instanceColors: g,
1298
+ instanceFeatureIds: _
1299
+ }), m++;
1300
+ }
1301
+ if (this.outline) {
1302
+ let e = new a.PolylineCollection(), r = this._resolveOutlineColor(), i = l ? 0 : this._normOpacity(n) * this.opacity * this._normAlpha(r.alpha), o = new a.Color(r.red, r.green, r.blue, i), s = [], u = new a.Cartesian3(), f = new a.Cartesian3();
1303
+ for (let t of p) {
1304
+ if (t.geometryKind !== 0 || !t.indices || t.indexCount === 0) continue;
1305
+ let n = t.boundaryRings ??= d(t.indices, t.vertexCount);
1306
+ for (let r of n) {
1307
+ let n = Array(r.length);
1308
+ for (let e = 0; e < r.length; e++) {
1309
+ let i = a.Cartesian3.fromArray(t.positions, r[e] * 3);
1310
+ a.Cartesian3.normalize(i, u), a.Cartesian3.multiplyByScalar(u, this.outlineHeightOffset, f), n[e] = a.Cartesian3.add(i, f, new a.Cartesian3());
1311
+ }
1312
+ s.push(e.add({
1313
+ positions: n,
1314
+ width: this.outline.width,
1315
+ material: a.Material.fromType("Color", { color: o })
1316
+ }));
1317
+ }
1318
+ }
1319
+ s.length > 0 ? (l || this.viewer.scene.primitives.add(e), c.push({
1320
+ primitive: e,
1321
+ polylines: s,
1322
+ baseOutlineColor: r
1323
+ }), m++, console.log(`[ShpZzts] LOD ${t} 边线渲染完成: ${s.length} 条`)) : e.destroy?.();
1324
+ }
1325
+ if (u.length > 0) {
1326
+ let e = new a.PointPrimitiveCollection(), t = [], r = [], o = [], s = this._normOpacity(n) * this.opacity;
1327
+ for (let n of u) {
1328
+ if (!n.positions || n.positions.length < 3) continue;
1329
+ let c = this._resolveFeatureColor(n, i);
1330
+ r.push(c), o.push(String(n.featureId ?? ""));
1331
+ let l = e.add({
1332
+ position: new a.Cartesian3(n.positions[0], n.positions[1], n.positions[2]),
1333
+ color: new a.Color(c.red, c.green, c.blue, s * this._normAlpha(c.alpha)),
1334
+ pixelSize: this.pointSize,
1335
+ disableDepthTestDistance: Infinity
1336
+ });
1337
+ t.push(l);
1338
+ }
1339
+ t.length > 0 ? (l || this.viewer.scene.primitives.add(e), c.push({
1340
+ primitive: e,
1341
+ pointPrimitives: t,
1342
+ pointBaseColors: r,
1343
+ instanceFeatureIds: o
1344
+ }), m++) : e.destroy?.();
1345
+ }
1346
+ if (m === 0) {
1347
+ y++, y < v.length ? requestAnimationFrame(() => b(e + 1)) : f();
1348
+ return;
1349
+ }
1350
+ y++;
1351
+ let S = c.slice(o);
1352
+ if (l) for (let e of S) e.primitive.show = !!e.polylines, this.viewer.scene.primitives.add(e.primitive);
1353
+ let C = () => {
1354
+ if (this.destroyed || s.isActive && !s.isActive()) {
1355
+ this._discardPrimitiveEntries(c), f();
1356
+ return;
1357
+ }
1358
+ if (S.some((e) => e.primitive.ready === !1)) {
1359
+ this.viewer.scene.requestRender(), requestAnimationFrame(C);
1360
+ return;
1361
+ }
1362
+ y < v.length ? b(e + 1) : f();
1363
+ };
1364
+ this.viewer.scene.requestRender(), requestAnimationFrame(C);
1365
+ } catch (e) {
1366
+ if (this._discardPrimitiveEntries(c), s.onError) s.onError(e);
1367
+ else throw e;
1368
+ }
1369
+ };
1370
+ return b(0), c;
1371
+ }
1372
+ async _getVectorTileData(e, t, n, r = this._previewContext, i = "tile") {
1373
+ let a = await this._previewRequest({
1374
+ method: "GET",
1375
+ url: this.tileUrl,
1376
+ headers: { Accept: "application/octet-stream" },
1377
+ params: {
1378
+ layerId: this.id,
1379
+ geosot: e,
1380
+ level: t,
1381
+ ...r?.bounded ? { bounded: 1 } : {}
1382
+ },
1383
+ responseType: "arraybuffer",
1384
+ timeout: 6e4,
1385
+ signal: n
1386
+ }, r, i), o = a?.data ?? a;
1387
+ if (!(o instanceof ArrayBuffer)) throw Error("Response data is empty");
1388
+ if (r) {
1389
+ if ((r.rawBytes || 0) + o.byteLength > 268435456) {
1390
+ let e = /* @__PURE__ */ Error("本轮预览数据量达到上限");
1391
+ throw e.code = "PREVIEW_RESOURCE_LIMIT", e;
1392
+ }
1393
+ r.rawBytes = (r.rawBytes || 0) + o.byteLength;
1394
+ }
1395
+ return {
1396
+ geosot: e,
1397
+ data: o
1398
+ };
1399
+ }
1400
+ async _fetchTileGeometries(e, t, n, r = this._previewContext, i = "tile") {
1401
+ let a = r?.bounded ? "bounded-v2|" : "", o = a + ae(t, e), s = L(this.tileCache, o);
1402
+ if (s) return s;
1403
+ let c = a + oe(t, e), l = await this._readIdbBuffer(c);
1404
+ if (n?.aborted) {
1405
+ let e = /* @__PURE__ */ Error("Aborted");
1406
+ throw e.name = "AbortError", e;
1407
+ }
1408
+ if (l !== void 0) try {
1409
+ return this._rememberTileGeometries(o, await this._decodeTileAsync(l, n));
1410
+ } catch (e) {
1411
+ if (e.name === "AbortError") throw e;
1412
+ try {
1413
+ await this.gridDb?.deleteData(P, c);
1414
+ } catch {}
1415
+ }
1416
+ let { data: u } = await this._getVectorTileData(e, t, n, r, i);
1417
+ if (n?.aborted) {
1418
+ let e = /* @__PURE__ */ Error("Aborted");
1419
+ throw e.name = "AbortError", e;
1420
+ }
1421
+ if (!B(u, !1)) throw Error("Response data is empty");
1422
+ let d = await this._decodeTileAsync(u, n);
1423
+ if (u.byteLength > 4 && d.length === 0) throw Error("矢量瓦片内容无效,未写入空瓦片缓存");
1424
+ return this._rememberTileGeometries(o, d), this._writeIdbBuffer(c, u), d;
1425
+ }
1426
+ _rememberTileGeometries(e, t) {
1427
+ this.tileCache.delete(e), R(this.tileCache, e, t, X);
1428
+ let n = (e) => e.positions.byteLength + e.indices.byteLength + (e.boundaryRings || []).reduce((e, t) => e + (t.byteLength ?? t.length * 8), 0), r = 0;
1429
+ for (let e of this.tileCache.values()) for (let t of e) r += n(t);
1430
+ for (; r > 128 * 1024 * 1024 && this.tileCache.size > 0;) {
1431
+ let e = this.tileCache.keys().next().value;
1432
+ for (let t of this.tileCache.get(e)) r -= n(t);
1433
+ this.tileCache.delete(e);
1434
+ }
1435
+ return t;
1436
+ }
1437
+ async _getLayerGeometries(e, t) {
1438
+ let n = L(this.bulkCache, e);
1439
+ if (n) return n;
1440
+ let r = se(e), i = await this._readIdbBuffer(r);
1441
+ if (t?.aborted) {
1442
+ let e = /* @__PURE__ */ Error("Aborted");
1443
+ throw e.name = "AbortError", e;
1444
+ }
1445
+ if (z(i)) {
1446
+ let n = await this._decodeTileAsync(i, t);
1447
+ if (n.length > 0) return R(this.bulkCache, e, n, Z);
1448
+ }
1449
+ let a = await this._previewRequest({
1450
+ method: "GET",
1451
+ url: this.layerDataUrl,
1452
+ headers: { Accept: "application/octet-stream" },
1453
+ params: {
1454
+ layerId: this.id,
1455
+ level: e
1456
+ },
1457
+ responseType: "arraybuffer",
1458
+ timeout: 12e4,
1459
+ signal: t
1460
+ }, this._previewContext, "tile"), o = a?.data ?? a, s = await this._decodeTileAsync(o, t);
1461
+ return s.length > 0 && (R(this.bulkCache, e, s, Z), o instanceof ArrayBuffer && this._writeIdbBuffer(r, o)), s;
1462
+ }
1463
+ async _commitPreviewRecords(e, t, n, r) {
1464
+ if (S(t), !r()) return !1;
1465
+ let i = this._colorMapFromCache(t);
1466
+ return new Promise((a, o) => {
1467
+ try {
1468
+ this._renderBatched(t, n, 1, null, i, null, {
1469
+ deferScene: !0,
1470
+ isActive: r,
1471
+ onError: o,
1472
+ onComplete: (o) => {
1473
+ if (!this._swapLodPrimitives(n, o, r)) return a(!1);
1474
+ for (let e of [...this.lodPrimitives.keys()]) e !== n && this._destroyLodPrimitives(e);
1475
+ this._lastTileRecords = e, this._lastViewData = {
1476
+ lodLevel: n,
1477
+ geometries: t,
1478
+ colorMap: i
1479
+ }, this._updatePrimitiveAlpha(o, this.opacity), a(!0);
1480
+ }
1481
+ });
1482
+ } catch (e) {
1483
+ o(e);
1484
+ }
1485
+ });
1486
+ }
1487
+ loadAndRender() {
1488
+ let e = this._getScreenBounds();
1489
+ if (!e || this.destroyed) return Promise.resolve();
1490
+ let t = JSON.stringify([
1491
+ e.region,
1492
+ e.width,
1493
+ e.height,
1494
+ this.id,
1495
+ this.calTilesUrl,
1496
+ this.tileUrl,
1497
+ this.dictCode,
1498
+ this.serviceName,
1499
+ this.modelColorUrl
1500
+ ]);
1501
+ if (this._activePreviewLoad?.key === t) return this._activePreviewLoad.promise;
1502
+ let n = {
1503
+ key: t,
1504
+ promise: null
1505
+ };
1506
+ return this._activePreviewLoad = n, n.promise = this._loadAndRender(e).finally(() => {
1507
+ this._activePreviewLoad === n && (this._activePreviewLoad = null);
1508
+ }), n.promise;
1509
+ }
1510
+ async _loadAndRender(e) {
1511
+ let t = ++this.renderRequestToken;
1512
+ this._previewContext?.budget.cancel("视野已变化"), this.activeAbort?.abort(), this._stopGeometryWorker(new DOMException("视野已变化", "AbortError"));
1513
+ let n = new AbortController(), r = {
1514
+ budget: j(),
1515
+ signal: n.signal,
1516
+ rawBytes: 0,
1517
+ bounded: !1
1518
+ };
1519
+ this._previewContext = r, this.activeAbort = n;
1520
+ let i = () => t === this.renderRequestToken && !this.destroyed, a = this._lastTileRecords || (this._lastViewData ? [{
1521
+ tile: {},
1522
+ geometries: this._lastViewData.geometries
1523
+ }] : []), o = this.currentLod === -1, s = null, c = null;
1524
+ this._setPreviewStatus("LOADING", o ? "正在加载预览…" : "", r);
1525
+ let l = () => {
1526
+ this._lastViewData = null, this._lastTileRecords = [], this._clearRenderedPrimitives(), this._setPreviewStatus("NO_DATA", r);
1527
+ };
1528
+ if (this.displayRange && !e.requestBounds) {
1529
+ l(), this.activeAbort = null;
1530
+ return;
1531
+ }
1532
+ try {
1533
+ this.transitionAnimId !== null && (cancelAnimationFrame(this.transitionAnimId), this.transitionAnimId = null);
1534
+ let t = await this._previewRequest({
1535
+ method: "GET",
1536
+ url: this.calTilesUrl,
1537
+ params: {
1538
+ region: e.region.join(","),
1539
+ height: e.height,
1540
+ width: e.width,
1541
+ planVersion: 2,
1542
+ maxTiles: 15,
1543
+ layerId: this.id
1544
+ },
1545
+ timeout: 15e3
1546
+ }, r, "plan");
1547
+ if (!i()) return;
1548
+ let u = t?.data ?? t ?? {}, d = re(u);
1549
+ if (d === "no-data") {
1550
+ l();
1551
+ return;
1552
+ }
1553
+ if (d !== "ready") {
1554
+ this._setPreviewStatus("DEFERRED", "当前范围暂时无法加载,请放大或稍后重试", r);
1555
+ return;
1556
+ }
1557
+ let { tiles: f, lodLevel: p } = u;
1558
+ if (console.log("[ShpZzts] 视野计划:", JSON.stringify({
1559
+ layerId: this.id,
1560
+ region: e.region,
1561
+ tiles: f.length,
1562
+ lodLevel: p,
1563
+ coverageLevel: u.coverageLevel
1564
+ })), ![
1565
+ 12,
1566
+ 13,
1567
+ 15,
1568
+ 16,
1569
+ 17
1570
+ ].includes(Number(p)) || f.length > 15 || f.some((e) => typeof e.geoSot != "string" || !/^G[0-3]{1,32}$/.test(e.geoSot.replace(/[-.]/g, ""))) || new Set(f.map((e) => e.geoSot)).size !== f.length) {
1571
+ this._setPreviewStatus("LIMITED", "当前范围超出预览限制,请放大查看", r);
1572
+ return;
1573
+ }
1574
+ r.bounded = Number(u.planVersion) === 2;
1575
+ let m = (r.bounded ? "bounded-v2|" : "") + F(p, f);
1576
+ if (I({
1577
+ tileSetKey: m,
1578
+ lastTileSetKey: this._lastTileSetKey,
1579
+ currentLod: this.currentLod,
1580
+ lodLevel: p,
1581
+ hasPrimitives: this.lodPrimitives.has(p)
1582
+ })) {
1583
+ this._setPreviewStatus("READY", "", r);
1584
+ return;
1585
+ }
1586
+ let h = this._ensureServiceColorIndex(r).then(() => !0, () => !1), g = [], _ = /* @__PURE__ */ new Map(), v = !1;
1587
+ o && (s = H(async () => {
1588
+ if (!i() || v) return;
1589
+ let e = b(g, [], []);
1590
+ if (e.geometries.length) try {
1591
+ v = await this._commitPreviewRecords(e.records, e.geometries, p, i);
1592
+ } catch (e) {
1593
+ c = e;
1594
+ }
1595
+ }));
1596
+ let y = async (e, t) => {
1597
+ try {
1598
+ let a = await this._fetchTileGeometries(e.geoSot, p, n.signal, r, t);
1599
+ if (!i()) return;
1600
+ g.push({
1601
+ tile: e,
1602
+ geometries: a
1603
+ }), _.delete(e.geoSot), s?.schedule(g.slice());
1604
+ } catch (t) {
1605
+ i() && (_.set(e.geoSot, {
1606
+ tile: e,
1607
+ error: t
1608
+ }), console.warn("[ShpZzts] 瓦片加载失败:", e.geoSot, t?.response?.status, t?.code, t?.message));
1609
+ }
1610
+ };
1611
+ if (await le(f, 4, (e) => y(e, "tile")), !i()) return;
1612
+ r.budget.releaseReserved("tile");
1613
+ for (let e of [..._.values()]) {
1614
+ if (!i() || r.budget.available("retry") < 1) break;
1615
+ (e.error?.response?.data?.code || e.error?.code) === "PREVIEW_RESOURCE_LIMIT" || e.error?.response?.status === 413 || await y(e.tile, "retry");
1616
+ }
1617
+ if (s && await s.whenIdle(), !i()) return;
1618
+ let x = b(g, [..._.values()].map((e) => e.tile), a);
1619
+ if (_.size === 0 && x.geometries.length === 0) {
1620
+ l();
1621
+ return;
1622
+ }
1623
+ if (x.geometries.length) {
1624
+ if (c) throw c;
1625
+ await this._commitPreviewRecords(x.records, x.geometries, p, i);
1626
+ }
1627
+ if (!i()) return;
1628
+ if (_.size) {
1629
+ let e = [..._.values()].some(({ error: e }) => e?.code === "PREVIEW_RESOURCE_LIMIT" || e?.response?.status === 413);
1630
+ this._setPreviewStatus(e ? "LIMITED" : "PARTIAL", e ? "当前范围数据量较大,已保留已加载数据,请放大查看" : "部分数据加载失败,已保留已加载数据,请稍后重试", r);
1631
+ } else this._lastTileSetKey = m, this._setPreviewStatus(u.status === "DEGRADED" ? "DEGRADED" : "READY", "", r);
1632
+ if (await h, !i()) return;
1633
+ if (this.isServiceColorEnabled() && !this._colorAllReady && r.budget.available("color") > 0) try {
1634
+ await this.loadModelColorsByIds(this._collectFeatureIds(x.geometries));
1635
+ } catch {}
1636
+ i() && this._applyServiceColorsInPlace();
1637
+ } catch (e) {
1638
+ if (!i() || n.signal.aborted) return;
1639
+ this._setPreviewStatus(e?.code === "PREVIEW_RESOURCE_LIMIT" ? "LIMITED" : "ERROR", e?.code === "PREVIEW_RESOURCE_LIMIT" ? "当前范围数据量较大,已保留已加载数据,请放大查看" : "预览加载失败,已保留已加载数据,请稍后重试", r), console.warn("[ShpZzts] 预览未完成:", e?.message || e);
1640
+ } finally {
1641
+ s && await s.whenIdle(), this.activeAbort === n && (this.activeAbort = null), i() && (this.previewStatus.requests = r.budget.used);
1642
+ }
1643
+ }
1644
+ _onCameraMoveEnd() {
1645
+ this.debounceTimer && clearTimeout(this.debounceTimer), this.debounceTimer = setTimeout(() => {
1646
+ this.destroyed || (console.log("[ShpZzts] 地图移动/缩放结束,重新加载瓦片"), this.loadAndRender());
1647
+ }, 300);
1648
+ }
1649
+ _setupMoveHandler() {
1650
+ this._moveHandler = () => this._onCameraMoveEnd(), this.viewer.camera.moveEnd.addEventListener(this._moveHandler);
1651
+ }
1652
+ _teardownMoveHandler() {
1653
+ if (this._moveHandler) {
1654
+ try {
1655
+ this.viewer.camera.moveEnd.removeEventListener(this._moveHandler);
1656
+ } catch {}
1657
+ this._moveHandler = null;
1658
+ }
1659
+ }
1660
+ async init() {
1661
+ this.destroyed || (this._setupMoveHandler(), await this._openTileDb(), await this._waitForScreenBounds(), this.destroyed || this.loadAndRender(), console.log(`[ShpZzts] 图层 ${this.id} 初始化完成`));
1662
+ }
1663
+ remove() {
1664
+ if (this.destroyed = !0, this._stopGeometryWorker(new DOMException("图层已移除", "AbortError")), this._previewContext?.budget.cancel("图层已移除"), this._statusElement?.remove(), this._statusElement = null, this.renderRequestToken += 1, this._lastViewData = null, this._lastTileSetKey = "", this._hiddenRebuildQueued = !1, this.activeAbort) {
1665
+ try {
1666
+ this.activeAbort.abort();
1667
+ } catch {}
1668
+ this.activeAbort = null;
1669
+ }
1670
+ 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;
1671
+ for (let e of this.lodPrimitives.keys()) this._destroyLodPrimitives(e);
1672
+ try {
1673
+ this.gridDb?.closeDatabase();
1674
+ } catch {}
1675
+ this.gridDb = null, console.log(`[ShpZzts] 图层 ${this.id} 已移除`);
1676
+ }
1677
+ updateOptions(e = {}) {
1678
+ let t = Object.hasOwn(e, "virtualLineStyle") ? e.virtualLineStyle || null : this.virtualLineStyle, n = Object.hasOwn(e, "virtualPointStyle") ? e.virtualPointStyle || null : this.virtualPointStyle;
1679
+ (JSON.stringify(t) !== JSON.stringify(this.virtualLineStyle) || JSON.stringify(n) !== JSON.stringify(this.virtualPointStyle)) && (this.virtualLineStyle = t, this.virtualPointStyle = n, this._clearRenderedPrimitives(), this.loadAndRender());
1680
+ let r = !1;
1681
+ if (e.opacity !== void 0) {
1682
+ let t = this._normOpacity(e.opacity);
1683
+ t !== this.opacity && (this.opacity = t, r = !0);
1684
+ }
1685
+ 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) {
1686
+ let t = Number(e.pointSize);
1687
+ if (Number.isFinite(t) && t > 0 && t !== this.pointSize) {
1688
+ this.pointSize = t;
1689
+ let e = this.lodPrimitives.get(this.currentLod);
1690
+ if (e) {
1691
+ for (let n of e) if (n.pointPrimitives) for (let e of n.pointPrimitives) q(e) || (e.pixelSize = t);
1692
+ }
1693
+ }
1694
+ }
1695
+ if (e.displayRange !== void 0 && (this.displayRange = K(e.displayRange)), e.outline !== void 0) {
1696
+ let t = J(e.outline);
1697
+ if (!Y(this.outline, t)) {
1698
+ let e = !!this.outline != !!t;
1699
+ if (this.outline = t, e) this._clearRenderedPrimitives(), this.loadAndRender();
1700
+ else {
1701
+ let e = this.lodPrimitives.get(this.currentLod);
1702
+ if (e) {
1703
+ let t = this._resolveOutlineColor();
1704
+ for (let n of e) if (n.polylines) for (let e of n.polylines) {
1705
+ if (q(e)) continue;
1706
+ e.width = this.outline.width;
1707
+ let n = e.material?.uniforms;
1708
+ n?.color && (n.color = new a.Color(t.red, t.green, t.blue, this.opacity * this._normAlpha(t.alpha)));
1709
+ }
1710
+ }
1711
+ }
1712
+ }
1713
+ }
1714
+ let i = !1;
1715
+ if (e.dictCode !== void 0 && e.dictCode !== this.dictCode && (this.dictCode = e.dictCode || "", i = !0), e.serviceName !== void 0 && e.serviceName !== this.serviceName && (this.serviceName = e.serviceName || "", i = !0), e.enableServiceColor !== void 0 && !!e.enableServiceColor !== this.enableServiceColor && (this.enableServiceColor = !!e.enableServiceColor, i = !0), e.modelColorUrl !== void 0 && e.modelColorUrl !== this.modelColorUrl && (this.modelColorUrl = e.modelColorUrl || "/v1/zzts/style/render/modelColors", i = !0), i && this._resetServiceColorIndex(), e.hiddenColors !== void 0) {
1716
+ let t = new Set((e.hiddenColors || []).map(W).filter(Boolean)), n = t.size !== this.hiddenColors.size || [...t].some((e) => !this.hiddenColors.has(e));
1717
+ this.hiddenColors = t, n && this._rebuildForHiddenColors();
1718
+ }
1719
+ r && this._applyLayerOpacity(), console.log(`[ShpZzts] 图层 ${this.id} 配置已更新`, {
1720
+ opacity: this.opacity,
1721
+ stackIndex: this.stackIndex
1722
+ });
1723
+ }
1724
+ };
1725
+ function de(e, t) {
1726
+ return !e && !t ? !0 : !e || !t ? !1 : e.west === t.west && e.south === t.south && e.east === t.east && e.north === t.north;
1727
+ }
1728
+ function fe(e, t = {}) {
1729
+ if (!e || e.destroyed) return !1;
1730
+ let n = t.layerId || t.id;
1731
+ 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 && !Y(J(t.outline), e.outline) || t.displayRange !== void 0 && !de(e.displayRange, K(t.displayRange)));
1732
+ }
1733
+ var Q = new class {
1734
+ constructor() {
1735
+ this.layers = /* @__PURE__ */ new Map();
1736
+ }
1737
+ async createLayer(e, t = {}) {
1738
+ let n = t?.layerId || t?.id;
1739
+ if (!n) return console.error("[ShpZzts] 创建图层失败:缺少 layerId"), null;
1740
+ this.layers.has(n) && (console.warn(`[ShpZzts] 图层 ${n} 已存在,移除旧图层后重建`), this.removeLayer(n));
1741
+ let r = new ue(e, t);
1742
+ this.layers.set(n, r);
1743
+ try {
1744
+ return r.initPromise = r.init(), await r.initPromise, r.destroyed || this.layers.get(n) !== r ? null : r;
1745
+ } catch (e) {
1746
+ throw this.layers.get(n) === r && this.layers.delete(n), r.destroyed || r.remove(), e;
1747
+ }
1748
+ }
1749
+ removeLayer(e) {
1750
+ let t = this.layers.get(e);
1751
+ t && (t.remove(), this.layers.delete(e), console.log(`[ShpZzts] 图层 ${e} 已移除`));
1752
+ }
1753
+ getLayer(e) {
1754
+ return this.layers.get(e);
1755
+ }
1756
+ removeAllLayers() {
1757
+ this.layers.forEach((e) => e.remove()), this.layers.clear();
1758
+ }
1759
+ }(), pe = async (e, t) => Q.createLayer(e, t), me = (e) => {
1760
+ Q.removeLayer(e);
1761
+ }, $ = (e) => Q.getLayer(e), he = {
1762
+ __name: "index",
1763
+ props: {
1764
+ config: {
1765
+ type: Object,
1766
+ default: () => ({})
1767
+ },
1768
+ stackIndex: {
1769
+ type: Number,
1770
+ default: -1
1771
+ },
1772
+ subStackIndex: {
1773
+ type: Number,
1774
+ default: 0
1775
+ },
1776
+ groupKey: {
1777
+ type: String,
1778
+ default: ""
1779
+ }
1780
+ },
1781
+ setup(a) {
1782
+ let o = t("cesiumViewer"), s = a, c = {
1783
+ layerId: "",
1784
+ calTilesUrl: "/v1/zzts/layer/shp/calTiles",
1785
+ tileUrl: "/v1/zzts/layer/3d/getVectorTile",
1786
+ layerDataUrl: "/v1/zzts/layer/3d/getVectorLayerData",
1787
+ displayRange: null,
1788
+ opacity: 1,
1789
+ batchSize: 2e3,
1790
+ transitionDuration: 50,
1791
+ hiddenColors: []
1792
+ }, l = e(() => ({
1793
+ ...c,
1794
+ ...s.config
1795
+ })), u = "", d = 0, f = !1, p = null, m = () => {
1796
+ p && $(p.id) === p && me(p.id), p = null;
1797
+ };
1798
+ function h(e) {
1799
+ return {
1800
+ layerId: e.layerId,
1801
+ calTilesUrl: e.calTilesUrl,
1802
+ tileUrl: e.tileUrl,
1803
+ layerDataUrl: e.layerDataUrl,
1804
+ displayRange: e.displayRange,
1805
+ opacity: e.opacity,
1806
+ batchSize: e.batchSize,
1807
+ transitionDuration: e.transitionDuration,
1808
+ color: e.color,
1809
+ pointSize: e.pointSize,
1810
+ virtualPointStyle: e.virtualPointStyle,
1811
+ virtualLineStyle: e.virtualLineStyle,
1812
+ outline: e.outline,
1813
+ outlineHeightOffset: e.outlineHeightOffset,
1814
+ dictCode: e.dictCode,
1815
+ serviceName: e.serviceName,
1816
+ enableServiceColor: e.enableServiceColor,
1817
+ modelColorUrl: e.modelColorUrl,
1818
+ hiddenColors: e.hiddenColors,
1819
+ stackIndex: s.stackIndex,
1820
+ subStackIndex: s.subStackIndex,
1821
+ groupKey: s.groupKey || e.layerId
1822
+ };
1823
+ }
1824
+ let g = async () => {
1825
+ let e = ++d;
1826
+ if (f) return;
1827
+ let t = l.value;
1828
+ if (!t.layerId) {
1829
+ console.warn("[zzLayerShpZzts] 缺少 layerId,跳过初始化", t);
1830
+ return;
1831
+ }
1832
+ let n = h(t);
1833
+ u && u !== t.layerId && m(), u = t.layerId;
1834
+ try {
1835
+ let r = $(t.layerId);
1836
+ if (r?.viewer === o.value && fe(r, n)) {
1837
+ if (p = r, r.initPromise && await r.initPromise, f || e !== d || r.destroyed || $(t.layerId) !== r) return;
1838
+ r.updateOptions(n);
1839
+ return;
1840
+ }
1841
+ console.log("[zzLayerShpZzts] initLayer 入参 =", {
1842
+ layerId: n.layerId,
1843
+ calTilesUrl: n.calTilesUrl,
1844
+ tileUrl: n.tileUrl,
1845
+ opacity: n.opacity
1846
+ });
1847
+ let i = pe(o.value, n);
1848
+ p = $(t.layerId) || null, await i;
1849
+ } catch (t) {
1850
+ !f && e === d && console.error("[zzLayerShpZzts] 图层初始化失败:", t);
1851
+ }
1852
+ };
1853
+ return i(() => s.config, async () => {
1854
+ console.log("[zzLayerShpZzts] props.config changed =", JSON.parse(JSON.stringify(s.config || {}))), await g();
1855
+ }, {
1856
+ deep: !0,
1857
+ immediate: !0
1858
+ }), i(() => [
1859
+ s.stackIndex,
1860
+ s.subStackIndex,
1861
+ s.groupKey
1862
+ ], () => {
1863
+ let e = l.value, t = $(e.layerId);
1864
+ if (t && t === p && typeof t.updateOptions == "function") {
1865
+ t.updateOptions({
1866
+ stackIndex: s.stackIndex,
1867
+ subStackIndex: s.subStackIndex,
1868
+ groupKey: s.groupKey || e.layerId
1869
+ });
1870
+ return;
1871
+ }
1872
+ g();
1873
+ }), n(() => {
1874
+ console.log("[zzLayerShpZzts] 组件挂载");
1875
+ }), r(() => {
1876
+ f = !0, d++, console.log("[zzLayerShpZzts] 组件卸载,开始清理资源..."), m();
1877
+ }), (e, t) => null;
1878
+ }
1879
+ };
1880
+ //#endregion
1881
+ export { he as default };