@oceanum/layers 0.1.1
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/README.md +206 -0
- package/dist/README.md +206 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +539 -0
- package/dist/oceanum-base-layer.d.ts +72 -0
- package/dist/oceanum-base-layer.d.ts.map +1 -0
- package/dist/oceanum-contour-layer.d.ts +45 -0
- package/dist/oceanum-contour-layer.d.ts.map +1 -0
- package/dist/oceanum-particle-layer.d.ts +40 -0
- package/dist/oceanum-particle-layer.d.ts.map +1 -0
- package/dist/oceanum-partmesh-layer.d.ts +50 -0
- package/dist/oceanum-partmesh-layer.d.ts.map +1 -0
- package/dist/oceanum-pcolor-layer.d.ts +22 -0
- package/dist/oceanum-pcolor-layer.d.ts.map +1 -0
- package/dist/utils/coordinates.d.ts +31 -0
- package/dist/utils/coordinates.d.ts.map +1 -0
- package/dist/utils/dataset-slice.d.ts +22 -0
- package/dist/utils/dataset-slice.d.ts.map +1 -0
- package/dist/utils/viewport.d.ts +18 -0
- package/dist/utils/viewport.d.ts.map +1 -0
- package/package.json +40 -0
package/README.md
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# @oceanum/layers
|
|
2
|
+
|
|
3
|
+
deck.gl layers for visualising gridded data from [Oceanum Datamesh](https://oceanum.io/datamesh-environmental-data-platform/) zarr datasets.
|
|
4
|
+
|
|
5
|
+
This library wraps [@oceanum/deck-gl-grid](https://github.com/oceanum/deck-gl-grid) layers with automatic data fetching from pre-cached zarr archives on the Datamesh. It handles time/level dimension selection, viewport-based spatial chunk loading, and debounced fetching — all through a simple props-based API.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @oceanum/layers
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Peer dependencies
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @deck.gl/core @deck.gl/layers @luma.gl/core
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```jsx
|
|
22
|
+
import { OceanumPcolorLayer } from '@oceanum/layers';
|
|
23
|
+
import DeckGL from '@deck.gl/react';
|
|
24
|
+
|
|
25
|
+
const SERVICE_URL = 'https://zarr.datamesh.oceanum.io';
|
|
26
|
+
|
|
27
|
+
function App() {
|
|
28
|
+
const [time, setTime] = useState('2024-01-15T00:00:00Z');
|
|
29
|
+
|
|
30
|
+
const layers = [
|
|
31
|
+
new OceanumPcolorLayer({
|
|
32
|
+
id: 'wave-height',
|
|
33
|
+
serviceUrl: SERVICE_URL,
|
|
34
|
+
authHeaders: { Authorization: `Bearer ${token}` },
|
|
35
|
+
datasource: 'oceanum_wave_glob05',
|
|
36
|
+
variable: 'hs',
|
|
37
|
+
time,
|
|
38
|
+
colormap: {
|
|
39
|
+
scale: ['#313695', '#4575b4', '#74add1', '#abd9e9',
|
|
40
|
+
'#fee090', '#fdae61', '#f46d43', '#d73027'],
|
|
41
|
+
domain: [0, 1, 2, 3, 4, 5, 6, 8],
|
|
42
|
+
},
|
|
43
|
+
opacity: 0.8,
|
|
44
|
+
}),
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
return <DeckGL layers={layers} />;
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Layers
|
|
52
|
+
|
|
53
|
+
### OceanumPcolorLayer
|
|
54
|
+
|
|
55
|
+
Renders a scalar variable as coloured grid cells.
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
new OceanumPcolorLayer({
|
|
59
|
+
id: 'sst',
|
|
60
|
+
serviceUrl: 'https://zarr.datamesh.oceanum.io',
|
|
61
|
+
datasource: 'my_dataset',
|
|
62
|
+
variable: 'temperature',
|
|
63
|
+
time: '2024-01-15T00:00:00Z',
|
|
64
|
+
colormap: { scale: [...], domain: [...] },
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
| Prop | Type | Default | Description |
|
|
69
|
+
|------|------|---------|-------------|
|
|
70
|
+
| `variable` | `string` | *required* | Scalar variable name in the zarr dataset |
|
|
71
|
+
| `color` | `[r,g,b]` | `[200,200,200]` | Fallback colour when no colormap |
|
|
72
|
+
| `material` | `boolean\|object` | `false` | Phong material for lighting |
|
|
73
|
+
|
|
74
|
+
### OceanumParticleLayer
|
|
75
|
+
|
|
76
|
+
Renders animated particles flowing through a vector field.
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
new OceanumParticleLayer({
|
|
80
|
+
id: 'wind',
|
|
81
|
+
serviceUrl: 'https://zarr.datamesh.oceanum.io',
|
|
82
|
+
datasource: 'era5_wind',
|
|
83
|
+
uVariable: 'u10',
|
|
84
|
+
vVariable: 'v10',
|
|
85
|
+
time: '2024-01-15T00:00:00Z',
|
|
86
|
+
npart: 5000,
|
|
87
|
+
speed: 2.0,
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
| Prop | Type | Default | Description |
|
|
92
|
+
|------|------|---------|-------------|
|
|
93
|
+
| `uVariable` | `string` | — | U (eastward) component variable |
|
|
94
|
+
| `vVariable` | `string` | — | V (northward) component variable |
|
|
95
|
+
| `magnitudeVariable` | `string` | — | Magnitude variable (alternative to u/v) |
|
|
96
|
+
| `directionVariable` | `string` | — | Direction variable (alternative to u/v) |
|
|
97
|
+
| `speed` | `number` | `1.0` | Animation speed multiplier |
|
|
98
|
+
| `npart` | `number` | `1000` | Number of particles |
|
|
99
|
+
| `size` | `number` | `3` | Particle size in pixels |
|
|
100
|
+
| `length` | `number` | `12` | Particle trail length |
|
|
101
|
+
| `directionConvention` | `string` | `'NAUTICAL_FROM'` | `'NAUTICAL_FROM'`, `'NAUTICAL_TO'`, or `'CARTESIAN_RADIANS'` |
|
|
102
|
+
|
|
103
|
+
Provide either (`uVariable` + `vVariable`) **or** (`magnitudeVariable` + `directionVariable`).
|
|
104
|
+
|
|
105
|
+
### OceanumPartmeshLayer
|
|
106
|
+
|
|
107
|
+
Renders mesh-based arrows for a vector field. Same variable props as ParticleLayer.
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
new OceanumPartmeshLayer({
|
|
111
|
+
id: 'currents',
|
|
112
|
+
serviceUrl: 'https://zarr.datamesh.oceanum.io',
|
|
113
|
+
datasource: 'ocean_currents',
|
|
114
|
+
uVariable: 'uo',
|
|
115
|
+
vVariable: 'vo',
|
|
116
|
+
time: '2024-01-15T00:00:00Z',
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
| Prop | Type | Default | Description |
|
|
121
|
+
|------|------|---------|-------------|
|
|
122
|
+
| `uVariable` / `vVariable` | `string` | — | Vector component pair |
|
|
123
|
+
| `magnitudeVariable` / `directionVariable` | `string` | — | Alternative vector pair |
|
|
124
|
+
| `speed` | `number` | `1.0` | Animation speed multiplier |
|
|
125
|
+
| `size` | `number` | `3` | Arrow size in pixels |
|
|
126
|
+
| `directionConvention` | `string` | `'NAUTICAL_FROM'` | Direction convention |
|
|
127
|
+
|
|
128
|
+
### OceanumContourLayer
|
|
129
|
+
|
|
130
|
+
Renders contour lines with labels for a scalar variable.
|
|
131
|
+
|
|
132
|
+
```javascript
|
|
133
|
+
new OceanumContourLayer({
|
|
134
|
+
id: 'pressure',
|
|
135
|
+
serviceUrl: 'https://zarr.datamesh.oceanum.io',
|
|
136
|
+
datasource: 'era5_surface',
|
|
137
|
+
variable: 'msl',
|
|
138
|
+
time: '2024-01-15T00:00:00Z',
|
|
139
|
+
levels: [990, 995, 1000, 1005, 1010, 1015, 1020, 1025],
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
| Prop | Type | Default | Description |
|
|
144
|
+
|------|------|---------|-------------|
|
|
145
|
+
| `variable` | `string` | *required* | Scalar variable name |
|
|
146
|
+
| `levels` | `number[]` | `[]` | Contour level values |
|
|
147
|
+
| `labelSize` | `number` | `12` | Label font size |
|
|
148
|
+
| `labelColor` | `[r,g,b,a]` | `[255,255,255,255]` | Label colour |
|
|
149
|
+
| `smoothing` | `boolean` | `false` | Smooth contour lines |
|
|
150
|
+
| `numLabels` | `number` | `1` | Labels per contour line |
|
|
151
|
+
|
|
152
|
+
## Common Props
|
|
153
|
+
|
|
154
|
+
All layers share these props:
|
|
155
|
+
|
|
156
|
+
| Prop | Type | Default | Description |
|
|
157
|
+
|------|------|---------|-------------|
|
|
158
|
+
| `serviceUrl` | `string` | *required* | Root URL of the zarr service |
|
|
159
|
+
| `authHeaders` | `object` | `{}` | HTTP headers for authentication |
|
|
160
|
+
| `datasource` | `string` | *required* | Dataset name (subpath of the service URL) |
|
|
161
|
+
| `instance` | `string` | latest | Zarr group name. Defaults to the latest (last lexicographically) |
|
|
162
|
+
| `time` | `string\|Date` | first | ISO 8601 string or `Date`. Resolved to nearest available time step |
|
|
163
|
+
| `level` | `number` | `0` | 0-based index into the level dimension |
|
|
164
|
+
| `colormap` | `object` | `null` | `{ scale: string[], domain: number[] }` |
|
|
165
|
+
| `opacity` | `number` | `1.0` | Layer opacity (0-1) |
|
|
166
|
+
| `altitude` | `number` | `0.0` | Altitude offset |
|
|
167
|
+
| `globalWrap` | `boolean` | `false` | Wrap across the antimeridian |
|
|
168
|
+
| `scale` | `number` | `1.0` | Value multiplier before colormapping |
|
|
169
|
+
| `offset` | `number` | `0.0` | Value offset before colormapping |
|
|
170
|
+
| `pickable` | `boolean` | `false` | Enable picking |
|
|
171
|
+
| `visible` | `boolean` | `true` | Layer visibility |
|
|
172
|
+
| `viewportPadding` | `number` | `0.1` | Spatial padding fraction beyond viewport edges |
|
|
173
|
+
| `debounceWait` | `number` | `100` | Debounce delay (ms) for slice requests |
|
|
174
|
+
| `onDataLoad` | `function` | — | Called when metadata loads. Receives `{ dataset, times, nlevels, instance }` |
|
|
175
|
+
| `onError` | `object` | — | Error hooks object (see below) |
|
|
176
|
+
|
|
177
|
+
## Zarr Dataset Structure
|
|
178
|
+
|
|
179
|
+
The zarr archives are expected to have:
|
|
180
|
+
|
|
181
|
+
- A `_coordinates` attribute in the root `.zattrs` mapping dimension roles:
|
|
182
|
+
```json
|
|
183
|
+
{ "x": "longitude", "y": "latitude", "t": "time", "z": "level" }
|
|
184
|
+
```
|
|
185
|
+
- Dimensions: `(time, [level], latitude, longitude)`
|
|
186
|
+
- One or more instance groups at the root level (optional)
|
|
187
|
+
|
|
188
|
+
## Error Hooks
|
|
189
|
+
|
|
190
|
+
The `onError` prop accepts per-state callbacks:
|
|
191
|
+
|
|
192
|
+
```javascript
|
|
193
|
+
onError: {
|
|
194
|
+
onMetadataError: (err) => { /* dataset open failed */ },
|
|
195
|
+
onChunkError: (err) => { /* chunk fetch failed */ },
|
|
196
|
+
onVariableError: (err) => { /* variable not found */ },
|
|
197
|
+
onValidationError: (err) => { /* invalid props */ },
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
| Hook | When | Layer Behaviour |
|
|
202
|
+
|------|------|-----------------|
|
|
203
|
+
| `onMetadataError` | Dataset open fails | Renders nothing |
|
|
204
|
+
| `onChunkError` | Chunk fetch fails | Keeps last valid slice |
|
|
205
|
+
| `onVariableError` | Variable not found in dataset | Renders nothing |
|
|
206
|
+
| `onValidationError` | Invalid prop combination | Renders nothing |
|
package/dist/README.md
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# @oceanum/layers
|
|
2
|
+
|
|
3
|
+
deck.gl layers for visualising gridded data from [Oceanum Datamesh](https://oceanum.io/datamesh-environmental-data-platform/) zarr datasets.
|
|
4
|
+
|
|
5
|
+
This library wraps [@oceanum/deck-gl-grid](https://github.com/oceanum/deck-gl-grid) layers with automatic data fetching from pre-cached zarr archives on the Datamesh. It handles time/level dimension selection, viewport-based spatial chunk loading, and debounced fetching — all through a simple props-based API.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @oceanum/layers
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Peer dependencies
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @deck.gl/core @deck.gl/layers @luma.gl/core
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```jsx
|
|
22
|
+
import { OceanumPcolorLayer } from '@oceanum/layers';
|
|
23
|
+
import DeckGL from '@deck.gl/react';
|
|
24
|
+
|
|
25
|
+
const SERVICE_URL = 'https://zarr.datamesh.oceanum.io';
|
|
26
|
+
|
|
27
|
+
function App() {
|
|
28
|
+
const [time, setTime] = useState('2024-01-15T00:00:00Z');
|
|
29
|
+
|
|
30
|
+
const layers = [
|
|
31
|
+
new OceanumPcolorLayer({
|
|
32
|
+
id: 'wave-height',
|
|
33
|
+
serviceUrl: SERVICE_URL,
|
|
34
|
+
authHeaders: { Authorization: `Bearer ${token}` },
|
|
35
|
+
datasource: 'oceanum_wave_glob05',
|
|
36
|
+
variable: 'hs',
|
|
37
|
+
time,
|
|
38
|
+
colormap: {
|
|
39
|
+
scale: ['#313695', '#4575b4', '#74add1', '#abd9e9',
|
|
40
|
+
'#fee090', '#fdae61', '#f46d43', '#d73027'],
|
|
41
|
+
domain: [0, 1, 2, 3, 4, 5, 6, 8],
|
|
42
|
+
},
|
|
43
|
+
opacity: 0.8,
|
|
44
|
+
}),
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
return <DeckGL layers={layers} />;
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Layers
|
|
52
|
+
|
|
53
|
+
### OceanumPcolorLayer
|
|
54
|
+
|
|
55
|
+
Renders a scalar variable as coloured grid cells.
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
new OceanumPcolorLayer({
|
|
59
|
+
id: 'sst',
|
|
60
|
+
serviceUrl: 'https://zarr.datamesh.oceanum.io',
|
|
61
|
+
datasource: 'my_dataset',
|
|
62
|
+
variable: 'temperature',
|
|
63
|
+
time: '2024-01-15T00:00:00Z',
|
|
64
|
+
colormap: { scale: [...], domain: [...] },
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
| Prop | Type | Default | Description |
|
|
69
|
+
|------|------|---------|-------------|
|
|
70
|
+
| `variable` | `string` | *required* | Scalar variable name in the zarr dataset |
|
|
71
|
+
| `color` | `[r,g,b]` | `[200,200,200]` | Fallback colour when no colormap |
|
|
72
|
+
| `material` | `boolean\|object` | `false` | Phong material for lighting |
|
|
73
|
+
|
|
74
|
+
### OceanumParticleLayer
|
|
75
|
+
|
|
76
|
+
Renders animated particles flowing through a vector field.
|
|
77
|
+
|
|
78
|
+
```javascript
|
|
79
|
+
new OceanumParticleLayer({
|
|
80
|
+
id: 'wind',
|
|
81
|
+
serviceUrl: 'https://zarr.datamesh.oceanum.io',
|
|
82
|
+
datasource: 'era5_wind',
|
|
83
|
+
uVariable: 'u10',
|
|
84
|
+
vVariable: 'v10',
|
|
85
|
+
time: '2024-01-15T00:00:00Z',
|
|
86
|
+
npart: 5000,
|
|
87
|
+
speed: 2.0,
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
| Prop | Type | Default | Description |
|
|
92
|
+
|------|------|---------|-------------|
|
|
93
|
+
| `uVariable` | `string` | — | U (eastward) component variable |
|
|
94
|
+
| `vVariable` | `string` | — | V (northward) component variable |
|
|
95
|
+
| `magnitudeVariable` | `string` | — | Magnitude variable (alternative to u/v) |
|
|
96
|
+
| `directionVariable` | `string` | — | Direction variable (alternative to u/v) |
|
|
97
|
+
| `speed` | `number` | `1.0` | Animation speed multiplier |
|
|
98
|
+
| `npart` | `number` | `1000` | Number of particles |
|
|
99
|
+
| `size` | `number` | `3` | Particle size in pixels |
|
|
100
|
+
| `length` | `number` | `12` | Particle trail length |
|
|
101
|
+
| `directionConvention` | `string` | `'NAUTICAL_FROM'` | `'NAUTICAL_FROM'`, `'NAUTICAL_TO'`, or `'CARTESIAN_RADIANS'` |
|
|
102
|
+
|
|
103
|
+
Provide either (`uVariable` + `vVariable`) **or** (`magnitudeVariable` + `directionVariable`).
|
|
104
|
+
|
|
105
|
+
### OceanumPartmeshLayer
|
|
106
|
+
|
|
107
|
+
Renders mesh-based arrows for a vector field. Same variable props as ParticleLayer.
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
new OceanumPartmeshLayer({
|
|
111
|
+
id: 'currents',
|
|
112
|
+
serviceUrl: 'https://zarr.datamesh.oceanum.io',
|
|
113
|
+
datasource: 'ocean_currents',
|
|
114
|
+
uVariable: 'uo',
|
|
115
|
+
vVariable: 'vo',
|
|
116
|
+
time: '2024-01-15T00:00:00Z',
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
| Prop | Type | Default | Description |
|
|
121
|
+
|------|------|---------|-------------|
|
|
122
|
+
| `uVariable` / `vVariable` | `string` | — | Vector component pair |
|
|
123
|
+
| `magnitudeVariable` / `directionVariable` | `string` | — | Alternative vector pair |
|
|
124
|
+
| `speed` | `number` | `1.0` | Animation speed multiplier |
|
|
125
|
+
| `size` | `number` | `3` | Arrow size in pixels |
|
|
126
|
+
| `directionConvention` | `string` | `'NAUTICAL_FROM'` | Direction convention |
|
|
127
|
+
|
|
128
|
+
### OceanumContourLayer
|
|
129
|
+
|
|
130
|
+
Renders contour lines with labels for a scalar variable.
|
|
131
|
+
|
|
132
|
+
```javascript
|
|
133
|
+
new OceanumContourLayer({
|
|
134
|
+
id: 'pressure',
|
|
135
|
+
serviceUrl: 'https://zarr.datamesh.oceanum.io',
|
|
136
|
+
datasource: 'era5_surface',
|
|
137
|
+
variable: 'msl',
|
|
138
|
+
time: '2024-01-15T00:00:00Z',
|
|
139
|
+
levels: [990, 995, 1000, 1005, 1010, 1015, 1020, 1025],
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
| Prop | Type | Default | Description |
|
|
144
|
+
|------|------|---------|-------------|
|
|
145
|
+
| `variable` | `string` | *required* | Scalar variable name |
|
|
146
|
+
| `levels` | `number[]` | `[]` | Contour level values |
|
|
147
|
+
| `labelSize` | `number` | `12` | Label font size |
|
|
148
|
+
| `labelColor` | `[r,g,b,a]` | `[255,255,255,255]` | Label colour |
|
|
149
|
+
| `smoothing` | `boolean` | `false` | Smooth contour lines |
|
|
150
|
+
| `numLabels` | `number` | `1` | Labels per contour line |
|
|
151
|
+
|
|
152
|
+
## Common Props
|
|
153
|
+
|
|
154
|
+
All layers share these props:
|
|
155
|
+
|
|
156
|
+
| Prop | Type | Default | Description |
|
|
157
|
+
|------|------|---------|-------------|
|
|
158
|
+
| `serviceUrl` | `string` | *required* | Root URL of the zarr service |
|
|
159
|
+
| `authHeaders` | `object` | `{}` | HTTP headers for authentication |
|
|
160
|
+
| `datasource` | `string` | *required* | Dataset name (subpath of the service URL) |
|
|
161
|
+
| `instance` | `string` | latest | Zarr group name. Defaults to the latest (last lexicographically) |
|
|
162
|
+
| `time` | `string\|Date` | first | ISO 8601 string or `Date`. Resolved to nearest available time step |
|
|
163
|
+
| `level` | `number` | `0` | 0-based index into the level dimension |
|
|
164
|
+
| `colormap` | `object` | `null` | `{ scale: string[], domain: number[] }` |
|
|
165
|
+
| `opacity` | `number` | `1.0` | Layer opacity (0-1) |
|
|
166
|
+
| `altitude` | `number` | `0.0` | Altitude offset |
|
|
167
|
+
| `globalWrap` | `boolean` | `false` | Wrap across the antimeridian |
|
|
168
|
+
| `scale` | `number` | `1.0` | Value multiplier before colormapping |
|
|
169
|
+
| `offset` | `number` | `0.0` | Value offset before colormapping |
|
|
170
|
+
| `pickable` | `boolean` | `false` | Enable picking |
|
|
171
|
+
| `visible` | `boolean` | `true` | Layer visibility |
|
|
172
|
+
| `viewportPadding` | `number` | `0.1` | Spatial padding fraction beyond viewport edges |
|
|
173
|
+
| `debounceWait` | `number` | `100` | Debounce delay (ms) for slice requests |
|
|
174
|
+
| `onDataLoad` | `function` | — | Called when metadata loads. Receives `{ dataset, times, nlevels, instance }` |
|
|
175
|
+
| `onError` | `object` | — | Error hooks object (see below) |
|
|
176
|
+
|
|
177
|
+
## Zarr Dataset Structure
|
|
178
|
+
|
|
179
|
+
The zarr archives are expected to have:
|
|
180
|
+
|
|
181
|
+
- A `_coordinates` attribute in the root `.zattrs` mapping dimension roles:
|
|
182
|
+
```json
|
|
183
|
+
{ "x": "longitude", "y": "latitude", "t": "time", "z": "level" }
|
|
184
|
+
```
|
|
185
|
+
- Dimensions: `(time, [level], latitude, longitude)`
|
|
186
|
+
- One or more instance groups at the root level (optional)
|
|
187
|
+
|
|
188
|
+
## Error Hooks
|
|
189
|
+
|
|
190
|
+
The `onError` prop accepts per-state callbacks:
|
|
191
|
+
|
|
192
|
+
```javascript
|
|
193
|
+
onError: {
|
|
194
|
+
onMetadataError: (err) => { /* dataset open failed */ },
|
|
195
|
+
onChunkError: (err) => { /* chunk fetch failed */ },
|
|
196
|
+
onVariableError: (err) => { /* variable not found */ },
|
|
197
|
+
onValidationError: (err) => { /* invalid props */ },
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
| Hook | When | Layer Behaviour |
|
|
202
|
+
|------|------|-----------------|
|
|
203
|
+
| `onMetadataError` | Dataset open fails | Renders nothing |
|
|
204
|
+
| `onChunkError` | Chunk fetch fails | Keeps last valid slice |
|
|
205
|
+
| `onVariableError` | Variable not found in dataset | Renders nothing |
|
|
206
|
+
| `onValidationError` | Invalid prop combination | Renders nothing |
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("@oceanum/deck-gl-grid"),R=require("@deck.gl/core"),B=require("@oceanum/datamesh");function E(a,e){const n={x:a.x,y:a.y};return e.xvector&&e.yvector?(n.u=e.xvector,n.v=e.yvector):n.c=e.magnitude,n}function q(a,e){const n={x:a.x,y:a.y};return e.xvector&&e.yvector?(n.u=e.xvector,n.v=e.yvector):(n.m=e.magnitude,n.d=e.direction),n}function $(a){const e=[];return a.magnitude&&e.push(a.magnitude),a.xvector&&e.push(a.xvector),a.yvector&&e.push(a.yvector),a.direction&&e.push(a.direction),e}function C(a,e){if(!a||a.length===0)return 0;const n=e instanceof Date?e.getTime()/1e3:new Date(e).getTime()/1e3;let t=0,l=a.length-1;for(;t<l;){const o=t+l>>1;a[o]<n?t=o+1:l=o}return t>0&&Math.abs(a[t-1]-n)<Math.abs(a[t]-n)?t-1:t}function M(a,e){return e<=0?0:Math.max(0,Math.min(a,e-1))}function S(a,e,n){if(!a||a.length===0)return[0,0];const t=a.length<2||a[1]>=a[0];let l=0,o=a.length-1;if(t){let r=0,s=a.length-1;for(;r<s;){const i=r+s>>1;a[i]<e?r=i+1:s=i}for(l=Math.max(0,r-1),r=l,s=a.length-1;r<s;){const i=r+s+1>>1;a[i]>n?s=i-1:r=i}o=Math.min(a.length-1,r+1)}else{let r=0,s=a.length-1;for(;r<s;){const i=r+s>>1;a[i]>n?r=i+1:s=i}for(l=Math.max(0,r-1),r=l,s=a.length-1;r<s;){const i=r+s+1>>1;a[i]<e?s=i-1:r=i}o=Math.min(a.length-1,r+1)}return[l,o]}function P(a,e){return{start:a,stop:e,step:null}}async function T(a,e,n,t,l,o,r){const s={},i={},c=a.variables[e.x],y=a.variables[e.y],[h,m]=await Promise.all([c.get([P(r[0],r[1]+1)]),y.get([P(o[0],o[1]+1)])]);s[e.x]={data:h},s[e.y]={data:m};const v=n.map(async b=>{const p=a.variables[b];if(!p)return;const x=p.dimensions.map(f=>e.t&&f===e.t?t:e.z&&f===e.z?l:f===e.y?P(o[0],o[1]+1):f===e.x?P(r[0],r[1]+1):null),D=await p.get(x);i[b]={data:D}});return await Promise.all(v),{coords:s,data_vars:i}}function V(a,e=.1){const n=a.getBounds(),t=n[0][0],l=n[0][1],o=n[1][0],r=n[1][1],s=o-t,i=r-l,c=s*e,y=i*e;return{west:t-c,south:Math.max(-90,l-y),east:o+c,north:Math.min(90,r+y)}}function j(a,e){return e?a.west>=e.west&&a.south>=e.south&&a.east<=e.east&&a.north<=e.north:!1}function W(a,e){let n=null;const t=((...l)=>{n&&clearTimeout(n),n=setTimeout(()=>{n=null,a(...l)},e)});return t.cancel=()=>{n&&(clearTimeout(n),n=null)},t}const A={onMetadataError:a=>console.warn(`[OceanumLayer] ${a.message}`),onChunkError:a=>console.warn(`[OceanumLayer] ${a.message}`),onVariableError:a=>console.warn(`[OceanumLayer] ${a.message}`),onValidationError:a=>console.error(`[OceanumLayer] ${a.message}`)},U={serviceUrl:{type:"string",value:"https://layers.app.oceanum.io"},authHeaders:{type:"object",value:{}},layerId:{type:"string",value:null},instance:{type:"string",value:null},time:{type:"string",value:null},level:{type:"number",value:0},colormap:{type:"object",value:null},opacity:{type:"number",value:1},altitude:{type:"number",value:0},globalWrap:{type:"boolean",value:!1},scale:{type:"number",value:1},offset:{type:"number",value:0},pickable:{type:"boolean",value:!1},visible:{type:"boolean",value:!0},viewportPadding:{type:"number",value:.1},debounceWait:{type:"number",value:100},onDataLoad:{type:"function",value:null},errorHandlers:{type:"object",value:null},xvector:{type:"string",value:null},yvector:{type:"string",value:null},magnitude:{type:"string",value:null},direction:{type:"string",value:null},directionConvention:{type:"string",value:"NAUTICAL_FROM"}};function g(a){return a.props}function w(a){return a.state}function _(a){return a.context}class d extends R.CompositeLayer{static layerName="OceanumBaseLayer";static defaultProps=U;initializeState(){this.setState({dataset:null,loading:!1,slicing:!1,error:null,instance:null,coordNames:null,times:null,nlevels:0,lats:null,lons:null,timeIndex:0,levelIndex:0,latRange:[0,0],lonRange:[0,0],fetchedBbox:null,slicedData:null,datakeys:null,debouncedSlice:W(()=>this._requestSlice(),g(this).debounceWait)}),this._openDataset()}shouldUpdateState({changeFlags:e}){return e.somethingChanged}updateState({props:e,oldProps:n,changeFlags:t}){const l=e,o=n,r=w(this);if(l.debounceWait!==o.debounceWait&&(r.debouncedSlice&&r.debouncedSlice.cancel(),this.setState({debouncedSlice:W(()=>this._requestSlice(),l.debounceWait)})),l.layerId!==o.layerId||l.instance!==o.instance||l.serviceUrl!==o.serviceUrl||this._variablePropsChanged(l,o)){this._openDataset();return}if(!r.dataset)return;let s=!1;if(l.time!==o.time&&r.times){const i=l.time?C(r.times,l.time):0;i!==r.timeIndex&&(this.setState({timeIndex:i}),s=!0)}if(l.level!==o.level){const i=M(l.level||0,r.nlevels);i!==r.levelIndex&&(this.setState({levelIndex:i}),s=!0)}if(s){this._requestSlice();return}if(t.viewportChanged&&_(this).viewport){const i=V(_(this).viewport,l.viewportPadding);if(!j(i,r.fetchedBbox)){const c=S(r.lons,i.west,i.east),y=S(r.lats,i.south,i.north);this.setState({latRange:y,lonRange:c,fetchedBbox:i}),r.debouncedSlice&&r.debouncedSlice()}}}finalizeState(){const e=w(this);e.debouncedSlice&&e.debouncedSlice.cancel()}_variablePropsChanged(e,n){return e.magnitude!==n.magnitude||e.direction!==n.direction||e.xvector!==n.xvector||e.yvector!==n.yvector||e.directionConvention!==n.directionConvention}_validateVariableProps(e){return null}_buildDatakeys(e){return{x:e.x,y:e.y}}_createInnerLayer(e,n){return null}_fireError(e,n){const t={type:e,...n};this.setState({error:t});const l=g(this).errorHandlers||{},o=`on${e.charAt(0).toUpperCase()+e.slice(1)}Error`,r=l[o]||A[o];r&&r(t)}async _openDataset(){const e=g(this),{serviceUrl:n,layerId:t,authHeaders:l}=e;if(!n||!t)return;const o=this._validateVariableProps(e);if(o){this._fireError("validation",{message:o});return}this.setState({loading:!0,error:null});try{let r=`${n}/zarr/${t}`,s=e.instance;if(!s){const u=await this._discoverInstances(r,l||{});u.length>0&&(u.sort(),s=u[u.length-1])}s&&(r=`${r}/${s}`);const i=await B.Dataset.zarr(r,l||{}),c=i.coordkeys;if(!c||!c.x||!c.y)throw new Error("Dataset is missing required coordinate mappings (x, y) in _coordinates");const y=$(e);for(const u of y)if(!i.variables[u]){const L=Object.keys(i.variables);this._fireError("variable",{layerId:t,variable:u,availableVariables:L,message:`Variable "${u}" not found in dataset. Available: ${L.join(", ")}`}),this.setState({loading:!1});return}const[h,m,v]=await Promise.all([i.variables[c.x]?.get(),i.variables[c.y]?.get(),c.t&&i.variables[c.t]?i.variables[c.t].get():null]),b=c.z&&i.dimensions[c.z]?i.dimensions[c.z]:0,p=e.time&&v?C(v,e.time):0,O=M(e.level||0,b),x={x:c.x,y:c.y,t:c.t,z:c.z},D=this._buildDatakeys(x);let f=[0,m?m.length-1:0],I=[0,h?h.length-1:0],z=null;if(_(this).viewport){const u=V(_(this).viewport,e.viewportPadding);h&&(I=S(h,u.west,u.east)),m&&(f=S(m,u.south,u.north)),z=u}if(this.setState({dataset:i,loading:!1,instance:s,coordNames:x,times:v,nlevels:b,lats:m,lons:h,timeIndex:p,levelIndex:O,latRange:f,lonRange:I,fetchedBbox:z,datakeys:D}),e.onDataLoad){const u=v?Array.from(v,L=>new Date(L*1e3)):[];e.onDataLoad({dataset:i,times:u,nlevels:b,instance:s})}this._requestSlice()}catch(r){this._fireError("metadata",{layerId:t,message:`Failed to open dataset: ${r.message}`,cause:r}),this.setState({loading:!1})}}async _discoverInstances(e,n){try{const t=await fetch(`${e}/.zmetadata`,{headers:n});if(!t.ok)return[];const l=await t.json();if(!l.metadata)return[];const o=new Set;for(const r of Object.keys(l.metadata)){const s=r.split("/");s.length===2&&s[1]===".zgroup"&&o.add(s[0])}return Array.from(o)}catch{return[]}}async _requestSlice(){const e=w(this),{dataset:n,coordNames:t,timeIndex:l,levelIndex:o,latRange:r,lonRange:s}=e;if(!n||!t)return;const i=$(g(this));if(i.length!==0){this.setState({slicing:!0});try{const c=await T(n,t,i,l,o,r,s);this.setState({slicedData:c,slicing:!1,error:null})}catch(c){this._fireError("chunk",{layerId:g(this).layerId,time:e.times?new Date(e.times[l]*1e3):null,level:o,message:`Chunk fetch failed: ${c.message}`,cause:c}),this.setState({slicing:!1})}}}renderLayers(){const e=w(this);return!e.slicedData||!e.datakeys?[]:this._createInnerLayer(e.slicedData,e.datakeys)}}const H={...d.defaultProps,color:{type:"array",value:[200,200,200]},material:!1};class X extends d{static layerName="OceanumPcolorLayer";static defaultProps=H;_validateVariableProps(e){const n=!!e.magnitude,t=e.xvector&&e.yvector;return!n&&!t?'OceanumPcolorLayer requires "magnitude" or "xvector" + "yvector"':null}_buildDatakeys(e){return E(e,this.props)}_createInnerLayer(e,n){const t=this.props;return new k.PcolorLayer({id:`${t.id}-inner`,data:e,datakeys:n,opacity:t.opacity,altitude:t.altitude,globalWrap:t.globalWrap,colormap:t.colormap,scale:t.scale,offset:t.offset,color:t.color,material:t.material,pickable:t.pickable,visible:t.visible})}}const Y={...d.defaultProps,speed:{type:"number",value:1},npart:{type:"number",value:1e3},size:{type:"number",value:3},length:{type:"number",value:12},color:{type:"array",value:[200,200,200]}};class F extends d{static layerName="OceanumParticleLayer";static defaultProps=Y;_validateVariableProps(e){const n=e.xvector&&e.yvector,t=e.magnitude&&e.direction;return!n&&!t?'OceanumParticleLayer requires "xvector" + "yvector" or "magnitude" + "direction"':n&&t?'OceanumParticleLayer: provide "xvector" + "yvector" or "magnitude" + "direction", not both':null}_buildDatakeys(e){return q(e,this.props)}_createInnerLayer(e,n){const t=this.props;return new k.ParticleLayer({id:`${t.id}-inner`,data:e,datakeys:n,opacity:t.opacity,altitude:t.altitude,globalWrap:t.globalWrap,colormap:t.colormap,scale:t.scale,offset:t.offset,color:t.color,direction:t.directionConvention,speed:t.speed,npart:t.npart,size:t.size,length:t.length,pickable:t.pickable,visible:t.visible})}}const N={...d.defaultProps,speed:{type:"number",value:1},size:{type:"number",value:3},color:{type:"array",value:[200,200,200]},meshShape:{type:"string",value:"cone"},meshLength:{type:"number",value:4},meshWidth:{type:"number",value:1},meshSize:{type:"number",value:1}};class G extends d{static layerName="OceanumPartmeshLayer";static defaultProps=N;_validateVariableProps(e){const n=e.xvector&&e.yvector,t=e.magnitude&&e.direction;return!n&&!t?'OceanumPartmeshLayer requires "xvector" + "yvector" or "magnitude" + "direction"':n&&t?'OceanumPartmeshLayer: provide "xvector" + "yvector" or "magnitude" + "direction", not both':null}_buildDatakeys(e){return q(e,this.props)}_createInnerLayer(e,n){const t=this.props;return new k.PartmeshLayer({id:`${t.id}-inner`,data:e,datakeys:n,opacity:t.opacity,altitude:t.altitude,globalWrap:t.globalWrap,colormap:t.colormap,scale:t.scale,offset:t.offset,color:t.color,direction:t.directionConvention,speed:t.speed,size:t.size,mesh:{shape:t.meshShape,length:t.meshLength,width:t.meshWidth,size:t.meshSize},pickable:t.pickable,visible:t.visible})}}const J={...d.defaultProps,levels:{type:"array",value:[]},labelSize:{type:"number",value:12},labelColor:{type:"array",value:[255,255,255,255]},smoothing:{type:"boolean",value:!1},numLabels:{type:"number",value:1},color:{type:"array",value:[200,200,200]}};class K extends d{static layerName="OceanumContourLayer";static defaultProps=J;_validateVariableProps(e){const n=!!e.magnitude,t=e.xvector&&e.yvector;return!n&&!t?'OceanumContourLayer requires "magnitude" or "xvector" + "yvector"':null}_buildDatakeys(e){return E(e,this.props)}_createInnerLayer(e,n){const t=this.props;return new k.ContourLayer({id:`${t.id}-inner`,data:e,datakeys:n,opacity:t.opacity,altitude:t.altitude,globalWrap:t.globalWrap,colormap:t.colormap,scale:t.scale,offset:t.offset,color:t.color,levels:t.levels,labelSize:t.labelSize,labelColor:t.labelColor,smoothing:t.smoothing,numLabels:t.numLabels,pickable:t.pickable,visible:t.visible})}}exports.OceanumBaseLayer=d;exports.OceanumContourLayer=K;exports.OceanumParticleLayer=F;exports.OceanumPartmeshLayer=G;exports.OceanumPcolorLayer=X;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as OceanumPcolorLayer } from './oceanum-pcolor-layer';
|
|
2
|
+
export { default as OceanumParticleLayer } from './oceanum-particle-layer';
|
|
3
|
+
export { default as OceanumPartmeshLayer } from './oceanum-partmesh-layer';
|
|
4
|
+
export { default as OceanumContourLayer } from './oceanum-contour-layer';
|
|
5
|
+
export { default as OceanumBaseLayer } from './oceanum-base-layer';
|
|
6
|
+
export type { Colormap, LayerError, ErrorHandlers, OnDataLoadInfo, OceanumLayerProps, } from './oceanum-base-layer';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAC3E,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnE,YAAY,EACV,QAAQ,EACR,UAAU,EACV,aAAa,EACb,cAAc,EACd,iBAAiB,GAClB,MAAM,sBAAsB,CAAC"}
|