Skip to content

Commit 3e3fa7a

Browse files
committed
Add zoom
1 parent c7e58a7 commit 3e3fa7a

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

src/App.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const INITIAL_VIEW_STATE = {
2222
latitude: 51.47,
2323
longitude: 0.45,
2424
zoom: 0,
25-
maxZoom: 1,
25+
maxZoom: 20,
2626
};
2727

2828
const MAP_STYLE =
@@ -88,8 +88,8 @@ function App() {
8888
// maxCacheByteSize: null,
8989
// maxCacheSize: null,
9090
// maxRequests: 6,
91-
// maxZoom: 19,
92-
// minZoom: 0,
91+
maxZoom: zarrReader.maxZoom,
92+
minZoom: zarrReader.minZoom,
9393
// onTileError: null,
9494
// onTileLoad: null,
9595
// onTileUnload: null,
@@ -162,6 +162,7 @@ function App() {
162162
<RangeSlider
163163
minMax={[zarrReader.scale.min, zarrReader.scale.max]}
164164
label="Scale"
165+
// @ts-expect-error: already fixed in the feature branch
165166
onValueChange={setMinMax}
166167
/>
167168

src/zarr/index.ts

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@ import type {
77
NumberDataType,
88
} from "zarrita";
99
import { findMinMax } from "./utils";
10-
interface ZarrReaderProps {
10+
type ZarrReaderProps = {
1111
zarrUrl: string;
1212
varName: string;
13-
}
13+
};
1414

15-
interface TileIndex {
15+
type TileIndex = {
1616
x: number;
1717
y: number;
1818
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+
};
2026

2127
export default class ZarrReader {
2228
private root!: Location<FetchStore>;
@@ -28,6 +34,7 @@ export default class ZarrReader {
2834
private _tileSize: number = 256;
2935
// @TODO: hard coding for now
3036
private _t: number = 0;
37+
private _zooms!: { min: number; max: number };
3138

3239
get scale() {
3340
return this._scale;
@@ -41,6 +48,12 @@ export default class ZarrReader {
4148
get metadata() {
4249
return this._metadata;
4350
}
51+
get minZoom() {
52+
return this._zooms.min;
53+
}
54+
get maxZoom() {
55+
return this._zooms.max;
56+
}
4457

4558
private constructor() {}
4659

@@ -74,6 +87,22 @@ export default class ZarrReader {
7487
min: minMax.min,
7588
};
7689
}
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+
}
77106
}
78107

79108
async getTileData({
@@ -89,12 +118,13 @@ export default class ZarrReader {
89118
});
90119

91120
if (arr.is("number")) {
92-
const { data } = await arr.getChunk([timestamp, y, x]);
121+
const { data } = await arr.getChunk([this._t, y, x]);
93122
// @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;
96127
}
97-
98128
return data;
99129
} else {
100130
return undefined;

0 commit comments

Comments
 (0)