cesium-ocean-current-zkxt123 1.0.0 → 1.0.2
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
import * as W from "cesium";
|
|
2
|
+
var me = function(y) {
|
|
3
|
+
var o = y.minVelocity || 0, v = y.maxVelocity || 10, m = (y.velocityScale || 5e-3) * (Math.pow(window.devicePixelRatio, 1 / 3) || 1), M = y.particleAge || 90, C = y.lineWidth || 1, D = y.particleMultiplier || 1 / 300, O = Math.pow(window.devicePixelRatio, 1 / 3) || 1.6, I = y.frameRate || 15, P = 1e3 / I, p = 0.97, H = [
|
|
4
4
|
"rgb(36,104, 180)",
|
|
5
5
|
"rgb(60,157, 194)",
|
|
6
6
|
"rgb(128,205,193 )",
|
|
@@ -17,208 +17,212 @@ var yt = function(m) {
|
|
|
17
17
|
"rgb(220,24,32)",
|
|
18
18
|
"rgb(180,0,35)"
|
|
19
19
|
];
|
|
20
|
-
const
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
},
|
|
24
|
-
t.hasOwnProperty("minVelocity") && (
|
|
25
|
-
},
|
|
26
|
-
var
|
|
27
|
-
return [
|
|
28
|
-
},
|
|
29
|
-
var a = t.data,
|
|
20
|
+
const e = y.colorScale || H;
|
|
21
|
+
var N = [NaN, NaN, null], b, g, L = y.data, V, n, T, F, z, j, k, Y = !1, te = function(t) {
|
|
22
|
+
L = t;
|
|
23
|
+
}, ie = function(t) {
|
|
24
|
+
t.hasOwnProperty("minVelocity") && (o = t.minVelocity), t.hasOwnProperty("maxVelocity") && (v = t.maxVelocity), t.hasOwnProperty("velocityScale") && (m = (t.velocityScale || 5e-3) * (Math.pow(window.devicePixelRatio, 1 / 3) || 1)), t.hasOwnProperty("particleAge") && (M = t.particleAge), t.hasOwnProperty("lineWidth") && (C = t.lineWidth), t.hasOwnProperty("particleMultiplier") && (D = t.particleMultiplier), t.hasOwnProperty("opacity") && (p = +t.opacity), t.hasOwnProperty("frameRate") && (I = t.frameRate), P = 1e3 / I;
|
|
25
|
+
}, ae = function(t, i, a, r, s, c) {
|
|
26
|
+
var l = 1 - t, h = 1 - i, w = l * h, E = t * h, d = l * i, x = t * i, S = a[0] * w + r[0] * E + s[0] * d + c[0] * x, f = a[1] * w + r[1] * E + s[1] * d + c[1] * x;
|
|
27
|
+
return [S, f, Math.sqrt(S * S + f * f)];
|
|
28
|
+
}, re = function(t, i) {
|
|
29
|
+
var a = t.data, r = i.data;
|
|
30
30
|
return {
|
|
31
31
|
header: t.header,
|
|
32
|
-
data: function(
|
|
33
|
-
return [a[
|
|
32
|
+
data: function(s) {
|
|
33
|
+
return [a[s], r[s]];
|
|
34
34
|
},
|
|
35
|
-
interpolate:
|
|
35
|
+
interpolate: ae
|
|
36
36
|
};
|
|
37
|
-
},
|
|
38
|
-
var
|
|
39
|
-
return t.forEach(function(
|
|
40
|
-
switch (
|
|
37
|
+
}, ne = function(t) {
|
|
38
|
+
var i = null, a = null;
|
|
39
|
+
return t.forEach(function(r) {
|
|
40
|
+
switch (r.header.parameterCategory + "," + r.header.parameterNumber) {
|
|
41
41
|
case "1,2":
|
|
42
42
|
case "2,2":
|
|
43
|
-
|
|
43
|
+
i = r;
|
|
44
44
|
break;
|
|
45
45
|
case "1,3":
|
|
46
46
|
case "2,3":
|
|
47
|
-
a =
|
|
47
|
+
a = r;
|
|
48
48
|
break;
|
|
49
49
|
}
|
|
50
|
-
}),
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
var a =
|
|
54
|
-
|
|
55
|
-
for (var
|
|
56
|
-
for (var
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
}), re(i, a);
|
|
51
|
+
}, oe = function(t, i) {
|
|
52
|
+
b = ne(t);
|
|
53
|
+
var a = b.header;
|
|
54
|
+
n = a.lo1, T = a.la1, F = a.dx, z = a.dy, j = a.nx, k = a.ny, a.la2 && a.la1 < a.la2 ? Y = !0 : Y = !1, V = new Date(a.refTime), V.setHours(V.getHours() + a.forecastTime), g = [];
|
|
55
|
+
for (var r = 0, s = Math.floor(j * F) >= 360, c = 0; c < k; c++) {
|
|
56
|
+
for (var l = [], h = 0; h < j; h++, r++)
|
|
57
|
+
l[h] = b.data(r);
|
|
58
|
+
s && l.push(l[0]), g[c] = l;
|
|
59
59
|
}
|
|
60
|
-
|
|
61
|
-
date:
|
|
62
|
-
interpolate:
|
|
60
|
+
i({
|
|
61
|
+
date: V,
|
|
62
|
+
interpolate: $
|
|
63
63
|
});
|
|
64
|
-
},
|
|
65
|
-
if (!
|
|
64
|
+
}, $ = function(t, i) {
|
|
65
|
+
if (!g)
|
|
66
66
|
return null;
|
|
67
|
-
var a =
|
|
68
|
-
|
|
69
|
-
var
|
|
70
|
-
if (
|
|
71
|
-
var
|
|
72
|
-
if (
|
|
73
|
-
var
|
|
74
|
-
if (
|
|
75
|
-
return
|
|
67
|
+
var a = le(t - n, 360) / F, r;
|
|
68
|
+
Y ? r = (i - T) / z : r = (T - i) / z;
|
|
69
|
+
var s = Math.floor(a), c = s + 1, l = Math.floor(r), h = l + 1, w;
|
|
70
|
+
if (w = g[l]) {
|
|
71
|
+
var E = w[s], d = w[c];
|
|
72
|
+
if (B(E) && B(d) && (w = g[h])) {
|
|
73
|
+
var x = w[s], S = w[c];
|
|
74
|
+
if (B(x) && B(S))
|
|
75
|
+
return b.interpolate(a - s, r - l, E, d, x, S);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
return null;
|
|
79
|
-
},
|
|
79
|
+
}, B = function(t) {
|
|
80
80
|
return t != null;
|
|
81
|
-
},
|
|
82
|
-
return t -
|
|
83
|
-
},
|
|
81
|
+
}, le = function(t, i) {
|
|
82
|
+
return t - i * Math.floor(t / i);
|
|
83
|
+
}, se = function() {
|
|
84
84
|
return /android|blackberry|iemobile|ipad|iphone|ipod|opera mini|webos/i.test(navigator.userAgent);
|
|
85
|
-
},
|
|
86
|
-
var
|
|
87
|
-
return
|
|
88
|
-
},
|
|
89
|
-
var
|
|
85
|
+
}, ve = function(t, i, a, r, s, c, l) {
|
|
86
|
+
var h = l[0] * c, w = l[1] * c, E = ce(t, i, a, r, s);
|
|
87
|
+
return l[0] = E[0] * h + E[2] * w, l[1] = E[1] * h + E[3] * w, l;
|
|
88
|
+
}, ce = function(t, i, a, r, s) {
|
|
89
|
+
var c = 2 * Math.PI, l = 5, h = i < 0 ? l : -l, w = a < 0 ? l : -l, E = K(a, i + h), d = K(a + w, i), x = Math.cos(a / 360 * c);
|
|
90
90
|
return [
|
|
91
|
-
(
|
|
92
|
-
(
|
|
93
|
-
(
|
|
94
|
-
(
|
|
91
|
+
(E[0] - r) / h / x,
|
|
92
|
+
(E[1] - s) / h / x,
|
|
93
|
+
(d[0] - r) / w,
|
|
94
|
+
(d[1] - s) / w
|
|
95
95
|
];
|
|
96
|
-
},
|
|
97
|
-
function
|
|
98
|
-
var
|
|
99
|
-
return
|
|
96
|
+
}, J = function(t, i, a) {
|
|
97
|
+
function r(s, c) {
|
|
98
|
+
var l = t[Math.round(s)];
|
|
99
|
+
return l && l[Math.round(c)] || N;
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
r.release = function() {
|
|
102
102
|
t = [];
|
|
103
|
-
},
|
|
104
|
-
var
|
|
103
|
+
}, r.randomize = function(s) {
|
|
104
|
+
var c, l, h = 0;
|
|
105
105
|
do
|
|
106
|
-
|
|
107
|
-
while (
|
|
108
|
-
return
|
|
109
|
-
}, a(
|
|
110
|
-
},
|
|
111
|
-
var
|
|
112
|
-
Math.min(Math.ceil(
|
|
113
|
-
var
|
|
114
|
-
return { x:
|
|
115
|
-
},
|
|
106
|
+
c = Math.round(Math.floor(Math.random() * i.width) + i.x), l = Math.round(Math.floor(Math.random() * i.height) + i.y);
|
|
107
|
+
while (r(c, l)[2] === null && h++ < 30);
|
|
108
|
+
return s.x = c, s.y = l, s;
|
|
109
|
+
}, a(i, r);
|
|
110
|
+
}, he = function(t, i, a) {
|
|
111
|
+
var r = t[0], s = t[1], c = Math.round(r[0]), l = Math.max(Math.floor(r[1], 0), 0);
|
|
112
|
+
Math.min(Math.ceil(s[0], i), i - 1);
|
|
113
|
+
var h = Math.min(Math.ceil(s[1], a), a - 1);
|
|
114
|
+
return { x: c, y: l, xMax: i, yMax: h, width: i, height: a };
|
|
115
|
+
}, G = function(t) {
|
|
116
116
|
return t / 180 * Math.PI;
|
|
117
|
-
},
|
|
118
|
-
var
|
|
119
|
-
return [
|
|
120
|
-
},
|
|
121
|
-
var
|
|
122
|
-
return [
|
|
123
|
-
},
|
|
124
|
-
var
|
|
125
|
-
function
|
|
126
|
-
for (var
|
|
127
|
-
var
|
|
128
|
-
if (
|
|
129
|
-
var
|
|
130
|
-
if (isFinite(
|
|
131
|
-
var
|
|
132
|
-
|
|
117
|
+
}, de = function(t, i, a) {
|
|
118
|
+
var r = y.map.containerPointToLatLng({ x: t, y: i });
|
|
119
|
+
return [r.lng, r.lat];
|
|
120
|
+
}, K = function(t, i, a) {
|
|
121
|
+
var r = y.map.latLngToContainerPoint({ lat: t, lng: i });
|
|
122
|
+
return [r.x, r.y];
|
|
123
|
+
}, fe = function(t, i, a, r) {
|
|
124
|
+
var s = {}, c = (a.south - a.north) * (a.west - a.east), l = m * Math.pow(c, 0.4), h = [], w = i.x;
|
|
125
|
+
function E(d) {
|
|
126
|
+
for (var x = [], S = i.y; S <= i.yMax; S += 2) {
|
|
127
|
+
var f = de(d, S);
|
|
128
|
+
if (f) {
|
|
129
|
+
var R = f[0], A = f[1];
|
|
130
|
+
if (isFinite(R)) {
|
|
131
|
+
var _ = t.interpolate(R, A);
|
|
132
|
+
_ && (_ = ve(s, R, A, d, S, l, _), x[S + 1] = x[S] = _);
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
|
-
|
|
136
|
+
h[d + 1] = h[d] = x;
|
|
137
137
|
}
|
|
138
|
-
(function
|
|
139
|
-
for (var
|
|
140
|
-
if (
|
|
141
|
-
setTimeout(
|
|
138
|
+
(function d() {
|
|
139
|
+
for (var x = Date.now(); w < i.width; )
|
|
140
|
+
if (E(w), w += 2, Date.now() - x > 1e3) {
|
|
141
|
+
setTimeout(d, 25);
|
|
142
142
|
return;
|
|
143
143
|
}
|
|
144
|
-
|
|
144
|
+
J(h, i, r);
|
|
145
145
|
})();
|
|
146
|
-
},
|
|
147
|
-
function a(
|
|
148
|
-
return
|
|
149
|
-
return Math.max(0, Math.min(
|
|
150
|
-
},
|
|
146
|
+
}, q, ue = function(t, i) {
|
|
147
|
+
function a(f, R) {
|
|
148
|
+
return e.indexFor = function(A) {
|
|
149
|
+
return Math.max(0, Math.min(e.length - 1, Math.round((A - f) / (R - f) * (e.length - 1))));
|
|
150
|
+
}, e;
|
|
151
151
|
}
|
|
152
|
-
var
|
|
152
|
+
var r = a(o, v), s = r.map(function() {
|
|
153
153
|
return [];
|
|
154
|
-
}),
|
|
155
|
-
|
|
156
|
-
for (var
|
|
157
|
-
|
|
158
|
-
function
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}),
|
|
162
|
-
|
|
163
|
-
var
|
|
164
|
-
if (
|
|
165
|
-
|
|
154
|
+
}), c = Math.round(t.width * t.height * D);
|
|
155
|
+
se() && (c *= O);
|
|
156
|
+
for (var l = `rgba(0, 0, 0, ${p})`, h = [], w = 0; w < c; w++)
|
|
157
|
+
h.push(i.randomize({ age: Math.floor(Math.random() * M) + 0 }));
|
|
158
|
+
function E() {
|
|
159
|
+
s.forEach(function(f) {
|
|
160
|
+
f.length = 0;
|
|
161
|
+
}), h.forEach(function(f) {
|
|
162
|
+
f.age > M && (i.randomize(f).age = 0);
|
|
163
|
+
var R = f.x, A = f.y, _ = i(R, A), ee = _[2];
|
|
164
|
+
if (ee === null)
|
|
165
|
+
f.age = M;
|
|
166
166
|
else {
|
|
167
|
-
var
|
|
168
|
-
|
|
167
|
+
var X = R + _[0], Z = A + _[1];
|
|
168
|
+
i(X, Z)[2] !== null ? (f.xt = X, f.yt = Z, s[r.indexFor(ee)].push(f)) : (f.x = X, f.y = Z);
|
|
169
169
|
}
|
|
170
|
-
|
|
170
|
+
f.age += 1;
|
|
171
171
|
});
|
|
172
172
|
}
|
|
173
|
-
var
|
|
174
|
-
|
|
175
|
-
function
|
|
176
|
-
var
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}),
|
|
173
|
+
var d = y.canvas.getContext("2d");
|
|
174
|
+
d.lineWidth = C, d.fillStyle = l, d.globalAlpha = 0.6;
|
|
175
|
+
function x() {
|
|
176
|
+
var f = "lighter";
|
|
177
|
+
d.globalCompositeOperation = "destination-in", d.fillRect(t.x, t.y, t.width, t.height), d.globalCompositeOperation = f, d.globalAlpha = p === 0 ? 0 : p * 0.9, s.forEach(function(R, A) {
|
|
178
|
+
R.length > 0 && (d.beginPath(), d.strokeStyle = r[A], R.forEach(function(_) {
|
|
179
|
+
d.moveTo(_.x, _.y), d.lineTo(_.xt, _.yt), _.x = _.xt, _.y = _.yt;
|
|
180
|
+
}), d.stroke());
|
|
181
181
|
});
|
|
182
182
|
}
|
|
183
|
-
var
|
|
184
|
-
(function
|
|
185
|
-
|
|
186
|
-
var
|
|
187
|
-
|
|
183
|
+
var S = Date.now();
|
|
184
|
+
(function f() {
|
|
185
|
+
q = requestAnimationFrame(f);
|
|
186
|
+
var R = Date.now(), A = R - S;
|
|
187
|
+
A > P && (S = R - A % P, E(), x());
|
|
188
188
|
})();
|
|
189
|
-
},
|
|
190
|
-
var
|
|
191
|
-
south:
|
|
192
|
-
north:
|
|
193
|
-
east:
|
|
194
|
-
west:
|
|
195
|
-
width:
|
|
189
|
+
}, pe = function(t, i, a, r) {
|
|
190
|
+
var s = {
|
|
191
|
+
south: G(r[0][1]),
|
|
192
|
+
north: G(r[1][1]),
|
|
193
|
+
east: G(r[1][0]),
|
|
194
|
+
west: G(r[0][0]),
|
|
195
|
+
width: i,
|
|
196
196
|
height: a
|
|
197
197
|
};
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
198
|
+
Q(), oe(L, function(c) {
|
|
199
|
+
fe(c, he(t, i, a), s, function(l, h) {
|
|
200
|
+
U.field = h, ue(l, h);
|
|
201
201
|
});
|
|
202
202
|
});
|
|
203
|
-
},
|
|
204
|
-
if (
|
|
205
|
-
var t =
|
|
206
|
-
t.clearRect(0, 0,
|
|
203
|
+
}, Q = function() {
|
|
204
|
+
if (U.field && U.field.release(), q && cancelAnimationFrame(q), y.canvas) {
|
|
205
|
+
var t = y.canvas.getContext("2d");
|
|
206
|
+
t.clearRect(0, 0, y.canvas.width, y.canvas.height);
|
|
207
207
|
}
|
|
208
|
-
},
|
|
209
|
-
params:
|
|
210
|
-
start:
|
|
211
|
-
stop:
|
|
212
|
-
createField:
|
|
213
|
-
interpolatePoint:
|
|
214
|
-
setData:
|
|
215
|
-
setOptions:
|
|
208
|
+
}, U = {
|
|
209
|
+
params: y,
|
|
210
|
+
start: pe,
|
|
211
|
+
stop: Q,
|
|
212
|
+
createField: J,
|
|
213
|
+
interpolatePoint: $,
|
|
214
|
+
setData: te,
|
|
215
|
+
setOptions: ie
|
|
216
216
|
};
|
|
217
|
-
return
|
|
217
|
+
return U;
|
|
218
218
|
};
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
219
|
+
function u(y, o, v) {
|
|
220
|
+
const m = Math.max(0, Math.min(1, v));
|
|
221
|
+
return y * (1 - m) + o * m;
|
|
222
|
+
}
|
|
223
|
+
class we {
|
|
224
|
+
constructor(o, v = {}) {
|
|
225
|
+
this.viewer = o, this.options = {
|
|
222
226
|
url: "",
|
|
223
227
|
// JSON 数据地址
|
|
224
228
|
lineWidth: 2,
|
|
@@ -230,23 +234,23 @@ class mt {
|
|
|
230
234
|
frameRate: 15,
|
|
231
235
|
colorScale: null,
|
|
232
236
|
safetyHeight: 48e5,
|
|
233
|
-
// 默认安全高度
|
|
234
|
-
...
|
|
237
|
+
// 默认安全高度 (用于保留原有的高空判断,虽然新逻辑主要依赖 H1)
|
|
238
|
+
...v
|
|
235
239
|
}, this.windy = null, this.canvas = null, this.globalData = null, this.activeExtent = [0, -90, 360, 90], this.timer = null, this._resizeListener = this._onResize.bind(this), this._cameraMoveEndListener = this._onCameraMoveEnd.bind(this), this._cameraMoveStartListener = this._onCameraMoveStart.bind(this), this._initCanvas(), this._setupEventListeners(), this.options.url && this.loadData(this.options.url);
|
|
236
240
|
}
|
|
237
241
|
_initCanvas() {
|
|
238
242
|
this.canvas = document.createElement("canvas"), this.canvas.style.cssText = "position:absolute; top:0; left:0; pointer-events:none; z-index:100; display:none;", this.canvas.className = "cesium-windy-canvas", this.viewer.cesiumWidget.container.appendChild(this.canvas), this._resizeCanvas();
|
|
239
243
|
}
|
|
240
244
|
_resizeCanvas() {
|
|
241
|
-
const
|
|
242
|
-
this.canvas.width =
|
|
245
|
+
const o = this.viewer.canvas.clientWidth, v = this.viewer.canvas.clientHeight;
|
|
246
|
+
this.canvas.width = o, this.canvas.height = v;
|
|
243
247
|
}
|
|
244
|
-
async loadData(
|
|
248
|
+
async loadData(o) {
|
|
245
249
|
try {
|
|
246
|
-
const
|
|
247
|
-
this.globalData = Object.freeze(
|
|
248
|
-
} catch (
|
|
249
|
-
console.error("[CesiumWindy] Data loading failed:",
|
|
250
|
+
const m = await (await fetch(o)).json();
|
|
251
|
+
this.globalData = Object.freeze(m), this.updateWindyState();
|
|
252
|
+
} catch (v) {
|
|
253
|
+
console.error("[CesiumWindy] Data loading failed:", v);
|
|
250
254
|
}
|
|
251
255
|
}
|
|
252
256
|
_setupEventListeners() {
|
|
@@ -263,38 +267,103 @@ class mt {
|
|
|
263
267
|
_onResize() {
|
|
264
268
|
this._resizeCanvas(), this.updateWindyState();
|
|
265
269
|
}
|
|
266
|
-
// ===
|
|
270
|
+
// === 核心逻辑:视图计算与参数动态调整 ===
|
|
267
271
|
updateWindyState() {
|
|
268
272
|
if (!this.globalData || !this.viewer)
|
|
269
273
|
return;
|
|
270
|
-
const
|
|
271
|
-
let
|
|
272
|
-
if (
|
|
273
|
-
|
|
274
|
+
const o = this.viewer.camera.positionCartographic.height;
|
|
275
|
+
let v = [0, -90, 360, 90], m = 360;
|
|
276
|
+
if (o > this.options.safetyHeight)
|
|
277
|
+
v = [0, -90, 360, 90], m = 360;
|
|
274
278
|
else {
|
|
275
|
-
const
|
|
276
|
-
if (
|
|
277
|
-
let
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
Math.max(-90,
|
|
282
|
-
|
|
283
|
-
Math.min(90,
|
|
284
|
-
],
|
|
285
|
-
}
|
|
279
|
+
const n = this.viewer.camera.computeViewRectangle(this.viewer.scene.globe.ellipsoid);
|
|
280
|
+
if (n) {
|
|
281
|
+
let T = W.Math.toDegrees(n.west), F = W.Math.toDegrees(n.south), z = W.Math.toDegrees(n.east), j = W.Math.toDegrees(n.north);
|
|
282
|
+
const k = (z - T + 360) % 360;
|
|
283
|
+
T > z || k < 0.5 ? (v = [0, -90, 360, 90], m = 360) : (v = [
|
|
284
|
+
T - 2,
|
|
285
|
+
Math.max(-90, F - 2),
|
|
286
|
+
z + 2,
|
|
287
|
+
Math.min(90, j + 2)
|
|
288
|
+
], v[0] < 0 && (v[0] += 360), v[2] < 0 && (v[2] += 360), m = k);
|
|
289
|
+
} else
|
|
290
|
+
v = [0, -90, 360, 90], m = 360;
|
|
286
291
|
}
|
|
287
|
-
this.activeExtent =
|
|
288
|
-
|
|
289
|
-
|
|
292
|
+
this.activeExtent = v;
|
|
293
|
+
const M = {
|
|
294
|
+
// 【开关】false 时,小于 50km 强制不渲染
|
|
295
|
+
showDeepZoom: !1,
|
|
296
|
+
// 【全局密度增强】
|
|
297
|
+
// 保持 1.5 倍密度,让画面饱满
|
|
298
|
+
midDensityScale: 1.5,
|
|
299
|
+
params: {
|
|
300
|
+
// [> 1000km] 全球视图
|
|
301
|
+
global: { den: 450, vel: 0.05, op: 0.97, lw: 2 },
|
|
302
|
+
// [1000km ~ 500km] 区域视图 (拖尾增强)
|
|
303
|
+
// vel 提高到 0.07,解决"变成点"的问题
|
|
304
|
+
tier1: { den: 800, vel: 0.07, op: 0.9, lw: 2.2 },
|
|
305
|
+
// [500km ~ 200km] 近景视图
|
|
306
|
+
tier2: { den: 1500, vel: 0.05, op: 0.85, lw: 2 },
|
|
307
|
+
// [200km ~ 50km] 细节视图
|
|
308
|
+
tier3: { den: 3e3, vel: 0.025, op: 0.75, lw: 1.8 },
|
|
309
|
+
// [< 50km] 超微距 (如果 showDeepZoom=true)
|
|
310
|
+
tier4: { den: 6e3, vel: 5e-3, op: 0.5, lw: 1.5 }
|
|
311
|
+
}
|
|
312
|
+
}, C = M.midDensityScale;
|
|
313
|
+
M.params.tier1.den /= C, M.params.tier2.den /= C, M.params.tier3.den /= C;
|
|
314
|
+
const D = 1e6, O = 5e5, I = 2e5, P = 5e4, p = 1e5, H = 2e4;
|
|
315
|
+
let e = M.params, N, b, g, L;
|
|
316
|
+
if (o > D) {
|
|
317
|
+
let n = e.global.den;
|
|
318
|
+
if (m > 120 ? n = 500 : m > 60 ? n = 450 : n = 400, o < D + p) {
|
|
319
|
+
const T = (D + p - o) / (p * 2);
|
|
320
|
+
N = u(n, e.tier1.den, T), b = u(e.global.vel, e.tier1.vel, T), g = u(e.global.op, e.tier1.op, T), L = u(e.global.lw, e.tier1.lw, T);
|
|
321
|
+
} else
|
|
322
|
+
N = n, b = e.global.vel, g = e.global.op, L = e.global.lw;
|
|
323
|
+
} else if (o > O)
|
|
324
|
+
if (o > D - p) {
|
|
325
|
+
const n = (D + p - o) / (p * 2);
|
|
326
|
+
N = u(e.global.den, e.tier1.den, n), b = u(e.global.vel, e.tier1.vel, n), g = u(e.global.op, e.tier1.op, n), L = u(e.global.lw, e.tier1.lw, n);
|
|
327
|
+
} else if (o < O + p) {
|
|
328
|
+
const n = (O + p - o) / (p * 2);
|
|
329
|
+
N = u(e.tier1.den, e.tier2.den, n), b = u(e.tier1.vel, e.tier2.vel, n), g = u(e.tier1.op, e.tier2.op, n), L = u(e.tier1.lw, e.tier2.lw, n);
|
|
330
|
+
} else
|
|
331
|
+
N = e.tier1.den, b = e.tier1.vel, g = e.tier1.op, L = e.tier1.lw;
|
|
332
|
+
else if (o > I)
|
|
333
|
+
if (o > O - p) {
|
|
334
|
+
const n = (O + p - o) / (p * 2);
|
|
335
|
+
N = u(e.tier1.den, e.tier2.den, n), b = u(e.tier1.vel, e.tier2.vel, n), g = u(e.tier1.op, e.tier2.op, n), L = u(e.tier1.lw, e.tier2.lw, n);
|
|
336
|
+
} else if (o < I + p) {
|
|
337
|
+
const n = (I + p - o) / (p * 2);
|
|
338
|
+
N = u(e.tier2.den, e.tier3.den, n), b = u(e.tier2.vel, e.tier3.vel, n), g = u(e.tier2.op, e.tier3.op, n), L = u(e.tier2.lw, e.tier3.lw, n);
|
|
339
|
+
} else
|
|
340
|
+
N = e.tier2.den, b = e.tier2.vel, g = e.tier2.op, L = e.tier2.lw;
|
|
341
|
+
else if (o > P)
|
|
342
|
+
if (o > I - p) {
|
|
343
|
+
const n = (I + p - o) / (p * 2);
|
|
344
|
+
N = u(e.tier2.den, e.tier3.den, n), b = u(e.tier2.vel, e.tier3.vel, n), g = u(e.tier2.op, e.tier3.op, n), L = u(e.tier2.lw, e.tier3.lw, n);
|
|
345
|
+
} else if (o < P + H) {
|
|
346
|
+
const n = (P + H - o) / (H * 2), T = 0;
|
|
347
|
+
N = u(e.tier3.den, e.tier4.den, n), b = u(e.tier3.vel, e.tier4.vel, n), g = u(e.tier3.op, T, n), L = u(e.tier3.lw, e.tier4.lw, n);
|
|
348
|
+
} else
|
|
349
|
+
N = e.tier3.den, b = e.tier3.vel, g = e.tier3.op, L = e.tier3.lw;
|
|
350
|
+
else
|
|
351
|
+
g = 0, N = 2e4, b = 0, L = 0;
|
|
352
|
+
const V = 1 / N;
|
|
353
|
+
this.windy && this.windy.setOptions({
|
|
354
|
+
particleMultiplier: V,
|
|
355
|
+
velocityScale: b,
|
|
356
|
+
lineWidth: L,
|
|
357
|
+
opacity: g
|
|
358
|
+
}), this._renderWindy(V, v);
|
|
290
359
|
}
|
|
291
|
-
_renderWindy(
|
|
292
|
-
const
|
|
293
|
-
this.windy || (this.windy = new
|
|
360
|
+
_renderWindy(o, v) {
|
|
361
|
+
const m = this.canvas.width, M = this.canvas.height;
|
|
362
|
+
this.windy || (this.windy = new me({
|
|
294
363
|
canvas: this.canvas,
|
|
295
364
|
data: this.globalData,
|
|
296
365
|
map: this._getMapAdapter(),
|
|
297
|
-
particleMultiplier:
|
|
366
|
+
particleMultiplier: o,
|
|
298
367
|
lineWidth: this.options.lineWidth,
|
|
299
368
|
velocityScale: this.options.velocityScale,
|
|
300
369
|
maxVelocity: this.options.maxVelocity,
|
|
@@ -303,45 +372,45 @@ class mt {
|
|
|
303
372
|
frameRate: this.options.frameRate,
|
|
304
373
|
colorScale: this.options.colorScale
|
|
305
374
|
})), this.windy.setOptions({
|
|
306
|
-
particleMultiplier:
|
|
375
|
+
particleMultiplier: o
|
|
307
376
|
}), this.canvas.style.display = "block", this.windy.start(
|
|
308
|
-
[[0, 0], [
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
[[
|
|
377
|
+
[[0, 0], [m, M]],
|
|
378
|
+
m,
|
|
379
|
+
M,
|
|
380
|
+
[[v[0], v[1]], [v[2], v[3]]]
|
|
312
381
|
);
|
|
313
382
|
}
|
|
314
383
|
// === 坐标适配器 ===
|
|
315
384
|
_getMapAdapter() {
|
|
316
|
-
const
|
|
385
|
+
const o = this;
|
|
317
386
|
return {
|
|
318
|
-
containerPointToLatLng: (
|
|
319
|
-
const
|
|
320
|
-
new
|
|
321
|
-
|
|
387
|
+
containerPointToLatLng: (v) => {
|
|
388
|
+
const m = o.viewer.camera.pickEllipsoid(
|
|
389
|
+
new W.Cartesian2(v.x, v.y),
|
|
390
|
+
o.viewer.scene.globe.ellipsoid
|
|
322
391
|
);
|
|
323
|
-
if (!
|
|
392
|
+
if (!m)
|
|
324
393
|
return { lng: NaN, lat: NaN };
|
|
325
|
-
const
|
|
326
|
-
let
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
const [
|
|
330
|
-
if (
|
|
331
|
-
if (
|
|
394
|
+
const M = W.Cartographic.fromCartesian(m);
|
|
395
|
+
let C = W.Math.toDegrees(M.longitude);
|
|
396
|
+
const D = W.Math.toDegrees(M.latitude);
|
|
397
|
+
C < 0 && (C += 360);
|
|
398
|
+
const [O, I, P, p] = o.activeExtent;
|
|
399
|
+
if (O < P) {
|
|
400
|
+
if (C < O || C > P || D < I || D > p)
|
|
332
401
|
return { lng: NaN, lat: NaN };
|
|
333
|
-
} else if (
|
|
402
|
+
} else if (D < I || D > p)
|
|
334
403
|
return { lng: NaN, lat: NaN };
|
|
335
|
-
return { lng:
|
|
404
|
+
return { lng: C, lat: D };
|
|
336
405
|
},
|
|
337
|
-
latLngToContainerPoint: (
|
|
338
|
-
let
|
|
339
|
-
|
|
340
|
-
const
|
|
406
|
+
latLngToContainerPoint: (v) => {
|
|
407
|
+
let m = v.lng;
|
|
408
|
+
m > 180 && (m -= 360);
|
|
409
|
+
const M = W.Cartesian3.fromDegrees(m, v.lat);
|
|
341
410
|
try {
|
|
342
|
-
const
|
|
343
|
-
if (
|
|
344
|
-
return { x:
|
|
411
|
+
const C = o.viewer.scene.cartesianToCanvasCoordinates(M);
|
|
412
|
+
if (C)
|
|
413
|
+
return { x: C.x, y: C.y };
|
|
345
414
|
} catch {
|
|
346
415
|
}
|
|
347
416
|
return { x: -1e3, y: -1e3 };
|
|
@@ -354,5 +423,5 @@ class mt {
|
|
|
354
423
|
}
|
|
355
424
|
}
|
|
356
425
|
export {
|
|
357
|
-
|
|
426
|
+
we as default
|
|
358
427
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(S,D){typeof exports=="object"&&typeof module<"u"?module.exports=D(require("cesium")):typeof define=="function"&&define.amd?define(["cesium"],D):(S=typeof globalThis<"u"?globalThis:S||self,S.CesiumOceanCurrentZKXT123=D(S.Cesium))})(this,function(S){"use strict";function D(v){const u=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(v){for(const n in v)if(n!=="default"){const f=Object.getOwnPropertyDescriptor(v,n);Object.defineProperty(u,n,f.get?f:{enumerable:!0,get:()=>v[n]})}}return u.default=v,Object.freeze(u)}const x=D(S);var te=function(v){var u=v.minVelocity||0,n=v.maxVelocity||10,f=(v.velocityScale||.005)*(Math.pow(window.devicePixelRatio,1/3)||1),m=v.particleAge||90,y=v.lineWidth||1,b=v.particleMultiplier||1/300,N=Math.pow(window.devicePixelRatio,1/3)||1.6,_=v.frameRate||15,T=1e3/_,L=.97,U=["rgb(36,104, 180)","rgb(60,157, 194)","rgb(128,205,193 )","rgb(151,218,168 )","rgb(198,231,181)","rgb(238,247,217)","rgb(255,238,159)","rgb(252,217,125)","rgb(255,182,100)","rgb(252,150,75)","rgb(250,112,52)","rgb(245,64,32)","rgb(237,45,28)","rgb(220,24,32)","rgb(180,0,35)"];const O=v.colorScale||U;var ie=[NaN,NaN,null],I,P,X=v.data,R,G,z,j,F,k,K,H=!1,re=function(e){X=e},ne=function(e){e.hasOwnProperty("minVelocity")&&(u=e.minVelocity),e.hasOwnProperty("maxVelocity")&&(n=e.maxVelocity),e.hasOwnProperty("velocityScale")&&(f=(e.velocityScale||.005)*(Math.pow(window.devicePixelRatio,1/3)||1)),e.hasOwnProperty("particleAge")&&(m=e.particleAge),e.hasOwnProperty("lineWidth")&&(y=e.lineWidth),e.hasOwnProperty("particleMultiplier")&&(b=e.particleMultiplier),e.hasOwnProperty("opacity")&&(L=+e.opacity),e.hasOwnProperty("frameRate")&&(_=e.frameRate),T=1e3/_},oe=function(e,t,a,i,o,s){var r=1-e,l=1-t,d=r*l,g=e*l,c=r*t,w=e*t,M=a[0]*d+i[0]*g+o[0]*c+s[0]*w,h=a[1]*d+i[1]*g+o[1]*c+s[1]*w;return[M,h,Math.sqrt(M*M+h*h)]},se=function(e,t){var a=e.data,i=t.data;return{header:e.header,data:function(o){return[a[o],i[o]]},interpolate:oe}},le=function(e){var t=null,a=null;return e.forEach(function(i){switch(i.header.parameterCategory+","+i.header.parameterNumber){case"1,2":case"2,2":t=i;break;case"1,3":case"2,3":a=i;break}}),se(t,a)},ce=function(e,t){I=le(e);var a=I.header;G=a.lo1,z=a.la1,j=a.dx,F=a.dy,k=a.nx,K=a.ny,a.la2&&a.la1<a.la2?H=!0:H=!1,R=new Date(a.refTime),R.setHours(R.getHours()+a.forecastTime),P=[];for(var i=0,o=Math.floor(k*j)>=360,s=0;s<K;s++){for(var r=[],l=0;l<k;l++,i++)r[l]=I.data(i);o&&r.push(r[0]),P[s]=r}t({date:R,interpolate:Z})},Z=function(e,t){if(!P)return null;var a=he(e-G,360)/j,i;H?i=(t-z)/F:i=(z-t)/F;var o=Math.floor(a),s=o+1,r=Math.floor(i),l=r+1,d;if(d=P[r]){var g=d[o],c=d[s];if(A(g)&&A(c)&&(d=P[l])){var w=d[o],M=d[s];if(A(w)&&A(M))return I.interpolate(a-o,i-r,g,c,w,M)}}return null},A=function(e){return e!=null},he=function(e,t){return e-t*Math.floor(e/t)},ve=function(){return/android|blackberry|iemobile|ipad|iphone|ipod|opera mini|webos/i.test(navigator.userAgent)},fe=function(e,t,a,i,o,s,r){var l=r[0]*s,d=r[1]*s,g=ue(e,t,a,i,o);return r[0]=g[0]*l+g[2]*d,r[1]=g[1]*l+g[3]*d,r},ue=function(e,t,a,i,o){var s=2*Math.PI,r=5,l=t<0?r:-r,d=a<0?r:-r,g=J(a,t+l),c=J(a+d,t),w=Math.cos(a/360*s);return[(g[0]-i)/l/w,(g[1]-o)/l/w,(c[0]-i)/d,(c[1]-o)/d]},$=function(e,t,a){function i(o,s){var r=e[Math.round(o)];return r&&r[Math.round(s)]||ie}i.release=function(){e=[]},i.randomize=function(o){var s,r,l=0;do s=Math.round(Math.floor(Math.random()*t.width)+t.x),r=Math.round(Math.floor(Math.random()*t.height)+t.y);while(i(s,r)[2]===null&&l++<30);return o.x=s,o.y=r,o},a(t,i)},de=function(e,t,a){var i=e[0],o=e[1],s=Math.round(i[0]),r=Math.max(Math.floor(i[1],0),0);Math.min(Math.ceil(o[0],t),t-1);var l=Math.min(Math.ceil(o[1],a),a-1);return{x:s,y:r,xMax:t,yMax:l,width:t,height:a}},W=function(e){return e/180*Math.PI},me=function(e,t,a){var i=v.map.containerPointToLatLng({x:e,y:t});return[i.lng,i.lat]},J=function(e,t,a){var i=v.map.latLngToContainerPoint({lat:e,lng:t});return[i.x,i.y]},ye=function(e,t,a,i){var o={},s=(a.south-a.north)*(a.west-a.east),r=f*Math.pow(s,.4),l=[],d=t.x;function g(c){for(var w=[],M=t.y;M<=t.yMax;M+=2){var h=me(c,M);if(h){var C=h[0],E=h[1];if(isFinite(C)){var p=e.interpolate(C,E);p&&(p=fe(o,C,E,c,M,r,p),w[M+1]=w[M]=p)}}}l[c+1]=l[c]=w}(function c(){for(var w=Date.now();d<t.width;)if(g(d),d+=2,Date.now()-w>1e3){setTimeout(c,25);return}$(l,t,i)})()},Y,ge=function(e,t){function a(h,C){return O.indexFor=function(E){return Math.max(0,Math.min(O.length-1,Math.round((E-h)/(C-h)*(O.length-1))))},O}var i=a(u,n),o=i.map(function(){return[]}),s=Math.round(e.width*e.height*b);ve()&&(s*=N);for(var r=`rgba(0, 0, 0, ${L})`,l=[],d=0;d<s;d++)l.push(t.randomize({age:Math.floor(Math.random()*m)+0}));function g(){o.forEach(function(h){h.length=0}),l.forEach(function(h){h.age>m&&(t.randomize(h).age=0);var C=h.x,E=h.y,p=t(C,E),ee=p[2];if(ee===null)h.age=m;else{var B=C+p[0],q=E+p[1];t(B,q)[2]!==null?(h.xt=B,h.yt=q,o[i.indexFor(ee)].push(h)):(h.x=B,h.y=q)}h.age+=1})}var c=v.canvas.getContext("2d");c.lineWidth=y,c.fillStyle=r,c.globalAlpha=.6;function w(){var h="lighter";c.globalCompositeOperation="destination-in",c.fillRect(e.x,e.y,e.width,e.height),c.globalCompositeOperation=h,c.globalAlpha=L===0?0:L*.9,o.forEach(function(C,E){C.length>0&&(c.beginPath(),c.strokeStyle=i[E],C.forEach(function(p){c.moveTo(p.x,p.y),c.lineTo(p.xt,p.yt),p.x=p.xt,p.y=p.yt}),c.stroke())})}var M=Date.now();(function h(){Y=requestAnimationFrame(h);var C=Date.now(),E=C-M;E>T&&(M=C-E%T,g(),w())})()},pe=function(e,t,a,i){var o={south:W(i[0][1]),north:W(i[1][1]),east:W(i[1][0]),west:W(i[0][0]),width:t,height:a};Q(),ce(X,function(s){ye(s,de(e,t,a),o,function(r,l){V.field=l,ge(r,l)})})},Q=function(){if(V.field&&V.field.release(),Y&&cancelAnimationFrame(Y),v.canvas){var e=v.canvas.getContext("2d");e.clearRect(0,0,v.canvas.width,v.canvas.height)}},V={params:v,start:pe,stop:Q,createField:$,interpolatePoint:Z,setData:re,setOptions:ne};return V};class ae{constructor(u,n={}){this.viewer=u,this.options={url:"",lineWidth:2,velocityScale:.05,maxVelocity:.7,minVelocity:0,opacity:.97,particleAge:90,frameRate:15,colorScale:null,safetyHeight:48e5,...n},this.windy=null,this.canvas=null,this.globalData=null,this.activeExtent=[0,-90,360,90],this.timer=null,this._resizeListener=this._onResize.bind(this),this._cameraMoveEndListener=this._onCameraMoveEnd.bind(this),this._cameraMoveStartListener=this._onCameraMoveStart.bind(this),this._initCanvas(),this._setupEventListeners(),this.options.url&&this.loadData(this.options.url)}_initCanvas(){this.canvas=document.createElement("canvas"),this.canvas.style.cssText="position:absolute; top:0; left:0; pointer-events:none; z-index:100; display:none;",this.canvas.className="cesium-windy-canvas",this.viewer.cesiumWidget.container.appendChild(this.canvas),this._resizeCanvas()}_resizeCanvas(){const u=this.viewer.canvas.clientWidth,n=this.viewer.canvas.clientHeight;this.canvas.width=u,this.canvas.height=n}async loadData(u){try{const f=await(await fetch(u)).json();this.globalData=Object.freeze(f),this.updateWindyState()}catch(n){console.error("[CesiumWindy] Data loading failed:",n)}}_setupEventListeners(){this.viewer.camera.moveStart.addEventListener(this._cameraMoveStartListener),this.viewer.camera.moveEnd.addEventListener(this._cameraMoveEndListener),window.addEventListener("resize",this._resizeListener)}_onCameraMoveStart(){this.canvas&&(this.canvas.style.display="none"),this.windy&&this.windy.stop()}_onCameraMoveEnd(){this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.updateWindyState()},200)}_onResize(){this._resizeCanvas(),this.updateWindyState()}updateWindyState(){if(!this.globalData||!this.viewer)return;const u=this.viewer.camera.positionCartographic.height;let n=[0,-90,360,90],f=360;if(u>this.options.safetyHeight)n=[0,-90,360,90],f=360;else{const y=this.viewer.camera.computeViewRectangle(this.viewer.scene.globe.ellipsoid);if(y){let b=x.Math.toDegrees(y.west),N=x.Math.toDegrees(y.south),_=x.Math.toDegrees(y.east),T=x.Math.toDegrees(y.north);const L=(_-b+360)%360;b>_||L<.5?(n=[0,-90,360,90],f=360):(n=[b-2,Math.max(-90,N-2),_+2,Math.min(90,T+2)],n[0]<0&&(n[0]+=360),n[2]<0&&(n[2]+=360),f=L)}}this.activeExtent=n;let m;f>120?m=1/600:f>60?m=1/500:f>20?m=1/300:m=1/200,u>this.options.safetyHeight&&m>1/300&&(m=1/300),this._renderWindy(m,n)}_renderWindy(u,n){const f=this.canvas.width,m=this.canvas.height;this.windy||(this.windy=new te({canvas:this.canvas,data:this.globalData,map:this._getMapAdapter(),particleMultiplier:u,lineWidth:this.options.lineWidth,velocityScale:this.options.velocityScale,maxVelocity:this.options.maxVelocity,minVelocity:this.options.minVelocity,opacity:this.options.opacity,frameRate:this.options.frameRate,colorScale:this.options.colorScale})),this.windy.setOptions({particleMultiplier:u}),this.canvas.style.display="block",this.windy.start([[0,0],[f,m]],f,m,[[n[0],n[1]],[n[2],n[3]]])}_getMapAdapter(){const u=this;return{containerPointToLatLng:n=>{const f=u.viewer.camera.pickEllipsoid(new x.Cartesian2(n.x,n.y),u.viewer.scene.globe.ellipsoid);if(!f)return{lng:NaN,lat:NaN};const m=x.Cartographic.fromCartesian(f);let y=x.Math.toDegrees(m.longitude);const b=x.Math.toDegrees(m.latitude);y<0&&(y+=360);const[N,_,T,L]=u.activeExtent;if(N<T){if(y<N||y>T||b<_||b>L)return{lng:NaN,lat:NaN}}else if(b<_||b>L)return{lng:NaN,lat:NaN};return{lng:y,lat:b}},latLngToContainerPoint:n=>{let f=n.lng;f>180&&(f-=360);const m=x.Cartesian3.fromDegrees(f,n.lat);try{const y=u.viewer.scene.cartesianToCanvasCoordinates(m);if(y)return{x:y.x,y:y.y}}catch{}return{x:-1e3,y:-1e3}}}}destroy(){this.windy&&this.windy.stop(),this.viewer.camera.moveStart.removeEventListener(this._cameraMoveStartListener),this.viewer.camera.moveEnd.removeEventListener(this._cameraMoveEndListener),window.removeEventListener("resize",this._resizeListener),this.canvas&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas)}}return ae});
|
|
1
|
+
(function(j,H){typeof exports=="object"&&typeof module<"u"?module.exports=H(require("cesium")):typeof define=="function"&&define.amd?define(["cesium"],H):(j=typeof globalThis<"u"?globalThis:j||self,j.CesiumOceanCurrentZKXT123=H(j.Cesium))})(this,function(j){"use strict";function H(m){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(m){for(const l in m)if(l!=="default"){const p=Object.getOwnPropertyDescriptor(m,l);Object.defineProperty(o,l,p.get?p:{enumerable:!0,get:()=>m[l]})}}return o.default=m,Object.freeze(o)}const W=H(j);var ae=function(m){var o=m.minVelocity||0,l=m.maxVelocity||10,p=(m.velocityScale||.005)*(Math.pow(window.devicePixelRatio,1/3)||1),M=m.particleAge||90,C=m.lineWidth||1,D=m.particleMultiplier||1/300,P=Math.pow(window.devicePixelRatio,1/3)||1.6,R=m.frameRate||15,A=1e3/R,y=.97,F=["rgb(36,104, 180)","rgb(60,157, 194)","rgb(128,205,193 )","rgb(151,218,168 )","rgb(198,231,181)","rgb(238,247,217)","rgb(255,238,159)","rgb(252,217,125)","rgb(255,182,100)","rgb(252,150,75)","rgb(250,112,52)","rgb(245,64,32)","rgb(237,45,28)","rgb(220,24,32)","rgb(180,0,35)"];const e=m.colorScale||F;var T=[NaN,NaN,null],b,w,L=m.data,V,n,N,k,z,Y,B,G=!1,ne=function(t){L=t},oe=function(t){t.hasOwnProperty("minVelocity")&&(o=t.minVelocity),t.hasOwnProperty("maxVelocity")&&(l=t.maxVelocity),t.hasOwnProperty("velocityScale")&&(p=(t.velocityScale||.005)*(Math.pow(window.devicePixelRatio,1/3)||1)),t.hasOwnProperty("particleAge")&&(M=t.particleAge),t.hasOwnProperty("lineWidth")&&(C=t.lineWidth),t.hasOwnProperty("particleMultiplier")&&(D=t.particleMultiplier),t.hasOwnProperty("opacity")&&(y=+t.opacity),t.hasOwnProperty("frameRate")&&(R=t.frameRate),A=1e3/R},le=function(t,i,a,r,c,v){var s=1-t,h=1-i,g=s*h,E=t*h,d=s*i,x=t*i,S=a[0]*g+r[0]*E+c[0]*d+v[0]*x,u=a[1]*g+r[1]*E+c[1]*d+v[1]*x;return[S,u,Math.sqrt(S*S+u*u)]},se=function(t,i){var a=t.data,r=i.data;return{header:t.header,data:function(c){return[a[c],r[c]]},interpolate:le}},ce=function(t){var i=null,a=null;return t.forEach(function(r){switch(r.header.parameterCategory+","+r.header.parameterNumber){case"1,2":case"2,2":i=r;break;case"1,3":case"2,3":a=r;break}}),se(i,a)},ve=function(t,i){b=ce(t);var a=b.header;n=a.lo1,N=a.la1,k=a.dx,z=a.dy,Y=a.nx,B=a.ny,a.la2&&a.la1<a.la2?G=!0:G=!1,V=new Date(a.refTime),V.setHours(V.getHours()+a.forecastTime),w=[];for(var r=0,c=Math.floor(Y*k)>=360,v=0;v<B;v++){for(var s=[],h=0;h<Y;h++,r++)s[h]=b.data(r);c&&s.push(s[0]),w[v]=s}i({date:V,interpolate:J})},J=function(t,i){if(!w)return null;var a=he(t-n,360)/k,r;G?r=(i-N)/z:r=(N-i)/z;var c=Math.floor(a),v=c+1,s=Math.floor(r),h=s+1,g;if(g=w[s]){var E=g[c],d=g[v];if(q(E)&&q(d)&&(g=w[h])){var x=g[c],S=g[v];if(q(x)&&q(S))return b.interpolate(a-c,r-s,E,d,x,S)}}return null},q=function(t){return t!=null},he=function(t,i){return t-i*Math.floor(t/i)},fe=function(){return/android|blackberry|iemobile|ipad|iphone|ipod|opera mini|webos/i.test(navigator.userAgent)},de=function(t,i,a,r,c,v,s){var h=s[0]*v,g=s[1]*v,E=ue(t,i,a,r,c);return s[0]=E[0]*h+E[2]*g,s[1]=E[1]*h+E[3]*g,s},ue=function(t,i,a,r,c){var v=2*Math.PI,s=5,h=i<0?s:-s,g=a<0?s:-s,E=ee(a,i+h),d=ee(a+g,i),x=Math.cos(a/360*v);return[(E[0]-r)/h/x,(E[1]-c)/h/x,(d[0]-r)/g,(d[1]-c)/g]},Q=function(t,i,a){function r(c,v){var s=t[Math.round(c)];return s&&s[Math.round(v)]||T}r.release=function(){t=[]},r.randomize=function(c){var v,s,h=0;do v=Math.round(Math.floor(Math.random()*i.width)+i.x),s=Math.round(Math.floor(Math.random()*i.height)+i.y);while(r(v,s)[2]===null&&h++<30);return c.x=v,c.y=s,c},a(i,r)},pe=function(t,i,a){var r=t[0],c=t[1],v=Math.round(r[0]),s=Math.max(Math.floor(r[1],0),0);Math.min(Math.ceil(c[0],i),i-1);var h=Math.min(Math.ceil(c[1],a),a-1);return{x:v,y:s,xMax:i,yMax:h,width:i,height:a}},U=function(t){return t/180*Math.PI},me=function(t,i,a){var r=m.map.containerPointToLatLng({x:t,y:i});return[r.lng,r.lat]},ee=function(t,i,a){var r=m.map.latLngToContainerPoint({lat:t,lng:i});return[r.x,r.y]},ye=function(t,i,a,r){var c={},v=(a.south-a.north)*(a.west-a.east),s=p*Math.pow(v,.4),h=[],g=i.x;function E(d){for(var x=[],S=i.y;S<=i.yMax;S+=2){var u=me(d,S);if(u){var O=u[0],I=u[1];if(isFinite(O)){var _=t.interpolate(O,I);_&&(_=de(c,O,I,d,S,s,_),x[S+1]=x[S]=_)}}}h[d+1]=h[d]=x}(function d(){for(var x=Date.now();g<i.width;)if(E(g),g+=2,Date.now()-x>1e3){setTimeout(d,25);return}Q(h,i,r)})()},Z,ge=function(t,i){function a(u,O){return e.indexFor=function(I){return Math.max(0,Math.min(e.length-1,Math.round((I-u)/(O-u)*(e.length-1))))},e}var r=a(o,l),c=r.map(function(){return[]}),v=Math.round(t.width*t.height*D);fe()&&(v*=P);for(var s=`rgba(0, 0, 0, ${y})`,h=[],g=0;g<v;g++)h.push(i.randomize({age:Math.floor(Math.random()*M)+0}));function E(){c.forEach(function(u){u.length=0}),h.forEach(function(u){u.age>M&&(i.randomize(u).age=0);var O=u.x,I=u.y,_=i(O,I),ie=_[2];if(ie===null)u.age=M;else{var K=O+_[0],$=I+_[1];i(K,$)[2]!==null?(u.xt=K,u.yt=$,c[r.indexFor(ie)].push(u)):(u.x=K,u.y=$)}u.age+=1})}var d=m.canvas.getContext("2d");d.lineWidth=C,d.fillStyle=s,d.globalAlpha=.6;function x(){var u="lighter";d.globalCompositeOperation="destination-in",d.fillRect(t.x,t.y,t.width,t.height),d.globalCompositeOperation=u,d.globalAlpha=y===0?0:y*.9,c.forEach(function(O,I){O.length>0&&(d.beginPath(),d.strokeStyle=r[I],O.forEach(function(_){d.moveTo(_.x,_.y),d.lineTo(_.xt,_.yt),_.x=_.xt,_.y=_.yt}),d.stroke())})}var S=Date.now();(function u(){Z=requestAnimationFrame(u);var O=Date.now(),I=O-S;I>A&&(S=O-I%A,E(),x())})()},we=function(t,i,a,r){var c={south:U(r[0][1]),north:U(r[1][1]),east:U(r[1][0]),west:U(r[0][0]),width:i,height:a};te(),ve(L,function(v){ye(v,pe(t,i,a),c,function(s,h){X.field=h,ge(s,h)})})},te=function(){if(X.field&&X.field.release(),Z&&cancelAnimationFrame(Z),m.canvas){var t=m.canvas.getContext("2d");t.clearRect(0,0,m.canvas.width,m.canvas.height)}},X={params:m,start:we,stop:te,createField:Q,interpolatePoint:J,setData:ne,setOptions:oe};return X};function f(m,o,l){const p=Math.max(0,Math.min(1,l));return m*(1-p)+o*p}class re{constructor(o,l={}){this.viewer=o,this.options={url:"",lineWidth:2,velocityScale:.05,maxVelocity:.7,minVelocity:0,opacity:.97,particleAge:90,frameRate:15,colorScale:null,safetyHeight:48e5,...l},this.windy=null,this.canvas=null,this.globalData=null,this.activeExtent=[0,-90,360,90],this.timer=null,this._resizeListener=this._onResize.bind(this),this._cameraMoveEndListener=this._onCameraMoveEnd.bind(this),this._cameraMoveStartListener=this._onCameraMoveStart.bind(this),this._initCanvas(),this._setupEventListeners(),this.options.url&&this.loadData(this.options.url)}_initCanvas(){this.canvas=document.createElement("canvas"),this.canvas.style.cssText="position:absolute; top:0; left:0; pointer-events:none; z-index:100; display:none;",this.canvas.className="cesium-windy-canvas",this.viewer.cesiumWidget.container.appendChild(this.canvas),this._resizeCanvas()}_resizeCanvas(){const o=this.viewer.canvas.clientWidth,l=this.viewer.canvas.clientHeight;this.canvas.width=o,this.canvas.height=l}async loadData(o){try{const p=await(await fetch(o)).json();this.globalData=Object.freeze(p),this.updateWindyState()}catch(l){console.error("[CesiumWindy] Data loading failed:",l)}}_setupEventListeners(){this.viewer.camera.moveStart.addEventListener(this._cameraMoveStartListener),this.viewer.camera.moveEnd.addEventListener(this._cameraMoveEndListener),window.addEventListener("resize",this._resizeListener)}_onCameraMoveStart(){this.canvas&&(this.canvas.style.display="none"),this.windy&&this.windy.stop()}_onCameraMoveEnd(){this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.updateWindyState()},200)}_onResize(){this._resizeCanvas(),this.updateWindyState()}updateWindyState(){if(!this.globalData||!this.viewer)return;const o=this.viewer.camera.positionCartographic.height;let l=[0,-90,360,90],p=360;if(o>this.options.safetyHeight)l=[0,-90,360,90],p=360;else{const n=this.viewer.camera.computeViewRectangle(this.viewer.scene.globe.ellipsoid);if(n){let N=W.Math.toDegrees(n.west),k=W.Math.toDegrees(n.south),z=W.Math.toDegrees(n.east),Y=W.Math.toDegrees(n.north);const B=(z-N+360)%360;N>z||B<.5?(l=[0,-90,360,90],p=360):(l=[N-2,Math.max(-90,k-2),z+2,Math.min(90,Y+2)],l[0]<0&&(l[0]+=360),l[2]<0&&(l[2]+=360),p=B)}else l=[0,-90,360,90],p=360}this.activeExtent=l;const M={showDeepZoom:!1,midDensityScale:1.5,params:{global:{den:450,vel:.05,op:.97,lw:2},tier1:{den:800,vel:.07,op:.9,lw:2.2},tier2:{den:1500,vel:.05,op:.85,lw:2},tier3:{den:3e3,vel:.025,op:.75,lw:1.8},tier4:{den:6e3,vel:.005,op:.5,lw:1.5}}},C=M.midDensityScale;M.params.tier1.den/=C,M.params.tier2.den/=C,M.params.tier3.den/=C;const D=1e6,P=5e5,R=2e5,A=5e4,y=1e5,F=2e4;let e=M.params,T,b,w,L;if(o>D){let n=e.global.den;if(p>120?n=500:p>60?n=450:n=400,o<D+y){const N=(D+y-o)/(y*2);T=f(n,e.tier1.den,N),b=f(e.global.vel,e.tier1.vel,N),w=f(e.global.op,e.tier1.op,N),L=f(e.global.lw,e.tier1.lw,N)}else T=n,b=e.global.vel,w=e.global.op,L=e.global.lw}else if(o>P)if(o>D-y){const n=(D+y-o)/(y*2);T=f(e.global.den,e.tier1.den,n),b=f(e.global.vel,e.tier1.vel,n),w=f(e.global.op,e.tier1.op,n),L=f(e.global.lw,e.tier1.lw,n)}else if(o<P+y){const n=(P+y-o)/(y*2);T=f(e.tier1.den,e.tier2.den,n),b=f(e.tier1.vel,e.tier2.vel,n),w=f(e.tier1.op,e.tier2.op,n),L=f(e.tier1.lw,e.tier2.lw,n)}else T=e.tier1.den,b=e.tier1.vel,w=e.tier1.op,L=e.tier1.lw;else if(o>R)if(o>P-y){const n=(P+y-o)/(y*2);T=f(e.tier1.den,e.tier2.den,n),b=f(e.tier1.vel,e.tier2.vel,n),w=f(e.tier1.op,e.tier2.op,n),L=f(e.tier1.lw,e.tier2.lw,n)}else if(o<R+y){const n=(R+y-o)/(y*2);T=f(e.tier2.den,e.tier3.den,n),b=f(e.tier2.vel,e.tier3.vel,n),w=f(e.tier2.op,e.tier3.op,n),L=f(e.tier2.lw,e.tier3.lw,n)}else T=e.tier2.den,b=e.tier2.vel,w=e.tier2.op,L=e.tier2.lw;else if(o>A)if(o>R-y){const n=(R+y-o)/(y*2);T=f(e.tier2.den,e.tier3.den,n),b=f(e.tier2.vel,e.tier3.vel,n),w=f(e.tier2.op,e.tier3.op,n),L=f(e.tier2.lw,e.tier3.lw,n)}else if(o<A+F){const n=(A+F-o)/(F*2),N=0;T=f(e.tier3.den,e.tier4.den,n),b=f(e.tier3.vel,e.tier4.vel,n),w=f(e.tier3.op,N,n),L=f(e.tier3.lw,e.tier4.lw,n)}else T=e.tier3.den,b=e.tier3.vel,w=e.tier3.op,L=e.tier3.lw;else w=0,T=2e4,b=0,L=0;const V=1/T;this.windy&&this.windy.setOptions({particleMultiplier:V,velocityScale:b,lineWidth:L,opacity:w}),this._renderWindy(V,l)}_renderWindy(o,l){const p=this.canvas.width,M=this.canvas.height;this.windy||(this.windy=new ae({canvas:this.canvas,data:this.globalData,map:this._getMapAdapter(),particleMultiplier:o,lineWidth:this.options.lineWidth,velocityScale:this.options.velocityScale,maxVelocity:this.options.maxVelocity,minVelocity:this.options.minVelocity,opacity:this.options.opacity,frameRate:this.options.frameRate,colorScale:this.options.colorScale})),this.windy.setOptions({particleMultiplier:o}),this.canvas.style.display="block",this.windy.start([[0,0],[p,M]],p,M,[[l[0],l[1]],[l[2],l[3]]])}_getMapAdapter(){const o=this;return{containerPointToLatLng:l=>{const p=o.viewer.camera.pickEllipsoid(new W.Cartesian2(l.x,l.y),o.viewer.scene.globe.ellipsoid);if(!p)return{lng:NaN,lat:NaN};const M=W.Cartographic.fromCartesian(p);let C=W.Math.toDegrees(M.longitude);const D=W.Math.toDegrees(M.latitude);C<0&&(C+=360);const[P,R,A,y]=o.activeExtent;if(P<A){if(C<P||C>A||D<R||D>y)return{lng:NaN,lat:NaN}}else if(D<R||D>y)return{lng:NaN,lat:NaN};return{lng:C,lat:D}},latLngToContainerPoint:l=>{let p=l.lng;p>180&&(p-=360);const M=W.Cartesian3.fromDegrees(p,l.lat);try{const C=o.viewer.scene.cartesianToCanvasCoordinates(M);if(C)return{x:C.x,y:C.y}}catch{}return{x:-1e3,y:-1e3}}}}destroy(){this.windy&&this.windy.stop(),this.viewer.camera.moveStart.removeEventListener(this._cameraMoveStartListener),this.viewer.camera.moveEnd.removeEventListener(this._cameraMoveEndListener),window.removeEventListener("resize",this._resizeListener),this.canvas&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas)}}return re});
|
package/package.json
CHANGED