@@ -7,16 +7,22 @@ import type {
7
7
NumberDataType ,
8
8
} from "zarrita" ;
9
9
import { findMinMax } from "./utils" ;
10
- interface ZarrReaderProps {
10
+ type ZarrReaderProps = {
11
11
zarrUrl : string ;
12
12
varName : string ;
13
- }
13
+ } ;
14
14
15
- interface TileIndex {
15
+ type TileIndex = {
16
16
x : number ;
17
17
y : number ;
18
18
z : number ;
19
- }
19
+ } ;
20
+
21
+ type Multiscale = {
22
+ tile_matrix_set : "WebMercatorQuad" ;
23
+ resampling_method : string ;
24
+ tile_matrix_limits : Record < string , unknown > ;
25
+ } ;
20
26
21
27
export default class ZarrReader {
22
28
private root ! : Location < FetchStore > ;
@@ -28,6 +34,7 @@ export default class ZarrReader {
28
34
private _tileSize : number = 256 ;
29
35
// @TODO : hard coding for now
30
36
private _t : number = 0 ;
37
+ private _zooms ! : { min : number ; max : number } ;
31
38
32
39
get scale ( ) {
33
40
return this . _scale ;
@@ -41,6 +48,12 @@ export default class ZarrReader {
41
48
get metadata ( ) {
42
49
return this . _metadata ;
43
50
}
51
+ get minZoom ( ) {
52
+ return this . _zooms . min ;
53
+ }
54
+ get maxZoom ( ) {
55
+ return this . _zooms . max ;
56
+ }
44
57
45
58
private constructor ( ) { }
46
59
@@ -74,6 +87,22 @@ export default class ZarrReader {
74
87
min : minMax . min ,
75
88
} ;
76
89
}
90
+
91
+ const zarrMetadata = await zarr . open . v3 ( this . root . resolve ( `${ varName } ` ) , {
92
+ kind : "array" ,
93
+ } ) ;
94
+ const multiscale = zarrMetadata . attrs . multiscales as Multiscale ;
95
+
96
+ if ( multiscale ?. tile_matrix_limits ) {
97
+ this . _zooms = {
98
+ min : Math . min (
99
+ ...Object . keys ( multiscale . tile_matrix_limits ) . map ( ( e ) => Number ( e ) )
100
+ ) ,
101
+ max : Math . max (
102
+ ...Object . keys ( multiscale . tile_matrix_limits ) . map ( ( e ) => Number ( e ) )
103
+ ) ,
104
+ } ;
105
+ }
77
106
}
78
107
79
108
async getTileData ( {
@@ -89,12 +118,13 @@ export default class ZarrReader {
89
118
} ) ;
90
119
91
120
if ( arr . is ( "number" ) ) {
92
- const { data } = await arr . getChunk ( [ timestamp , y , x ] ) ;
121
+ const { data } = await arr . getChunk ( [ this . _t , y , x ] ) ;
93
122
// @TODO : remove once the data has actual timestamps
94
- if ( timestamp == 2 ) {
95
- return new Float32Array ( this . tileSize * this . tileSize ) ;
123
+ if ( timestamp % 2 == 1 ) {
124
+ const tempArray = new Float32Array ( this . tileSize * this . tileSize ) ;
125
+ tempArray . fill ( this . scale . min ) ;
126
+ return tempArray ;
96
127
}
97
-
98
128
return data ;
99
129
} else {
100
130
return undefined ;
0 commit comments