deckgl-expansion 1.0.4 → 1.0.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.
- package/dist/lib/index.es.js +144 -146
- package/dist/lib/index.umd.js +1 -1
- package/dist/types/layers/src/windy-layer.d.ts +2 -0
- package/package.json +1 -1
package/dist/lib/index.es.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { Layer as
|
|
5
|
-
function
|
|
1
|
+
var E = Object.defineProperty;
|
|
2
|
+
var $ = (n, t, e) => t in n ? E(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
3
|
+
var j = (n, t, e) => $(n, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { Layer as G } from "@deck.gl/core";
|
|
5
|
+
function q() {
|
|
6
6
|
}
|
|
7
|
-
function
|
|
7
|
+
function D(n) {
|
|
8
8
|
return Object.getOwnPropertySymbols(n).filter((t) => Object.prototype.propertyIsEnumerable.call(n, t));
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function N(n) {
|
|
11
11
|
return n == null ? n === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(n);
|
|
12
12
|
}
|
|
13
|
-
const K = "[object RegExp]", k = "[object String]",
|
|
13
|
+
const K = "[object RegExp]", k = "[object String]", Z = "[object Number]", _ = "[object Boolean]", V = "[object Arguments]", H = "[object Symbol]", J = "[object Date]", Q = "[object Map]", tt = "[object Set]", et = "[object Array]", it = "[object Function]", nt = "[object ArrayBuffer]", v = "[object Object]", st = "[object Error]", ot = "[object DataView]", rt = "[object Uint8Array]", at = "[object Uint8ClampedArray]", ct = "[object Uint16Array]", lt = "[object Uint32Array]", ht = "[object BigUint64Array]", ut = "[object Int8Array]", dt = "[object Int16Array]", ft = "[object Int32Array]", gt = "[object BigInt64Array]", pt = "[object Float32Array]", yt = "[object Float64Array]";
|
|
14
14
|
function Y(n) {
|
|
15
15
|
if (!n || typeof n != "object")
|
|
16
16
|
return !1;
|
|
17
17
|
const t = Object.getPrototypeOf(n);
|
|
18
18
|
return t === null || t === Object.prototype || Object.getPrototypeOf(t) === null ? Object.prototype.toString.call(n) === "[object Object]" : !1;
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function xt(n, t) {
|
|
21
21
|
return n === t || Number.isNaN(n) && Number.isNaN(t);
|
|
22
22
|
}
|
|
23
23
|
function mt(n, t, e) {
|
|
24
|
-
return
|
|
24
|
+
return m(n, t, void 0, void 0, void 0, void 0, e);
|
|
25
25
|
}
|
|
26
|
-
function
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
return
|
|
26
|
+
function m(n, t, e, i, s, o, a) {
|
|
27
|
+
const c = a(n, t, e, i, s, o);
|
|
28
|
+
if (c !== void 0)
|
|
29
|
+
return c;
|
|
30
30
|
if (typeof n == typeof t)
|
|
31
31
|
switch (typeof n) {
|
|
32
32
|
case "bigint":
|
|
@@ -40,96 +40,96 @@ function p(n, t, e, i, s, o, c) {
|
|
|
40
40
|
case "function":
|
|
41
41
|
return n === t;
|
|
42
42
|
case "object":
|
|
43
|
-
return w(n, t, o,
|
|
43
|
+
return w(n, t, o, a);
|
|
44
44
|
}
|
|
45
|
-
return w(n, t, o,
|
|
45
|
+
return w(n, t, o, a);
|
|
46
46
|
}
|
|
47
47
|
function w(n, t, e, i) {
|
|
48
48
|
if (Object.is(n, t))
|
|
49
49
|
return !0;
|
|
50
|
-
let s =
|
|
51
|
-
if (s === V && (s =
|
|
50
|
+
let s = N(n), o = N(t);
|
|
51
|
+
if (s === V && (s = v), o === V && (o = v), s !== o)
|
|
52
52
|
return !1;
|
|
53
53
|
switch (s) {
|
|
54
54
|
case k:
|
|
55
55
|
return n.toString() === t.toString();
|
|
56
|
-
case
|
|
56
|
+
case Z: {
|
|
57
57
|
const r = n.valueOf(), l = t.valueOf();
|
|
58
|
-
return
|
|
58
|
+
return xt(r, l);
|
|
59
59
|
}
|
|
60
|
-
case Z:
|
|
61
|
-
case H:
|
|
62
60
|
case _:
|
|
61
|
+
case J:
|
|
62
|
+
case H:
|
|
63
63
|
return Object.is(n.valueOf(), t.valueOf());
|
|
64
64
|
case K:
|
|
65
65
|
return n.source === t.source && n.flags === t.flags;
|
|
66
|
-
case
|
|
66
|
+
case it:
|
|
67
67
|
return n === t;
|
|
68
68
|
}
|
|
69
69
|
e = e ?? /* @__PURE__ */ new Map();
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
return
|
|
70
|
+
const a = e.get(n), c = e.get(t);
|
|
71
|
+
if (a != null && c != null)
|
|
72
|
+
return a === t;
|
|
73
73
|
e.set(n, t), e.set(t, n);
|
|
74
74
|
try {
|
|
75
75
|
switch (s) {
|
|
76
|
-
case
|
|
76
|
+
case Q: {
|
|
77
77
|
if (n.size !== t.size)
|
|
78
78
|
return !1;
|
|
79
79
|
for (const [r, l] of n.entries())
|
|
80
|
-
if (!t.has(r) || !
|
|
80
|
+
if (!t.has(r) || !m(l, t.get(r), r, n, t, e, i))
|
|
81
81
|
return !1;
|
|
82
82
|
return !0;
|
|
83
83
|
}
|
|
84
|
-
case
|
|
84
|
+
case tt: {
|
|
85
85
|
if (n.size !== t.size)
|
|
86
86
|
return !1;
|
|
87
87
|
const r = Array.from(n.values()), l = Array.from(t.values());
|
|
88
|
-
for (let
|
|
89
|
-
const h = r[
|
|
88
|
+
for (let d = 0; d < r.length; d++) {
|
|
89
|
+
const h = r[d], u = l.findIndex((f) => m(h, f, void 0, n, t, e, i));
|
|
90
90
|
if (u === -1)
|
|
91
91
|
return !1;
|
|
92
92
|
l.splice(u, 1);
|
|
93
93
|
}
|
|
94
94
|
return !0;
|
|
95
95
|
}
|
|
96
|
-
case
|
|
97
|
-
case ot:
|
|
96
|
+
case et:
|
|
98
97
|
case rt:
|
|
99
|
-
case ct:
|
|
100
98
|
case at:
|
|
99
|
+
case ct:
|
|
101
100
|
case lt:
|
|
102
101
|
case ht:
|
|
103
102
|
case ut:
|
|
104
|
-
case ft:
|
|
105
103
|
case dt:
|
|
104
|
+
case ft:
|
|
106
105
|
case gt:
|
|
107
|
-
case
|
|
106
|
+
case pt:
|
|
107
|
+
case yt: {
|
|
108
108
|
if (typeof Buffer < "u" && Buffer.isBuffer(n) !== Buffer.isBuffer(t) || n.length !== t.length)
|
|
109
109
|
return !1;
|
|
110
110
|
for (let r = 0; r < n.length; r++)
|
|
111
|
-
if (!
|
|
111
|
+
if (!m(n[r], t[r], r, n, t, e, i))
|
|
112
112
|
return !1;
|
|
113
113
|
return !0;
|
|
114
114
|
}
|
|
115
|
-
case
|
|
115
|
+
case nt:
|
|
116
116
|
return n.byteLength !== t.byteLength ? !1 : w(new Uint8Array(n), new Uint8Array(t), e, i);
|
|
117
|
-
case
|
|
117
|
+
case ot:
|
|
118
118
|
return n.byteLength !== t.byteLength || n.byteOffset !== t.byteOffset ? !1 : w(new Uint8Array(n), new Uint8Array(t), e, i);
|
|
119
|
-
case
|
|
119
|
+
case st:
|
|
120
120
|
return n.name === t.name && n.message === t.message;
|
|
121
|
-
case
|
|
121
|
+
case v: {
|
|
122
122
|
if (!(w(n.constructor, t.constructor, e, i) || Y(n) && Y(t)))
|
|
123
123
|
return !1;
|
|
124
|
-
const l = [...Object.keys(n), ...
|
|
125
|
-
if (l.length !==
|
|
124
|
+
const l = [...Object.keys(n), ...D(n)], d = [...Object.keys(t), ...D(t)];
|
|
125
|
+
if (l.length !== d.length)
|
|
126
126
|
return !1;
|
|
127
127
|
for (let h = 0; h < l.length; h++) {
|
|
128
|
-
const u = l[h],
|
|
128
|
+
const u = l[h], f = n[u];
|
|
129
129
|
if (!Object.hasOwn(t, u))
|
|
130
130
|
return !1;
|
|
131
|
-
const
|
|
132
|
-
if (!
|
|
131
|
+
const p = t[u];
|
|
132
|
+
if (!m(f, p, u, n, t, e, i))
|
|
133
133
|
return !1;
|
|
134
134
|
}
|
|
135
135
|
return !0;
|
|
@@ -141,16 +141,16 @@ function w(n, t, e, i) {
|
|
|
141
141
|
e.delete(n), e.delete(t);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
function
|
|
145
|
-
return mt(n, t,
|
|
144
|
+
function wt(n, t) {
|
|
145
|
+
return mt(n, t, q);
|
|
146
146
|
}
|
|
147
|
-
const
|
|
148
|
-
function
|
|
147
|
+
const bt = Object.prototype.hasOwnProperty, y = typeof Symbol < "u" ? Symbol.toStringTag : void 0;
|
|
148
|
+
function jt(n) {
|
|
149
149
|
if (n === null)
|
|
150
150
|
return n === void 0 ? "[object Undefined]" : "[object Null]";
|
|
151
151
|
if (!(y && y in Object(n)))
|
|
152
152
|
return toString.call(n);
|
|
153
|
-
const t =
|
|
153
|
+
const t = bt.call(n, y), e = n[y];
|
|
154
154
|
let i = !1;
|
|
155
155
|
try {
|
|
156
156
|
n[y] = void 0, i = !0;
|
|
@@ -159,13 +159,13 @@ function bt(n) {
|
|
|
159
159
|
const s = Object.prototype.toString.call(n);
|
|
160
160
|
return i && (t ? n[y] = e : delete n[y]), s;
|
|
161
161
|
}
|
|
162
|
-
function
|
|
163
|
-
if (!
|
|
162
|
+
function x(n) {
|
|
163
|
+
if (!vt(n))
|
|
164
164
|
return !1;
|
|
165
|
-
const t =
|
|
165
|
+
const t = jt(n);
|
|
166
166
|
return t === "[object Function]" || t === "[object AsyncFunction]" || t === "[object GeneratorFunction]" || t === "[object Proxy]";
|
|
167
167
|
}
|
|
168
|
-
function
|
|
168
|
+
function vt(n) {
|
|
169
169
|
const t = typeof n;
|
|
170
170
|
return n !== null && (t === "object" || t === "function");
|
|
171
171
|
}
|
|
@@ -175,39 +175,39 @@ function At(n) {
|
|
|
175
175
|
function A(n) {
|
|
176
176
|
return Object.prototype.toString.call(n) === "[object Number]" && !isNaN(n);
|
|
177
177
|
}
|
|
178
|
-
function
|
|
178
|
+
function St(n) {
|
|
179
179
|
return Array.isArray(n);
|
|
180
180
|
}
|
|
181
|
-
function
|
|
181
|
+
function Ot(n, t) {
|
|
182
182
|
console.warn(`${t}: ${n}`);
|
|
183
183
|
}
|
|
184
184
|
const z = {};
|
|
185
|
-
function Ot(n, t) {
|
|
186
|
-
z[t] || (St(t, n), z[t] = !0);
|
|
187
|
-
}
|
|
188
185
|
function It(n, t) {
|
|
186
|
+
z[t] || (Ot(t, n), z[t] = !0);
|
|
187
|
+
}
|
|
188
|
+
function Tt(n, t) {
|
|
189
189
|
return n - t * Math.floor(n / t);
|
|
190
190
|
}
|
|
191
191
|
function g(n) {
|
|
192
192
|
return n != null && !isNaN(n);
|
|
193
193
|
}
|
|
194
|
-
function
|
|
194
|
+
function Ct(n, t = {}) {
|
|
195
195
|
let e, i;
|
|
196
|
-
if (n.forEach(function(
|
|
197
|
-
switch (
|
|
196
|
+
if (n.forEach(function(a) {
|
|
197
|
+
switch (a.header.parameterCategory + "," + a.header.parameterNumber) {
|
|
198
198
|
case "1,2":
|
|
199
199
|
case "2,2":
|
|
200
|
-
e =
|
|
200
|
+
e = a;
|
|
201
201
|
break;
|
|
202
202
|
case "1,3":
|
|
203
203
|
case "2,3":
|
|
204
|
-
i =
|
|
204
|
+
i = a;
|
|
205
205
|
break;
|
|
206
206
|
}
|
|
207
207
|
}), !i || !e)
|
|
208
208
|
return;
|
|
209
209
|
const s = e.header;
|
|
210
|
-
return new
|
|
210
|
+
return new U({
|
|
211
211
|
xmin: s.lo1,
|
|
212
212
|
// 一般格点数据是按照矩形范围来切割,所以定义其经纬度范围
|
|
213
213
|
ymin: s.la1,
|
|
@@ -228,16 +228,13 @@ function Tt(n, t = {}) {
|
|
|
228
228
|
...t
|
|
229
229
|
});
|
|
230
230
|
}
|
|
231
|
-
function
|
|
231
|
+
function Mt(n, t, e, i) {
|
|
232
232
|
if (typeof document < "u") {
|
|
233
233
|
const s = document.createElement("canvas");
|
|
234
234
|
return s.width = n * e, s.height = t * e, s;
|
|
235
235
|
} else
|
|
236
236
|
return new i(n * e, t * e);
|
|
237
237
|
}
|
|
238
|
-
function Mt(n) {
|
|
239
|
-
return n ? (n.parentNode && n.parentNode.removeChild(n), n) : null;
|
|
240
|
-
}
|
|
241
238
|
class L {
|
|
242
239
|
constructor(t, e) {
|
|
243
240
|
this.u = t, this.v = e, this.m = this.magnitude();
|
|
@@ -267,24 +264,24 @@ class L {
|
|
|
267
264
|
return (this.directionTo() + 180) % 360;
|
|
268
265
|
}
|
|
269
266
|
}
|
|
270
|
-
class
|
|
267
|
+
class U {
|
|
271
268
|
constructor(t) {
|
|
272
269
|
this.grid = [], this.xmin = t.xmin, this.xmax = t.xmax, this.ymin = t.ymin, this.ymax = t.ymax, this.cols = t.cols, this.rows = t.rows, this.us = t.us, this.vs = t.vs, this.deltaX = t.deltaX, this.deltaY = t.deltaY, this.flipY = !!t.flipY, this.ymin = Math.min(t.ymax, t.ymin), this.ymax = Math.max(t.ymax, t.ymin), this.deltaY < 0 && this.ymin < this.ymax || (t.flipY === void 0 && (this.flipY = !0), console.warn("[wind-core]: The data is flipY")), this.isFields = !0;
|
|
273
270
|
const e = Math.ceil((this.xmax - this.xmin) / t.deltaX), i = Math.ceil((this.ymax - this.ymin) / t.deltaY);
|
|
274
|
-
(e !== this.cols || i !== this.rows) && console.warn("[wind-core]: The data grid not equal"), this.isContinuous = Math.floor(this.cols * t.deltaX) >= 360, this.translateX = "translateX" in t ? t.translateX : this.xmax > 180, "wrappedX" in t &&
|
|
271
|
+
(e !== this.cols || i !== this.rows) && console.warn("[wind-core]: The data grid not equal"), this.isContinuous = Math.floor(this.cols * t.deltaX) >= 360, this.translateX = "translateX" in t ? t.translateX : this.xmax > 180, "wrappedX" in t && It("[wind-core]: ", "`wrappedX` namespace will deprecated please use `translateX` instead!"), this.wrapX = !!t.wrapX, this.grid = this.buildGrid(), this.range = this.calculateRange();
|
|
275
272
|
}
|
|
276
273
|
// from https://github.com/sakitam-fdd/wind-layer/blob/95368f9433/src/windy/windy.js#L110
|
|
277
274
|
buildGrid() {
|
|
278
275
|
const t = [];
|
|
279
276
|
let e = 0;
|
|
280
|
-
const { rows: i, cols: s, us: o, vs:
|
|
281
|
-
for (let
|
|
277
|
+
const { rows: i, cols: s, us: o, vs: a } = this;
|
|
278
|
+
for (let c = 0; c < i; c++) {
|
|
282
279
|
const r = [];
|
|
283
280
|
for (let l = 0; l < s; l++, e++) {
|
|
284
|
-
const
|
|
285
|
-
r[l] = u ? new L(
|
|
281
|
+
const d = o[e], h = a[e], u = this.isValid(d) && this.isValid(h);
|
|
282
|
+
r[l] = u ? new L(d, h) : null;
|
|
286
283
|
}
|
|
287
|
-
this.isContinuous && r.push(r[0]), t[
|
|
284
|
+
this.isContinuous && r.push(r[0]), t[c] = r;
|
|
288
285
|
}
|
|
289
286
|
return t;
|
|
290
287
|
}
|
|
@@ -313,9 +310,9 @@ class B {
|
|
|
313
310
|
* @param {Number[]} g11
|
|
314
311
|
* @returns {Vector}
|
|
315
312
|
*/
|
|
316
|
-
bilinearInterpolateVector(t, e, i, s, o,
|
|
317
|
-
const
|
|
318
|
-
return new L(
|
|
313
|
+
bilinearInterpolateVector(t, e, i, s, o, a) {
|
|
314
|
+
const c = 1 - t, r = 1 - e, l = c * r, d = t * r, h = c * e, u = t * e, f = i.u * l + s.u * d + o.u * h + a.u * u, p = i.v * l + s.v * d + o.v * h + a.v * u;
|
|
315
|
+
return new L(f, p);
|
|
319
316
|
}
|
|
320
317
|
/**
|
|
321
318
|
* calculate vector value range
|
|
@@ -326,10 +323,10 @@ class B {
|
|
|
326
323
|
const t = this.grid.length, e = this.grid[0].length;
|
|
327
324
|
let i, s;
|
|
328
325
|
for (let o = 0; o < t; o++)
|
|
329
|
-
for (let
|
|
330
|
-
const
|
|
331
|
-
if (
|
|
332
|
-
const r =
|
|
326
|
+
for (let a = 0; a < e; a++) {
|
|
327
|
+
const c = this.grid[o][a];
|
|
328
|
+
if (c !== null) {
|
|
329
|
+
const r = c.m || c.magnitude();
|
|
333
330
|
i === void 0 ? i = r : s === void 0 ? (s = r, i = Math.min(i, s), s = Math.max(i, s)) : (i = Math.min(r, i), s = Math.max(r, s));
|
|
334
331
|
}
|
|
335
332
|
}
|
|
@@ -351,8 +348,8 @@ class B {
|
|
|
351
348
|
const [i, s] = this.getWrappedLongitudes();
|
|
352
349
|
s > 180 && t >= -180 && t <= s - 360 ? t += 360 : i < -180 && t <= 180 && t >= i + 360 && (t -= 360);
|
|
353
350
|
const o = t >= i && t <= s;
|
|
354
|
-
let
|
|
355
|
-
return this.deltaY >= 0 ?
|
|
351
|
+
let a;
|
|
352
|
+
return this.deltaY >= 0 ? a = e >= this.ymin && e <= this.ymax : a = e >= this.ymax && e <= this.ymin, o && a;
|
|
356
353
|
}
|
|
357
354
|
/**
|
|
358
355
|
* 获取经纬度所在的位置索引
|
|
@@ -360,7 +357,7 @@ class B {
|
|
|
360
357
|
* @param lat
|
|
361
358
|
*/
|
|
362
359
|
getDecimalIndexes(t, e) {
|
|
363
|
-
const i =
|
|
360
|
+
const i = Tt(t - this.xmin, 360) / this.deltaX;
|
|
364
361
|
if (this.flipY) {
|
|
365
362
|
const s = (this.ymax - e) / this.deltaY;
|
|
366
363
|
return [i, s];
|
|
@@ -379,8 +376,8 @@ class B {
|
|
|
379
376
|
let i = !1;
|
|
380
377
|
if ((this.wrapX || this.contains(t, e)) && (i = !0), !i)
|
|
381
378
|
return null;
|
|
382
|
-
const s = this.getDecimalIndexes(t, e), o = Math.floor(s[0]),
|
|
383
|
-
return this.valueAtIndexes(
|
|
379
|
+
const s = this.getDecimalIndexes(t, e), o = Math.floor(s[0]), a = Math.floor(s[1]), c = this.clampColumnIndex(o), r = this.clampRowIndex(a);
|
|
380
|
+
return this.valueAtIndexes(c, r);
|
|
384
381
|
}
|
|
385
382
|
/**
|
|
386
383
|
* Get interpolated grid value lon-lat coordinates
|
|
@@ -404,10 +401,10 @@ class B {
|
|
|
404
401
|
* @param j
|
|
405
402
|
*/
|
|
406
403
|
interpolatePoint(t, e) {
|
|
407
|
-
const i = this.getFourSurroundingIndexes(t, e), [s, o,
|
|
404
|
+
const i = this.getFourSurroundingIndexes(t, e), [s, o, a, c] = i, r = this.getFourSurroundingValues(s, o, a, c);
|
|
408
405
|
if (r) {
|
|
409
|
-
const [l,
|
|
410
|
-
return this.bilinearInterpolateVector(t - s, e -
|
|
406
|
+
const [l, d, h, u] = r;
|
|
407
|
+
return this.bilinearInterpolateVector(t - s, e - a, l, d, h, u);
|
|
411
408
|
}
|
|
412
409
|
return null;
|
|
413
410
|
}
|
|
@@ -448,8 +445,8 @@ class B {
|
|
|
448
445
|
const i = Math.floor(t);
|
|
449
446
|
let s = i + 1;
|
|
450
447
|
this.isContinuous && s >= this.cols && (s = 0), s = this.clampColumnIndex(s);
|
|
451
|
-
const o = this.clampRowIndex(Math.floor(e)),
|
|
452
|
-
return [i, s, o,
|
|
448
|
+
const o = this.clampRowIndex(Math.floor(e)), a = this.clampRowIndex(o + 1);
|
|
449
|
+
return [i, s, o, a];
|
|
453
450
|
}
|
|
454
451
|
/**
|
|
455
452
|
* Get four surrounding values or null if not available,
|
|
@@ -464,11 +461,11 @@ class B {
|
|
|
464
461
|
getFourSurroundingValues(t, e, i, s) {
|
|
465
462
|
let o;
|
|
466
463
|
if (o = this.grid[i]) {
|
|
467
|
-
const
|
|
468
|
-
if (this.isValid(
|
|
464
|
+
const a = o[t], c = o[e];
|
|
465
|
+
if (this.isValid(a) && this.isValid(c) && (o = this.grid[s])) {
|
|
469
466
|
const r = o[t], l = o[e];
|
|
470
467
|
if (this.isValid(r) && this.isValid(l))
|
|
471
|
-
return [
|
|
468
|
+
return [a, c, r, l];
|
|
472
469
|
}
|
|
473
470
|
}
|
|
474
471
|
return null;
|
|
@@ -520,8 +517,8 @@ class B {
|
|
|
520
517
|
* @return IPosition
|
|
521
518
|
*/
|
|
522
519
|
randomize(t = {}, e, i, s) {
|
|
523
|
-
const o = Math.random() * (e || this.cols) | 0,
|
|
524
|
-
return
|
|
520
|
+
const o = Math.random() * (e || this.cols) | 0, a = Math.random() * (i || this.rows) | 0, c = s([o, a]);
|
|
521
|
+
return c !== null ? (t.x = c[0], t.y = c[1]) : (t.x = this.longitudeAtX(o), t.y = this.latitudeAtY(a)), t;
|
|
525
522
|
}
|
|
526
523
|
/**
|
|
527
524
|
* 判断是否是 `Field` 的实例
|
|
@@ -531,7 +528,7 @@ class B {
|
|
|
531
528
|
return this.isFields;
|
|
532
529
|
}
|
|
533
530
|
}
|
|
534
|
-
const
|
|
531
|
+
const W = {
|
|
535
532
|
globalAlpha: 0.9,
|
|
536
533
|
// 全局透明度
|
|
537
534
|
lineWidth: 1,
|
|
@@ -549,7 +546,7 @@ const U = {
|
|
|
549
546
|
function R(n, t, e, i) {
|
|
550
547
|
return Math.max(0, Math.min(i.length - 1, Math.round((n - t) / (e - t) * (i.length - 1))));
|
|
551
548
|
}
|
|
552
|
-
const
|
|
549
|
+
const O = class O {
|
|
553
550
|
constructor(t, e, i) {
|
|
554
551
|
if (this.particles = [], this.generated = !1, this.ctx = t, !this.ctx)
|
|
555
552
|
throw new Error("ctx error");
|
|
@@ -560,7 +557,7 @@ const S = class S {
|
|
|
560
557
|
* @param options
|
|
561
558
|
*/
|
|
562
559
|
setOptions(t) {
|
|
563
|
-
this.options = { ...
|
|
560
|
+
this.options = { ...W, ...t };
|
|
564
561
|
const { width: e, height: i } = this.ctx.canvas;
|
|
565
562
|
"particleAge" in t && !("maxAge" in t) && A(this.options.particleAge) && (this.options.maxAge = this.options.particleAge), "particleMultiplier" in t && !("paths" in t) && A(this.options.particleMultiplier) && (this.options.paths = Math.round(e * i * this.options.particleMultiplier)), this.prerender();
|
|
566
563
|
}
|
|
@@ -636,18 +633,18 @@ const S = class S {
|
|
|
636
633
|
postrender() {
|
|
637
634
|
}
|
|
638
635
|
moveParticles() {
|
|
639
|
-
const { width: t, height: e } = this.ctx.canvas, i = this.particles, s = this.options.maxAge, o =
|
|
640
|
-
let
|
|
641
|
-
const
|
|
642
|
-
for (;
|
|
643
|
-
const r = i[
|
|
636
|
+
const { width: t, height: e } = this.ctx.canvas, i = this.particles, s = this.options.maxAge, o = x(this.options.velocityScale) ? this.options.velocityScale() : this.options.velocityScale;
|
|
637
|
+
let a = 0;
|
|
638
|
+
const c = i.length;
|
|
639
|
+
for (; a < c; a++) {
|
|
640
|
+
const r = i[a];
|
|
644
641
|
r.age > s && (r.age = 0, this.field.randomize(r, t, e, this.unproject));
|
|
645
|
-
const l = r.x,
|
|
642
|
+
const l = r.x, d = r.y, h = this.field.interpolatedValueAt(l, d);
|
|
646
643
|
if (h === null)
|
|
647
644
|
r.age = s;
|
|
648
645
|
else {
|
|
649
|
-
const u = l + h.u * o,
|
|
650
|
-
this.field.hasValueAt(u,
|
|
646
|
+
const u = l + h.u * o, f = d + h.v * o;
|
|
647
|
+
this.field.hasValueAt(u, f) ? (r.xt = u, r.yt = f, r.m = h.m) : (r.x = u, r.y = f, r.age = s);
|
|
651
648
|
}
|
|
652
649
|
r.age++;
|
|
653
650
|
}
|
|
@@ -676,13 +673,13 @@ const S = class S {
|
|
|
676
673
|
drawPixelParticle(t, e, i) {
|
|
677
674
|
const s = [t.x, t.y], o = [t.xt, t.yt];
|
|
678
675
|
if (o && s && g(o[0]) && g(o[1]) && g(s[0]) && g(s[1]) && t.age <= this.options.maxAge) {
|
|
679
|
-
if (this.ctx.beginPath(), this.ctx.moveTo(s[0], s[1]), this.ctx.lineTo(o[0], o[1]),
|
|
676
|
+
if (this.ctx.beginPath(), this.ctx.moveTo(s[0], s[1]), this.ctx.lineTo(o[0], o[1]), x(this.options.colorScale))
|
|
680
677
|
this.ctx.strokeStyle = this.options.colorScale(t.m);
|
|
681
678
|
else if (Array.isArray(this.options.colorScale)) {
|
|
682
|
-
const
|
|
683
|
-
this.ctx.strokeStyle = this.options.colorScale[
|
|
679
|
+
const a = R(t.m, e, i, this.options.colorScale);
|
|
680
|
+
this.ctx.strokeStyle = this.options.colorScale[a];
|
|
684
681
|
}
|
|
685
|
-
|
|
682
|
+
x(this.options.lineWidth) && (this.ctx.lineWidth = this.options.lineWidth(t.m)), t.x = t.xt, t.y = t.yt, this.ctx.stroke();
|
|
686
683
|
}
|
|
687
684
|
}
|
|
688
685
|
/**
|
|
@@ -694,15 +691,15 @@ const S = class S {
|
|
|
694
691
|
drawCoordsParticle(t, e, i) {
|
|
695
692
|
const s = [t.x, t.y], o = [t.xt, t.yt];
|
|
696
693
|
if (o && s && g(o[0]) && g(o[1]) && g(s[0]) && g(s[1]) && this.intersectsCoordinate(o) && t.age <= this.options.maxAge) {
|
|
697
|
-
const
|
|
698
|
-
if (
|
|
699
|
-
if (this.ctx.beginPath(), this.ctx.moveTo(
|
|
694
|
+
const a = this.project(s), c = this.project(o);
|
|
695
|
+
if (a && c) {
|
|
696
|
+
if (this.ctx.beginPath(), this.ctx.moveTo(a[0], a[1]), this.ctx.lineTo(c[0], c[1]), t.x = t.xt, t.y = t.yt, x(this.options.colorScale))
|
|
700
697
|
this.ctx.strokeStyle = this.options.colorScale(t.m);
|
|
701
698
|
else if (Array.isArray(this.options.colorScale)) {
|
|
702
699
|
const r = R(t.m, e, i, this.options.colorScale);
|
|
703
700
|
this.ctx.strokeStyle = this.options.colorScale[r];
|
|
704
701
|
}
|
|
705
|
-
|
|
702
|
+
x(this.options.lineWidth) && (this.ctx.lineWidth = this.options.lineWidth(t.m)), this.ctx.stroke();
|
|
706
703
|
}
|
|
707
704
|
}
|
|
708
705
|
}
|
|
@@ -728,13 +725,13 @@ const S = class S {
|
|
|
728
725
|
return Math.floor(Math.random() * this.options.maxAge);
|
|
729
726
|
}
|
|
730
727
|
};
|
|
731
|
-
|
|
732
|
-
let
|
|
733
|
-
class
|
|
728
|
+
O.Field = U;
|
|
729
|
+
let S = O;
|
|
730
|
+
class B extends G {
|
|
734
731
|
constructor() {
|
|
735
732
|
super(...arguments);
|
|
736
|
-
|
|
737
|
-
...
|
|
733
|
+
j(this, "_defaultOptions", {
|
|
734
|
+
...W
|
|
738
735
|
});
|
|
739
736
|
}
|
|
740
737
|
initializeState() {
|
|
@@ -744,32 +741,33 @@ class Ft extends $ {
|
|
|
744
741
|
return e.somethingChanged;
|
|
745
742
|
}
|
|
746
743
|
updateState({ props: e, oldProps: i, context: s }) {
|
|
747
|
-
var
|
|
748
|
-
const { bounds: o, wind:
|
|
744
|
+
var d;
|
|
745
|
+
const { bounds: o, wind: a, windOptions: c } = this.state, r = (o == null ? void 0 : o.reduce((h, u) => h + u, 0)) || 0, l = ((d = s.viewport.getBounds()) == null ? void 0 : d.reduce((h, u) => h + u, 0)) || 0;
|
|
749
746
|
if (r !== l && this.setState({
|
|
750
747
|
bounds: s.viewport.getBounds()
|
|
751
|
-
}), (i == null ? void 0 : i.data) !== (e == null ? void 0 : e.data) && this.setData(e.data, (e == null ? void 0 : e.fieldOptions) || {}), (i == null ? void 0 : i.
|
|
752
|
-
const h = Object.assign({},
|
|
753
|
-
|
|
748
|
+
}), (i == null ? void 0 : i.data) !== (e == null ? void 0 : e.data) && this.setData(e.data, (e == null ? void 0 : e.fieldOptions) || {}), (i == null ? void 0 : i.visible) !== e.visible && this.setVisible(e.visible), (i == null ? void 0 : i.zIndex) !== e.zIndex && this.setzIndex(String(e.zIndex) || "unset"), !wt(c, e == null ? void 0 : e.windOptions)) {
|
|
749
|
+
const h = Object.assign({}, c, e.windOptions);
|
|
750
|
+
a.setOptions(h), this.setState({
|
|
754
751
|
windOptions: h
|
|
755
752
|
});
|
|
756
753
|
}
|
|
757
754
|
}
|
|
758
755
|
intersectsCoordinate([e, i]) {
|
|
759
|
-
const [s, o,
|
|
760
|
-
return e >= s && e <=
|
|
756
|
+
const [s, o, a, c] = this.state.bounds;
|
|
757
|
+
return e >= s && e <= a && i >= o && i <= c;
|
|
761
758
|
}
|
|
762
759
|
init() {
|
|
763
|
-
var I, T, C, M, F,
|
|
764
|
-
const { viewport: e, deck: i } = this.context, s = i == null ? void 0 : i.width, o = i == null ? void 0 : i.height,
|
|
765
|
-
|
|
766
|
-
const r =
|
|
767
|
-
|
|
768
|
-
const
|
|
769
|
-
|
|
760
|
+
var I, T, C, M, F, P, X;
|
|
761
|
+
const { viewport: e, deck: i } = this.context, s = i == null ? void 0 : i.width, o = i == null ? void 0 : i.height, a = this.getDevicePixelRatio(), c = this.state.canvas ?? Mt(s, o, a);
|
|
762
|
+
c.style.position = "absolute", c.style.top = "0px", c.style.left = "0px", c.style.right = "0px", c.style.bottom = "0px", c.style.width = `${s}px`, c.style.height = `${o}px`, c.style.display = (I = this.props) != null && I.visible ? "block" : "none", c.style.zIndex = ((C = (T = this.props) == null ? void 0 : T.zIndex) == null ? void 0 : C.toString()) || "unset", c.id = "windy-layer-canvas";
|
|
763
|
+
const r = c.getContext("2d"), l = e.getBounds(), d = (M = this.props) == null ? void 0 : M.data, h = Object.assign(this._defaultOptions, ((F = this.props) == null ? void 0 : F.windOptions) || {}), u = ((P = this.props) == null ? void 0 : P.fieldOptions) || null, f = this.checkData(d, u), p = new S(r, h, f);
|
|
764
|
+
p.postrender = this.postrender.bind(this), p.project = this.cproject.bind(this), p.unproject = this.cunproject.bind(this), p.intersectsCoordinate = this.intersectsCoordinate.bind(this);
|
|
765
|
+
const b = (X = i == null ? void 0 : i.getCanvas()) == null ? void 0 : X.parentNode;
|
|
766
|
+
b && !b.querySelector("#windy-layer-canvas") && b.appendChild(c), this.setState({
|
|
770
767
|
bounds: l,
|
|
771
|
-
canvas:
|
|
772
|
-
wind:
|
|
768
|
+
canvas: c,
|
|
769
|
+
wind: p,
|
|
770
|
+
container: b,
|
|
773
771
|
windOpitons: h
|
|
774
772
|
});
|
|
775
773
|
}
|
|
@@ -787,15 +785,15 @@ class Ft extends $ {
|
|
|
787
785
|
(i = (e = this.props) == null ? void 0 : e.onPostRender) == null || i.call(e, this);
|
|
788
786
|
}
|
|
789
787
|
cproject([e, i]) {
|
|
790
|
-
const s = this.getDevicePixelRatio(), [o,
|
|
791
|
-
return [o * s,
|
|
788
|
+
const s = this.getDevicePixelRatio(), [o, a] = this.context.viewport.project([e, i, 0]);
|
|
789
|
+
return [o * s, a * s];
|
|
792
790
|
}
|
|
793
791
|
cunproject([e, i]) {
|
|
794
792
|
const s = this.context.viewport.unproject([e, i]);
|
|
795
793
|
return s ? [s[0], s[1]] : null;
|
|
796
794
|
}
|
|
797
795
|
checkData(e, i) {
|
|
798
|
-
return typeof e == "string" ? null : e && e.checkFields && e.checkFields() ? e :
|
|
796
|
+
return typeof e == "string" ? null : e && e.checkFields && e.checkFields() ? e : St(e) ? Ct(e, i) : (console.error("Illegal data"), null);
|
|
799
797
|
}
|
|
800
798
|
setData(e, i) {
|
|
801
799
|
const s = this.checkData(e, i);
|
|
@@ -804,8 +802,8 @@ class Ft extends $ {
|
|
|
804
802
|
}), this.state.wind.updateData(s), this.state.wind.prerender();
|
|
805
803
|
}
|
|
806
804
|
destory() {
|
|
807
|
-
const { wind: e } = this.state;
|
|
808
|
-
e == null || e.stop(), e == null || e.clearCanvas(),
|
|
805
|
+
const { wind: e, container: i } = this.state;
|
|
806
|
+
e == null || e.stop(), e == null || e.clearCanvas(), i && i.removeChild(this.state.canvas), this.setState({
|
|
809
807
|
canvas: null,
|
|
810
808
|
wind: null,
|
|
811
809
|
bounds: null,
|
|
@@ -817,7 +815,7 @@ class Ft extends $ {
|
|
|
817
815
|
this.destory();
|
|
818
816
|
}
|
|
819
817
|
}
|
|
820
|
-
|
|
818
|
+
j(B, "layerName", "WindyLayer"), j(B, "componentName", "WindyLayer");
|
|
821
819
|
export {
|
|
822
|
-
|
|
820
|
+
B as WindyLayer
|
|
823
821
|
};
|
package/dist/lib/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(d,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("@deck.gl/core")):typeof define=="function"&&define.amd?define(["exports","@deck.gl/core"],g):(d=typeof globalThis<"u"?globalThis:d||self,g(d["deckgl-expansion"]={},d.Deck["gl/core"]))})(this,function(d,g){"use strict";var Ft=Object.defineProperty;var Dt=(d,g,w)=>g in d?Ft(d,g,{enumerable:!0,configurable:!0,writable:!0,value:w}):d[g]=w;var I=(d,g,w)=>Dt(d,typeof g!="symbol"?g+"":g,w);function w(){}function C(n){return Object.getOwnPropertySymbols(n).filter(t=>Object.prototype.propertyIsEnumerable.call(n,t))}function M(n){return n==null?n===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(n)}const G="[object RegExp]",q="[object String]",K="[object Number]",Z="[object Boolean]",F="[object Arguments]",_="[object Symbol]",H="[object Date]",J="[object Map]",Q="[object Set]",tt="[object Array]",et="[object Function]",it="[object ArrayBuffer]",A="[object Object]",nt="[object Error]",st="[object DataView]",ot="[object Uint8Array]",rt="[object Uint8ClampedArray]",ct="[object Uint16Array]",at="[object Uint32Array]",lt="[object BigUint64Array]",ht="[object Int8Array]",ut="[object Int16Array]",ft="[object Int32Array]",dt="[object BigInt64Array]",gt="[object Float32Array]",yt="[object Float64Array]";function D(n){if(!n||typeof n!="object")return!1;const t=Object.getPrototypeOf(n);return t===null||t===Object.prototype||Object.getPrototypeOf(t)===null?Object.prototype.toString.call(n)==="[object Object]":!1}function xt(n,t){return n===t||Number.isNaN(n)&&Number.isNaN(t)}function pt(n,t,e){return b(n,t,void 0,void 0,void 0,void 0,e)}function b(n,t,e,i,s,o,c){const a=c(n,t,e,i,s,o);if(a!==void 0)return a;if(typeof n==typeof t)switch(typeof n){case"bigint":case"string":case"boolean":case"symbol":case"undefined":return n===t;case"number":return n===t||Object.is(n,t);case"function":return n===t;case"object":return j(n,t,o,c)}return j(n,t,o,c)}function j(n,t,e,i){if(Object.is(n,t))return!0;let s=M(n),o=M(t);if(s===F&&(s=A),o===F&&(o=A),s!==o)return!1;switch(s){case q:return n.toString()===t.toString();case K:{const r=n.valueOf(),l=t.valueOf();return xt(r,l)}case Z:case H:case _:return Object.is(n.valueOf(),t.valueOf());case G:return n.source===t.source&&n.flags===t.flags;case et:return n===t}e=e??new Map;const c=e.get(n),a=e.get(t);if(c!=null&&a!=null)return c===t;e.set(n,t),e.set(t,n);try{switch(s){case J:{if(n.size!==t.size)return!1;for(const[r,l]of n.entries())if(!t.has(r)||!b(l,t.get(r),r,n,t,e,i))return!1;return!0}case Q:{if(n.size!==t.size)return!1;const r=Array.from(n.values()),l=Array.from(t.values());for(let f=0;f<r.length;f++){const h=r[f],u=l.findIndex(y=>b(h,y,void 0,n,t,e,i));if(u===-1)return!1;l.splice(u,1)}return!0}case tt:case ot:case rt:case ct:case at:case lt:case ht:case ut:case ft:case dt:case gt:case yt:{if(typeof Buffer<"u"&&Buffer.isBuffer(n)!==Buffer.isBuffer(t)||n.length!==t.length)return!1;for(let r=0;r<n.length;r++)if(!b(n[r],t[r],r,n,t,e,i))return!1;return!0}case it:return n.byteLength!==t.byteLength?!1:j(new Uint8Array(n),new Uint8Array(t),e,i);case st:return n.byteLength!==t.byteLength||n.byteOffset!==t.byteOffset?!1:j(new Uint8Array(n),new Uint8Array(t),e,i);case nt:return n.name===t.name&&n.message===t.message;case A:{if(!(j(n.constructor,t.constructor,e,i)||D(n)&&D(t)))return!1;const l=[...Object.keys(n),...C(n)],f=[...Object.keys(t),...C(t)];if(l.length!==f.length)return!1;for(let h=0;h<l.length;h++){const u=l[h],y=n[u];if(!Object.hasOwn(t,u))return!1;const p=t[u];if(!b(y,p,u,n,t,e,i))return!1}return!0}default:return!1}}finally{e.delete(n),e.delete(t)}}function mt(n,t){return pt(n,t,w)}const wt=Object.prototype.hasOwnProperty,m=typeof Symbol<"u"?Symbol.toStringTag:void 0;function bt(n){if(n===null)return n===void 0?"[object Undefined]":"[object Null]";if(!(m&&m in Object(n)))return toString.call(n);const t=wt.call(n,m),e=n[m];let i=!1;try{n[m]=void 0,i=!0}catch{}const s=Object.prototype.toString.call(n);return i&&(t?n[m]=e:delete n[m]),s}function v(n){if(!jt(n))return!1;const t=bt(n);return t==="[object Function]"||t==="[object AsyncFunction]"||t==="[object GeneratorFunction]"||t==="[object Proxy]"}function jt(n){const t=typeof n;return n!==null&&(t==="object"||t==="function")}function vt(n){return n==null?!1:typeof n=="string"||n.constructor!==null&&n.constructor===String}function S(n){return Object.prototype.toString.call(n)==="[object Number]"&&!isNaN(n)}function At(n){return Array.isArray(n)}function St(n,t){console.warn(`${t}: ${n}`)}const X={};function Ot(n,t){X[t]||(St(t,n),X[t]=!0)}function Tt(n,t){return n-t*Math.floor(n/t)}function x(n){return n!=null&&!isNaN(n)}function It(n,t={}){let e,i;if(n.forEach(function(c){switch(c.header.parameterCategory+","+c.header.parameterNumber){case"1,2":case"2,2":e=c;break;case"1,3":case"2,3":i=c;break}}),!i||!e)return;const s=e.header;return new P({xmin:s.lo1,ymin:s.la1,xmax:s.lo2,ymax:s.la2,deltaX:s.dx,deltaY:s.dy,cols:s.nx,rows:s.ny,us:e.data,vs:i.data,...t})}function Ct(n,t,e,i){if(typeof document<"u"){const s=document.createElement("canvas");return s.width=n*e,s.height=t*e,s}else return new i(n*e,t*e)}function Mt(n){return n?(n.parentNode&&n.parentNode.removeChild(n),n):null}class N{constructor(t,e){this.u=t,this.v=e,this.m=this.magnitude()}magnitude(){return Math.sqrt(this.u**2+this.v**2)}directionTo(){let e=Math.atan2(this.u,this.v)*(180/Math.PI);return e<0&&(e+=360),e}directionFrom(){return(this.directionTo()+180)%360}}class P{constructor(t){this.grid=[],this.xmin=t.xmin,this.xmax=t.xmax,this.ymin=t.ymin,this.ymax=t.ymax,this.cols=t.cols,this.rows=t.rows,this.us=t.us,this.vs=t.vs,this.deltaX=t.deltaX,this.deltaY=t.deltaY,this.flipY=!!t.flipY,this.ymin=Math.min(t.ymax,t.ymin),this.ymax=Math.max(t.ymax,t.ymin),this.deltaY<0&&this.ymin<this.ymax||(t.flipY===void 0&&(this.flipY=!0),console.warn("[wind-core]: The data is flipY")),this.isFields=!0;const e=Math.ceil((this.xmax-this.xmin)/t.deltaX),i=Math.ceil((this.ymax-this.ymin)/t.deltaY);(e!==this.cols||i!==this.rows)&&console.warn("[wind-core]: The data grid not equal"),this.isContinuous=Math.floor(this.cols*t.deltaX)>=360,this.translateX="translateX"in t?t.translateX:this.xmax>180,"wrappedX"in t&&Ot("[wind-core]: ","`wrappedX` namespace will deprecated please use `translateX` instead!"),this.wrapX=!!t.wrapX,this.grid=this.buildGrid(),this.range=this.calculateRange()}buildGrid(){const t=[];let e=0;const{rows:i,cols:s,us:o,vs:c}=this;for(let a=0;a<i;a++){const r=[];for(let l=0;l<s;l++,e++){const f=o[e],h=c[e],u=this.isValid(f)&&this.isValid(h);r[l]=u?new N(f,h):null}this.isContinuous&&r.push(r[0]),t[a]=r}return t}release(){this.grid=[]}extent(){return[this.xmin,this.ymin,this.xmax,this.ymax]}bilinearInterpolateVector(t,e,i,s,o,c){const a=1-t,r=1-e,l=a*r,f=t*r,h=a*e,u=t*e,y=i.u*l+s.u*f+o.u*h+c.u*u,p=i.v*l+s.v*f+o.v*h+c.v*u;return new N(y,p)}calculateRange(){if(!this.grid||!this.grid[0])return;const t=this.grid.length,e=this.grid[0].length;let i,s;for(let o=0;o<t;o++)for(let c=0;c<e;c++){const a=this.grid[o][c];if(a!==null){const r=a.m||a.magnitude();i===void 0?i=r:s===void 0?(s=r,i=Math.min(i,s),s=Math.max(i,s)):(i=Math.min(r,i),s=Math.max(r,s))}}return[i,s]}isValid(t){return t!=null}getWrappedLongitudes(){let t=this.xmin,e=this.xmax;return this.translateX&&(this.isContinuous?(t=-180,e=180):(e=this.xmax-360,t=this.xmin-360)),[t,e]}contains(t,e){const[i,s]=this.getWrappedLongitudes();s>180&&t>=-180&&t<=s-360?t+=360:i<-180&&t<=180&&t>=i+360&&(t-=360);const o=t>=i&&t<=s;let c;return this.deltaY>=0?c=e>=this.ymin&&e<=this.ymax:c=e>=this.ymax&&e<=this.ymin,o&&c}getDecimalIndexes(t,e){const i=Tt(t-this.xmin,360)/this.deltaX;if(this.flipY){const s=(this.ymax-e)/this.deltaY;return[i,s]}else{const s=(this.ymin+e)/this.deltaY;return[i,s]}}valueAt(t,e){let i=!1;if((this.wrapX||this.contains(t,e))&&(i=!0),!i)return null;const s=this.getDecimalIndexes(t,e),o=Math.floor(s[0]),c=Math.floor(s[1]),a=this.clampColumnIndex(o),r=this.clampRowIndex(c);return this.valueAtIndexes(a,r)}interpolatedValueAt(t,e){let i=!1;if((this.wrapX||this.contains(t,e))&&(i=!0),!i)return null;const[s,o]=this.getDecimalIndexes(t,e);return this.interpolatePoint(s,o)}hasValueAt(t,e){return this.valueAt(t,e)!==null}interpolatePoint(t,e){const i=this.getFourSurroundingIndexes(t,e),[s,o,c,a]=i,r=this.getFourSurroundingValues(s,o,c,a);if(r){const[l,f,h,u]=r;return this.bilinearInterpolateVector(t-s,e-c,l,f,h,u)}return null}clampColumnIndex(t){let e=t;t<0&&(e=0);const i=this.cols-1;return t>i&&(e=i),e}clampRowIndex(t){let e=t;t<0&&(e=0);const i=this.rows-1;return t>i&&(e=i),e}getFourSurroundingIndexes(t,e){const i=Math.floor(t);let s=i+1;this.isContinuous&&s>=this.cols&&(s=0),s=this.clampColumnIndex(s);const o=this.clampRowIndex(Math.floor(e)),c=this.clampRowIndex(o+1);return[i,s,o,c]}getFourSurroundingValues(t,e,i,s){let o;if(o=this.grid[i]){const c=o[t],a=o[e];if(this.isValid(c)&&this.isValid(a)&&(o=this.grid[s])){const r=o[t],l=o[e];if(this.isValid(r)&&this.isValid(l))return[c,a,r,l]}}return null}valueAtIndexes(t,e){return this.grid[e][t]}lonLatAtIndexes(t,e){const i=this.longitudeAtX(t),s=this.latitudeAtY(e);return[i,s]}longitudeAtX(t){const e=this.deltaX/2;let i=this.xmin+e+t*this.deltaX;return this.translateX&&(i=i>180?i-360:i),i}latitudeAtY(t){const e=this.deltaY/2;return this.ymax-e-t*this.deltaY}randomize(t={},e,i,s){const o=Math.random()*(e||this.cols)|0,c=Math.random()*(i||this.rows)|0,a=s([o,c]);return a!==null?(t.x=a[0],t.y=a[1]):(t.x=this.longitudeAtX(o),t.y=this.latitudeAtY(c)),t}checkFields(){return this.isFields}}const V={globalAlpha:.9,lineWidth:1,colorScale:"#fff",velocityScale:1/25,maxAge:90,paths:800,frameRate:20,useCoordsDraw:!0};function Y(n,t,e,i){return Math.max(0,Math.min(i.length-1,Math.round((n-t)/(e-t)*(i.length-1))))}const T=class T{constructor(t,e,i){if(this.particles=[],this.generated=!1,this.ctx=t,!this.ctx)throw new Error("ctx error");this.animate=this.animate.bind(this),this.setOptions(e),i&&this.updateData(i)}setOptions(t){this.options={...V,...t};const{width:e,height:i}=this.ctx.canvas;"particleAge"in t&&!("maxAge"in t)&&S(this.options.particleAge)&&(this.options.maxAge=this.options.particleAge),"particleMultiplier"in t&&!("paths"in t)&&S(this.options.particleMultiplier)&&(this.options.paths=Math.round(e*i*this.options.particleMultiplier)),this.prerender()}getOptions(){return this.options}updateData(t){this.field=t,this.generated&&(this.particles=this.prepareParticlePaths())}project(...t){throw new Error("project must be overriden")}unproject(...t){throw new Error("unproject must be overriden")}intersectsCoordinate(t){throw new Error("must be overriden")}clearCanvas(){this.stop(),this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.forceStop=!1}isStop(){return!this.starting}start(){this.starting=!0,this.forceStop=!1,this.then=Date.now(),this.animate()}stop(){cancelAnimationFrame(this.animationLoop),this.starting=!1,this.forceStop=!0}animate(){this.animationLoop&&cancelAnimationFrame(this.animationLoop),this.animationLoop=requestAnimationFrame(this.animate);const t=Date.now(),e=t-this.then;e>this.options.frameRate&&(this.then=t-e%this.options.frameRate,this.render())}prerender(){this.generated=!1,this.field&&(this.particles=this.prepareParticlePaths(),this.generated=!0,!this.starting&&!this.forceStop&&(this.starting=!0,this.then=Date.now(),this.animate()))}render(){this.moveParticles(),this.drawParticles(),this.postrender()}postrender(){}moveParticles(){const{width:t,height:e}=this.ctx.canvas,i=this.particles,s=this.options.maxAge,o=v(this.options.velocityScale)?this.options.velocityScale():this.options.velocityScale;let c=0;const a=i.length;for(;c<a;c++){const r=i[c];r.age>s&&(r.age=0,this.field.randomize(r,t,e,this.unproject));const l=r.x,f=r.y,h=this.field.interpolatedValueAt(l,f);if(h===null)r.age=s;else{const u=l+h.u*o,y=f+h.v*o;this.field.hasValueAt(u,y)?(r.xt=u,r.yt=y,r.m=h.m):(r.x=u,r.y=y,r.age=s)}r.age++}}fadeIn(){const t=this.ctx.globalCompositeOperation;this.ctx.globalCompositeOperation="destination-in",this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.globalCompositeOperation=t}drawParticles(){const t=this.particles;this.fadeIn(),this.ctx.globalAlpha=this.options.globalAlpha,this.ctx.fillStyle=`rgba(0, 0, 0, ${this.options.globalAlpha})`,this.ctx.lineWidth=S(this.options.lineWidth)?this.options.lineWidth:1,this.ctx.strokeStyle=vt(this.options.colorScale)?this.options.colorScale:"#fff";let e=0;const i=t.length;if(this.field&&i>0){let s,o;for(x(this.options.minVelocity)&&x(this.options.maxVelocity)?(s=this.options.minVelocity,o=this.options.maxVelocity):[s,o]=this.field.range;e<i;e++)this[this.options.useCoordsDraw?"drawCoordsParticle":"drawPixelParticle"](t[e],s,o)}}drawPixelParticle(t,e,i){const s=[t.x,t.y],o=[t.xt,t.yt];if(o&&s&&x(o[0])&&x(o[1])&&x(s[0])&&x(s[1])&&t.age<=this.options.maxAge){if(this.ctx.beginPath(),this.ctx.moveTo(s[0],s[1]),this.ctx.lineTo(o[0],o[1]),v(this.options.colorScale))this.ctx.strokeStyle=this.options.colorScale(t.m);else if(Array.isArray(this.options.colorScale)){const c=Y(t.m,e,i,this.options.colorScale);this.ctx.strokeStyle=this.options.colorScale[c]}v(this.options.lineWidth)&&(this.ctx.lineWidth=this.options.lineWidth(t.m)),t.x=t.xt,t.y=t.yt,this.ctx.stroke()}}drawCoordsParticle(t,e,i){const s=[t.x,t.y],o=[t.xt,t.yt];if(o&&s&&x(o[0])&&x(o[1])&&x(s[0])&&x(s[1])&&this.intersectsCoordinate(o)&&t.age<=this.options.maxAge){const c=this.project(s),a=this.project(o);if(c&&a){if(this.ctx.beginPath(),this.ctx.moveTo(c[0],c[1]),this.ctx.lineTo(a[0],a[1]),t.x=t.xt,t.y=t.yt,v(this.options.colorScale))this.ctx.strokeStyle=this.options.colorScale(t.m);else if(Array.isArray(this.options.colorScale)){const r=Y(t.m,e,i,this.options.colorScale);this.ctx.strokeStyle=this.options.colorScale[r]}v(this.options.lineWidth)&&(this.ctx.lineWidth=this.options.lineWidth(t.m)),this.ctx.stroke()}}}prepareParticlePaths(){const{width:t,height:e}=this.ctx.canvas,i=typeof this.options.paths=="function"?this.options.paths(this):this.options.paths,s=[];if(!this.field)return[];let o=0;for(;o<i;o++)s.push(this.field.randomize({age:this.randomize()},t,e,this.unproject));return s}randomize(){return Math.floor(Math.random()*this.options.maxAge)}};T.Field=P;let O=T;class z extends g.Layer{constructor(){super(...arguments);I(this,"_defaultOptions",{...V})}initializeState(){this.init()}shouldUpdateState({changeFlags:e}){return e.somethingChanged}updateState({props:e,oldProps:i,context:s}){var f;const{bounds:o,wind:c,windOptions:a}=this.state,r=(o==null?void 0:o.reduce((h,u)=>h+u,0))||0,l=((f=s.viewport.getBounds())==null?void 0:f.reduce((h,u)=>h+u,0))||0;if(r!==l&&this.setState({bounds:s.viewport.getBounds()}),(i==null?void 0:i.data)!==(e==null?void 0:e.data)&&this.setData(e.data,(e==null?void 0:e.fieldOptions)||{}),(i==null?void 0:i.windOptions)!==(e==null?void 0:e.windOptions)&&this.init(),(i==null?void 0:i.visible)!==e.visible&&this.setVisible(e.visible),(i==null?void 0:i.zIndex)!==e.zIndex&&this.setzIndex(String(e.zIndex)||"unset"),!mt(a,e==null?void 0:e.windOptions)){const h=Object.assign({},a,e.windOptions);c.setOptions(h),this.setState({windOptions:h})}}intersectsCoordinate([e,i]){const[s,o,c,a]=this.state.bounds;return e>=s&&e<=c&&i>=o&&i<=a}init(){var R,B,W,U,E,k,$;const{viewport:e,deck:i}=this.context,s=i==null?void 0:i.width,o=i==null?void 0:i.height,c=this.getDevicePixelRatio(),a=Ct(s,o,c);a.style.position="absolute",a.style.top="0px",a.style.left="0px",a.style.right="0px",a.style.bottom="0px",a.style.width=`${s}px`,a.style.height=`${o}px`,a.style.display=(R=this.props)!=null&&R.visible?"block":"none",a.style.zIndex=((W=(B=this.props)==null?void 0:B.zIndex)==null?void 0:W.toString())||"unset";const r=a.getContext("2d"),l=e.getBounds(),f=(U=this.props)==null?void 0:U.data,h=Object.assign(this._defaultOptions,((E=this.props)==null?void 0:E.windOptions)||{}),u=((k=this.props)==null?void 0:k.fieldOptions)||null,y=this.checkData(f,u),p=new O(r,h,y);p.postrender=this.postrender.bind(this),p.project=this.cproject.bind(this),p.unproject=this.cunproject.bind(this),p.intersectsCoordinate=this.intersectsCoordinate.bind(this);const L=($=i==null?void 0:i.getCanvas())==null?void 0:$.parentNode;L&&L.appendChild(a),this.setState({bounds:l,canvas:a,wind:p,windOpitons:h})}setVisible(e){this.state.canvas.style.display=e?"block":"none"}setzIndex(e){this.state.canvas.style.zIndex=String(e)||"unset"}getDevicePixelRatio(){return(window==null?void 0:window.devicePixelRatio)||1}postrender(){var e,i;(i=(e=this.props)==null?void 0:e.onPostRender)==null||i.call(e,this)}cproject([e,i]){const s=this.getDevicePixelRatio(),[o,c]=this.context.viewport.project([e,i,0]);return[o*s,c*s]}cunproject([e,i]){const s=this.context.viewport.unproject([e,i]);return s?[s[0],s[1]]:null}checkData(e,i){return typeof e=="string"?null:e&&e.checkFields&&e.checkFields()?e:At(e)?It(e,i):(console.error("Illegal data"),null)}setData(e,i){const s=this.checkData(e,i);this.setState({data:s}),this.state.wind.updateData(s),this.state.wind.prerender()}destory(){const{wind:e}=this.state;e==null||e.stop(),e==null||e.clearCanvas(),Mt(this.state.canvas),this.setState({canvas:null,wind:null,bounds:null,windOptions:null,fieldOptions:null})}finalizeState(){this.destory()}}I(z,"layerName","WindLayer"),d.WindyLayer=z,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(f,g){typeof exports=="object"&&typeof module<"u"?g(exports,require("@deck.gl/core")):typeof define=="function"&&define.amd?define(["exports","@deck.gl/core"],g):(f=typeof globalThis<"u"?globalThis:f||self,g(f["deckgl-expansion"]={},f.Deck["gl/core"]))})(this,function(f,g){"use strict";var Mt=Object.defineProperty;var Pt=(f,g,w)=>g in f?Mt(f,g,{enumerable:!0,configurable:!0,writable:!0,value:w}):f[g]=w;var S=(f,g,w)=>Pt(f,typeof g!="symbol"?g+"":g,w);function w(){}function P(n){return Object.getOwnPropertySymbols(n).filter(t=>Object.prototype.propertyIsEnumerable.call(n,t))}function F(n){return n==null?n===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(n)}const q="[object RegExp]",G="[object String]",K="[object Number]",Z="[object Boolean]",D="[object Arguments]",_="[object Symbol]",H="[object Date]",J="[object Map]",Q="[object Set]",tt="[object Array]",et="[object Function]",it="[object ArrayBuffer]",O="[object Object]",nt="[object Error]",st="[object DataView]",ot="[object Uint8Array]",rt="[object Uint8ClampedArray]",ct="[object Uint16Array]",at="[object Uint32Array]",lt="[object BigUint64Array]",ht="[object Int8Array]",ut="[object Int16Array]",dt="[object Int32Array]",ft="[object BigInt64Array]",gt="[object Float32Array]",pt="[object Float64Array]";function X(n){if(!n||typeof n!="object")return!1;const t=Object.getPrototypeOf(n);return t===null||t===Object.prototype||Object.getPrototypeOf(t)===null?Object.prototype.toString.call(n)==="[object Object]":!1}function yt(n,t){return n===t||Number.isNaN(n)&&Number.isNaN(t)}function xt(n,t,e){return b(n,t,void 0,void 0,void 0,void 0,e)}function b(n,t,e,i,s,o,c){const a=c(n,t,e,i,s,o);if(a!==void 0)return a;if(typeof n==typeof t)switch(typeof n){case"bigint":case"string":case"boolean":case"symbol":case"undefined":return n===t;case"number":return n===t||Object.is(n,t);case"function":return n===t;case"object":return j(n,t,o,c)}return j(n,t,o,c)}function j(n,t,e,i){if(Object.is(n,t))return!0;let s=F(n),o=F(t);if(s===D&&(s=O),o===D&&(o=O),s!==o)return!1;switch(s){case G:return n.toString()===t.toString();case K:{const r=n.valueOf(),l=t.valueOf();return yt(r,l)}case Z:case H:case _:return Object.is(n.valueOf(),t.valueOf());case q:return n.source===t.source&&n.flags===t.flags;case et:return n===t}e=e??new Map;const c=e.get(n),a=e.get(t);if(c!=null&&a!=null)return c===t;e.set(n,t),e.set(t,n);try{switch(s){case J:{if(n.size!==t.size)return!1;for(const[r,l]of n.entries())if(!t.has(r)||!b(l,t.get(r),r,n,t,e,i))return!1;return!0}case Q:{if(n.size!==t.size)return!1;const r=Array.from(n.values()),l=Array.from(t.values());for(let d=0;d<r.length;d++){const h=r[d],u=l.findIndex(p=>b(h,p,void 0,n,t,e,i));if(u===-1)return!1;l.splice(u,1)}return!0}case tt:case ot:case rt:case ct:case at:case lt:case ht:case ut:case dt:case ft:case gt:case pt:{if(typeof Buffer<"u"&&Buffer.isBuffer(n)!==Buffer.isBuffer(t)||n.length!==t.length)return!1;for(let r=0;r<n.length;r++)if(!b(n[r],t[r],r,n,t,e,i))return!1;return!0}case it:return n.byteLength!==t.byteLength?!1:j(new Uint8Array(n),new Uint8Array(t),e,i);case st:return n.byteLength!==t.byteLength||n.byteOffset!==t.byteOffset?!1:j(new Uint8Array(n),new Uint8Array(t),e,i);case nt:return n.name===t.name&&n.message===t.message;case O:{if(!(j(n.constructor,t.constructor,e,i)||X(n)&&X(t)))return!1;const l=[...Object.keys(n),...P(n)],d=[...Object.keys(t),...P(t)];if(l.length!==d.length)return!1;for(let h=0;h<l.length;h++){const u=l[h],p=n[u];if(!Object.hasOwn(t,u))return!1;const x=t[u];if(!b(p,x,u,n,t,e,i))return!1}return!0}default:return!1}}finally{e.delete(n),e.delete(t)}}function mt(n,t){return xt(n,t,w)}const wt=Object.prototype.hasOwnProperty,m=typeof Symbol<"u"?Symbol.toStringTag:void 0;function bt(n){if(n===null)return n===void 0?"[object Undefined]":"[object Null]";if(!(m&&m in Object(n)))return toString.call(n);const t=wt.call(n,m),e=n[m];let i=!1;try{n[m]=void 0,i=!0}catch{}const s=Object.prototype.toString.call(n);return i&&(t?n[m]=e:delete n[m]),s}function v(n){if(!jt(n))return!1;const t=bt(n);return t==="[object Function]"||t==="[object AsyncFunction]"||t==="[object GeneratorFunction]"||t==="[object Proxy]"}function jt(n){const t=typeof n;return n!==null&&(t==="object"||t==="function")}function vt(n){return n==null?!1:typeof n=="string"||n.constructor!==null&&n.constructor===String}function T(n){return Object.prototype.toString.call(n)==="[object Number]"&&!isNaN(n)}function At(n){return Array.isArray(n)}function St(n,t){console.warn(`${t}: ${n}`)}const N={};function Ot(n,t){N[t]||(St(t,n),N[t]=!0)}function Tt(n,t){return n-t*Math.floor(n/t)}function y(n){return n!=null&&!isNaN(n)}function It(n,t={}){let e,i;if(n.forEach(function(c){switch(c.header.parameterCategory+","+c.header.parameterNumber){case"1,2":case"2,2":e=c;break;case"1,3":case"2,3":i=c;break}}),!i||!e)return;const s=e.header;return new Y({xmin:s.lo1,ymin:s.la1,xmax:s.lo2,ymax:s.la2,deltaX:s.dx,deltaY:s.dy,cols:s.nx,rows:s.ny,us:e.data,vs:i.data,...t})}function Ct(n,t,e,i){if(typeof document<"u"){const s=document.createElement("canvas");return s.width=n*e,s.height=t*e,s}else return new i(n*e,t*e)}class V{constructor(t,e){this.u=t,this.v=e,this.m=this.magnitude()}magnitude(){return Math.sqrt(this.u**2+this.v**2)}directionTo(){let e=Math.atan2(this.u,this.v)*(180/Math.PI);return e<0&&(e+=360),e}directionFrom(){return(this.directionTo()+180)%360}}class Y{constructor(t){this.grid=[],this.xmin=t.xmin,this.xmax=t.xmax,this.ymin=t.ymin,this.ymax=t.ymax,this.cols=t.cols,this.rows=t.rows,this.us=t.us,this.vs=t.vs,this.deltaX=t.deltaX,this.deltaY=t.deltaY,this.flipY=!!t.flipY,this.ymin=Math.min(t.ymax,t.ymin),this.ymax=Math.max(t.ymax,t.ymin),this.deltaY<0&&this.ymin<this.ymax||(t.flipY===void 0&&(this.flipY=!0),console.warn("[wind-core]: The data is flipY")),this.isFields=!0;const e=Math.ceil((this.xmax-this.xmin)/t.deltaX),i=Math.ceil((this.ymax-this.ymin)/t.deltaY);(e!==this.cols||i!==this.rows)&&console.warn("[wind-core]: The data grid not equal"),this.isContinuous=Math.floor(this.cols*t.deltaX)>=360,this.translateX="translateX"in t?t.translateX:this.xmax>180,"wrappedX"in t&&Ot("[wind-core]: ","`wrappedX` namespace will deprecated please use `translateX` instead!"),this.wrapX=!!t.wrapX,this.grid=this.buildGrid(),this.range=this.calculateRange()}buildGrid(){const t=[];let e=0;const{rows:i,cols:s,us:o,vs:c}=this;for(let a=0;a<i;a++){const r=[];for(let l=0;l<s;l++,e++){const d=o[e],h=c[e],u=this.isValid(d)&&this.isValid(h);r[l]=u?new V(d,h):null}this.isContinuous&&r.push(r[0]),t[a]=r}return t}release(){this.grid=[]}extent(){return[this.xmin,this.ymin,this.xmax,this.ymax]}bilinearInterpolateVector(t,e,i,s,o,c){const a=1-t,r=1-e,l=a*r,d=t*r,h=a*e,u=t*e,p=i.u*l+s.u*d+o.u*h+c.u*u,x=i.v*l+s.v*d+o.v*h+c.v*u;return new V(p,x)}calculateRange(){if(!this.grid||!this.grid[0])return;const t=this.grid.length,e=this.grid[0].length;let i,s;for(let o=0;o<t;o++)for(let c=0;c<e;c++){const a=this.grid[o][c];if(a!==null){const r=a.m||a.magnitude();i===void 0?i=r:s===void 0?(s=r,i=Math.min(i,s),s=Math.max(i,s)):(i=Math.min(r,i),s=Math.max(r,s))}}return[i,s]}isValid(t){return t!=null}getWrappedLongitudes(){let t=this.xmin,e=this.xmax;return this.translateX&&(this.isContinuous?(t=-180,e=180):(e=this.xmax-360,t=this.xmin-360)),[t,e]}contains(t,e){const[i,s]=this.getWrappedLongitudes();s>180&&t>=-180&&t<=s-360?t+=360:i<-180&&t<=180&&t>=i+360&&(t-=360);const o=t>=i&&t<=s;let c;return this.deltaY>=0?c=e>=this.ymin&&e<=this.ymax:c=e>=this.ymax&&e<=this.ymin,o&&c}getDecimalIndexes(t,e){const i=Tt(t-this.xmin,360)/this.deltaX;if(this.flipY){const s=(this.ymax-e)/this.deltaY;return[i,s]}else{const s=(this.ymin+e)/this.deltaY;return[i,s]}}valueAt(t,e){let i=!1;if((this.wrapX||this.contains(t,e))&&(i=!0),!i)return null;const s=this.getDecimalIndexes(t,e),o=Math.floor(s[0]),c=Math.floor(s[1]),a=this.clampColumnIndex(o),r=this.clampRowIndex(c);return this.valueAtIndexes(a,r)}interpolatedValueAt(t,e){let i=!1;if((this.wrapX||this.contains(t,e))&&(i=!0),!i)return null;const[s,o]=this.getDecimalIndexes(t,e);return this.interpolatePoint(s,o)}hasValueAt(t,e){return this.valueAt(t,e)!==null}interpolatePoint(t,e){const i=this.getFourSurroundingIndexes(t,e),[s,o,c,a]=i,r=this.getFourSurroundingValues(s,o,c,a);if(r){const[l,d,h,u]=r;return this.bilinearInterpolateVector(t-s,e-c,l,d,h,u)}return null}clampColumnIndex(t){let e=t;t<0&&(e=0);const i=this.cols-1;return t>i&&(e=i),e}clampRowIndex(t){let e=t;t<0&&(e=0);const i=this.rows-1;return t>i&&(e=i),e}getFourSurroundingIndexes(t,e){const i=Math.floor(t);let s=i+1;this.isContinuous&&s>=this.cols&&(s=0),s=this.clampColumnIndex(s);const o=this.clampRowIndex(Math.floor(e)),c=this.clampRowIndex(o+1);return[i,s,o,c]}getFourSurroundingValues(t,e,i,s){let o;if(o=this.grid[i]){const c=o[t],a=o[e];if(this.isValid(c)&&this.isValid(a)&&(o=this.grid[s])){const r=o[t],l=o[e];if(this.isValid(r)&&this.isValid(l))return[c,a,r,l]}}return null}valueAtIndexes(t,e){return this.grid[e][t]}lonLatAtIndexes(t,e){const i=this.longitudeAtX(t),s=this.latitudeAtY(e);return[i,s]}longitudeAtX(t){const e=this.deltaX/2;let i=this.xmin+e+t*this.deltaX;return this.translateX&&(i=i>180?i-360:i),i}latitudeAtY(t){const e=this.deltaY/2;return this.ymax-e-t*this.deltaY}randomize(t={},e,i,s){const o=Math.random()*(e||this.cols)|0,c=Math.random()*(i||this.rows)|0,a=s([o,c]);return a!==null?(t.x=a[0],t.y=a[1]):(t.x=this.longitudeAtX(o),t.y=this.latitudeAtY(c)),t}checkFields(){return this.isFields}}const z={globalAlpha:.9,lineWidth:1,colorScale:"#fff",velocityScale:1/25,maxAge:90,paths:800,frameRate:20,useCoordsDraw:!0};function L(n,t,e,i){return Math.max(0,Math.min(i.length-1,Math.round((n-t)/(e-t)*(i.length-1))))}const M=class M{constructor(t,e,i){if(this.particles=[],this.generated=!1,this.ctx=t,!this.ctx)throw new Error("ctx error");this.animate=this.animate.bind(this),this.setOptions(e),i&&this.updateData(i)}setOptions(t){this.options={...z,...t};const{width:e,height:i}=this.ctx.canvas;"particleAge"in t&&!("maxAge"in t)&&T(this.options.particleAge)&&(this.options.maxAge=this.options.particleAge),"particleMultiplier"in t&&!("paths"in t)&&T(this.options.particleMultiplier)&&(this.options.paths=Math.round(e*i*this.options.particleMultiplier)),this.prerender()}getOptions(){return this.options}updateData(t){this.field=t,this.generated&&(this.particles=this.prepareParticlePaths())}project(...t){throw new Error("project must be overriden")}unproject(...t){throw new Error("unproject must be overriden")}intersectsCoordinate(t){throw new Error("must be overriden")}clearCanvas(){this.stop(),this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.forceStop=!1}isStop(){return!this.starting}start(){this.starting=!0,this.forceStop=!1,this.then=Date.now(),this.animate()}stop(){cancelAnimationFrame(this.animationLoop),this.starting=!1,this.forceStop=!0}animate(){this.animationLoop&&cancelAnimationFrame(this.animationLoop),this.animationLoop=requestAnimationFrame(this.animate);const t=Date.now(),e=t-this.then;e>this.options.frameRate&&(this.then=t-e%this.options.frameRate,this.render())}prerender(){this.generated=!1,this.field&&(this.particles=this.prepareParticlePaths(),this.generated=!0,!this.starting&&!this.forceStop&&(this.starting=!0,this.then=Date.now(),this.animate()))}render(){this.moveParticles(),this.drawParticles(),this.postrender()}postrender(){}moveParticles(){const{width:t,height:e}=this.ctx.canvas,i=this.particles,s=this.options.maxAge,o=v(this.options.velocityScale)?this.options.velocityScale():this.options.velocityScale;let c=0;const a=i.length;for(;c<a;c++){const r=i[c];r.age>s&&(r.age=0,this.field.randomize(r,t,e,this.unproject));const l=r.x,d=r.y,h=this.field.interpolatedValueAt(l,d);if(h===null)r.age=s;else{const u=l+h.u*o,p=d+h.v*o;this.field.hasValueAt(u,p)?(r.xt=u,r.yt=p,r.m=h.m):(r.x=u,r.y=p,r.age=s)}r.age++}}fadeIn(){const t=this.ctx.globalCompositeOperation;this.ctx.globalCompositeOperation="destination-in",this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.globalCompositeOperation=t}drawParticles(){const t=this.particles;this.fadeIn(),this.ctx.globalAlpha=this.options.globalAlpha,this.ctx.fillStyle=`rgba(0, 0, 0, ${this.options.globalAlpha})`,this.ctx.lineWidth=T(this.options.lineWidth)?this.options.lineWidth:1,this.ctx.strokeStyle=vt(this.options.colorScale)?this.options.colorScale:"#fff";let e=0;const i=t.length;if(this.field&&i>0){let s,o;for(y(this.options.minVelocity)&&y(this.options.maxVelocity)?(s=this.options.minVelocity,o=this.options.maxVelocity):[s,o]=this.field.range;e<i;e++)this[this.options.useCoordsDraw?"drawCoordsParticle":"drawPixelParticle"](t[e],s,o)}}drawPixelParticle(t,e,i){const s=[t.x,t.y],o=[t.xt,t.yt];if(o&&s&&y(o[0])&&y(o[1])&&y(s[0])&&y(s[1])&&t.age<=this.options.maxAge){if(this.ctx.beginPath(),this.ctx.moveTo(s[0],s[1]),this.ctx.lineTo(o[0],o[1]),v(this.options.colorScale))this.ctx.strokeStyle=this.options.colorScale(t.m);else if(Array.isArray(this.options.colorScale)){const c=L(t.m,e,i,this.options.colorScale);this.ctx.strokeStyle=this.options.colorScale[c]}v(this.options.lineWidth)&&(this.ctx.lineWidth=this.options.lineWidth(t.m)),t.x=t.xt,t.y=t.yt,this.ctx.stroke()}}drawCoordsParticle(t,e,i){const s=[t.x,t.y],o=[t.xt,t.yt];if(o&&s&&y(o[0])&&y(o[1])&&y(s[0])&&y(s[1])&&this.intersectsCoordinate(o)&&t.age<=this.options.maxAge){const c=this.project(s),a=this.project(o);if(c&&a){if(this.ctx.beginPath(),this.ctx.moveTo(c[0],c[1]),this.ctx.lineTo(a[0],a[1]),t.x=t.xt,t.y=t.yt,v(this.options.colorScale))this.ctx.strokeStyle=this.options.colorScale(t.m);else if(Array.isArray(this.options.colorScale)){const r=L(t.m,e,i,this.options.colorScale);this.ctx.strokeStyle=this.options.colorScale[r]}v(this.options.lineWidth)&&(this.ctx.lineWidth=this.options.lineWidth(t.m)),this.ctx.stroke()}}}prepareParticlePaths(){const{width:t,height:e}=this.ctx.canvas,i=typeof this.options.paths=="function"?this.options.paths(this):this.options.paths,s=[];if(!this.field)return[];let o=0;for(;o<i;o++)s.push(this.field.randomize({age:this.randomize()},t,e,this.unproject));return s}randomize(){return Math.floor(Math.random()*this.options.maxAge)}};M.Field=Y;let I=M;class C extends g.Layer{constructor(){super(...arguments);S(this,"_defaultOptions",{...z})}initializeState(){this.init()}shouldUpdateState({changeFlags:e}){return e.somethingChanged}updateState({props:e,oldProps:i,context:s}){var d;const{bounds:o,wind:c,windOptions:a}=this.state,r=(o==null?void 0:o.reduce((h,u)=>h+u,0))||0,l=((d=s.viewport.getBounds())==null?void 0:d.reduce((h,u)=>h+u,0))||0;if(r!==l&&this.setState({bounds:s.viewport.getBounds()}),(i==null?void 0:i.data)!==(e==null?void 0:e.data)&&this.setData(e.data,(e==null?void 0:e.fieldOptions)||{}),(i==null?void 0:i.visible)!==e.visible&&this.setVisible(e.visible),(i==null?void 0:i.zIndex)!==e.zIndex&&this.setzIndex(String(e.zIndex)||"unset"),!mt(a,e==null?void 0:e.windOptions)){const h=Object.assign({},a,e.windOptions);c.setOptions(h),this.setState({windOptions:h})}}intersectsCoordinate([e,i]){const[s,o,c,a]=this.state.bounds;return e>=s&&e<=c&&i>=o&&i<=a}init(){var R,B,W,U,E,k,$;const{viewport:e,deck:i}=this.context,s=i==null?void 0:i.width,o=i==null?void 0:i.height,c=this.getDevicePixelRatio(),a=this.state.canvas??Ct(s,o,c);a.style.position="absolute",a.style.top="0px",a.style.left="0px",a.style.right="0px",a.style.bottom="0px",a.style.width=`${s}px`,a.style.height=`${o}px`,a.style.display=(R=this.props)!=null&&R.visible?"block":"none",a.style.zIndex=((W=(B=this.props)==null?void 0:B.zIndex)==null?void 0:W.toString())||"unset",a.id="windy-layer-canvas";const r=a.getContext("2d"),l=e.getBounds(),d=(U=this.props)==null?void 0:U.data,h=Object.assign(this._defaultOptions,((E=this.props)==null?void 0:E.windOptions)||{}),u=((k=this.props)==null?void 0:k.fieldOptions)||null,p=this.checkData(d,u),x=new I(r,h,p);x.postrender=this.postrender.bind(this),x.project=this.cproject.bind(this),x.unproject=this.cunproject.bind(this),x.intersectsCoordinate=this.intersectsCoordinate.bind(this);const A=($=i==null?void 0:i.getCanvas())==null?void 0:$.parentNode;A&&!A.querySelector("#windy-layer-canvas")&&A.appendChild(a),this.setState({bounds:l,canvas:a,wind:x,container:A,windOpitons:h})}setVisible(e){this.state.canvas.style.display=e?"block":"none"}setzIndex(e){this.state.canvas.style.zIndex=String(e)||"unset"}getDevicePixelRatio(){return(window==null?void 0:window.devicePixelRatio)||1}postrender(){var e,i;(i=(e=this.props)==null?void 0:e.onPostRender)==null||i.call(e,this)}cproject([e,i]){const s=this.getDevicePixelRatio(),[o,c]=this.context.viewport.project([e,i,0]);return[o*s,c*s]}cunproject([e,i]){const s=this.context.viewport.unproject([e,i]);return s?[s[0],s[1]]:null}checkData(e,i){return typeof e=="string"?null:e&&e.checkFields&&e.checkFields()?e:At(e)?It(e,i):(console.error("Illegal data"),null)}setData(e,i){const s=this.checkData(e,i);this.setState({data:s}),this.state.wind.updateData(s),this.state.wind.prerender()}destory(){const{wind:e,container:i}=this.state;e==null||e.stop(),e==null||e.clearCanvas(),i&&i.removeChild(this.state.canvas),this.setState({canvas:null,wind:null,bounds:null,windOptions:null,fieldOptions:null})}finalizeState(){this.destory()}}S(C,"layerName","WindyLayer"),S(C,"componentName","WindyLayer"),f.WindyLayer=C,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -9,6 +9,7 @@ export interface WindyLayerProps extends LayerProps {
|
|
|
9
9
|
}
|
|
10
10
|
export default class WindyLayer extends Layer<WindyLayerProps> {
|
|
11
11
|
static layerName: string;
|
|
12
|
+
static componentName: string;
|
|
12
13
|
private _defaultOptions;
|
|
13
14
|
state: {
|
|
14
15
|
canvas: HTMLCanvasElement;
|
|
@@ -16,6 +17,7 @@ export default class WindyLayer extends Layer<WindyLayerProps> {
|
|
|
16
17
|
bounds: [number, number, number, number];
|
|
17
18
|
windOptions: Partial<IOptions> | undefined;
|
|
18
19
|
fieldOptions: Partial<IField> | undefined;
|
|
20
|
+
container: HTMLElement | null;
|
|
19
21
|
};
|
|
20
22
|
initializeState(): void;
|
|
21
23
|
shouldUpdateState({ changeFlags }: UpdateParameters<this>): boolean;
|