Skip to content

Commit fd24e31

Browse files
author
Vincent van der Wal
committed
cleanup types and center every domain
1 parent e42f579 commit fd24e31

File tree

8 files changed

+199
-201
lines changed

8 files changed

+199
-201
lines changed

.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ VITE_DOMAIN=dwd_icon_d2
22
VITE_VARIABLE=temperature_2m
33
VITE_TILE_SIZE=256
44
VITE_TILE_OPACITY=70
5-
VITE_BUILD=package

src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ let showTemp = false;
125125
if (mapContainer) {
126126
maplibregl.addProtocol('om', omProtocol);
127127

128+
console.log(domains);
129+
128130
map = new maplibregl.Map({
129131
container: mapContainer,
130132
style: `https://maptiler.servert.nl/styles/basic-world-maps/style.json`,

src/om-protocol.ts

Lines changed: 14 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@ import {
77
type TypedArray
88
} from '@openmeteo/file-reader';
99

10-
import { getIndexFromLatLong, interpolate2DHermite } from './utils/math';
10+
import {
11+
interpolate2DHermite,
12+
getBorderPoints,
13+
getBoundsFromGrid,
14+
getIndexFromLatLong,
15+
getBoundsFromBorderPoints
16+
} from './utils/math';
1117

1218
import { domains } from './utils/domains';
13-
import { variables } from './utils/variables';
19+
import { variables, requestMultiple } from './utils/variables';
1420

1521
import TileWorker from './worker?worker';
1622

17-
import type { TileJSON, TileIndex, Domain, Variable } from './types';
23+
import type { TileJSON, TileIndex, Domain, Variable, Bounds } from './types';
1824
import { DynamicProjection, ProjectionGrid, type Projection } from './utils/projection';
1925

20-
const ONE_HOUR_IN_MILLISECONDS = 60 * 60 * 1000;
21-
2226
let domain: Domain;
2327
let variable: Variable;
2428

@@ -144,75 +148,13 @@ const renderTile = async (url: string) => {
144148
return tile;
145149
};
146150

147-
const getBorderPoints = () => {
148-
const points = [];
149-
for (let i = 0; i < projectionGrid.ny; i++) {
150-
points.push([
151-
projectionGrid.origin[0],
152-
projectionGrid.origin[1] + i * projectionGrid.dy
153-
]);
154-
}
155-
for (let i = 0; i < projectionGrid.nx; i++) {
156-
points.push([
157-
projectionGrid.origin[0] + i * projectionGrid.dx,
158-
projectionGrid.origin[1] + projectionGrid.ny * projectionGrid.dy
159-
]);
160-
}
161-
for (let i = projectionGrid.ny; i >= 0; i--) {
162-
points.push([
163-
projectionGrid.origin[0] + projectionGrid.nx * projectionGrid.dx,
164-
projectionGrid.origin[1] + i * projectionGrid.dy
165-
]);
166-
}
167-
for (let i = projectionGrid.nx; i >= 0; i--) {
168-
points.push([
169-
projectionGrid.origin[0] + i * projectionGrid.dx,
170-
projectionGrid.origin[1]
171-
]);
172-
}
173-
174-
return points;
175-
};
176-
177151
const getTilejson = async (fullUrl: string): Promise<TileJSON> => {
178-
let minLon;
179-
let minLat;
180-
let maxLon;
181-
let maxLat;
182-
183-
let bounds;
152+
let bounds: Bounds;
184153
if (domain.grid.projection) {
185-
// loop over all border points to get max / min lat / lon
186-
const borderPoints = getBorderPoints();
187-
minLon = 180;
188-
minLat = 90;
189-
maxLon = -180;
190-
maxLat = -90;
191-
for (let borderPoint of borderPoints) {
192-
const borderPointLatLon = projection.reverse(
193-
borderPoint[0],
194-
borderPoint[1]
195-
);
196-
if (borderPointLatLon[0] < minLat) {
197-
minLat = borderPointLatLon[0];
198-
}
199-
if (borderPointLatLon[0] > maxLat) {
200-
maxLat = borderPointLatLon[0];
201-
}
202-
if (borderPointLatLon[1] < minLon) {
203-
minLon = borderPointLatLon[1];
204-
}
205-
if (borderPointLatLon[1] > maxLon) {
206-
maxLon = borderPointLatLon[1];
207-
}
208-
}
209-
bounds = [minLon, minLat, maxLon, maxLat];
154+
const borderPoints = getBorderPoints(projectionGrid);
155+
bounds = getBoundsFromBorderPoints(borderPoints, projection);
210156
} else {
211-
minLon = lonMin;
212-
minLat = latMin;
213-
maxLon = minLon + dx * nx;
214-
maxLat = minLat + dy * ny;
215-
bounds = [minLon, minLat, maxLon, maxLat];
157+
bounds = getBoundsFromGrid(lonMin, latMin, dx, dy, nx, ny);
216158
}
217159

218160
return {
@@ -277,7 +219,7 @@ const initOMFile = async (url: string) => {
277219
);
278220
}
279221

280-
if (variable.value === 'wind') {
222+
if (requestMultiple.includes(variable.value)) {
281223
fileReader.backendu = new MemoryHttpBackend({
282224
url: omUrl.replace('wind.om', 'wind_u_component_10m.om'),
283225
maxFileSize: 500 * 1024 * 1024 // 500 MB

src/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,15 @@ export interface Domain {
8282
export interface DomainGroups {
8383
[key: string]: Domain[];
8484
}
85+
86+
export type Bounds = [
87+
minimumLongitude: number,
88+
minimumLatitude: number,
89+
maximumLongitude: number,
90+
maximumLatitude: number
91+
];
92+
93+
export interface Center {
94+
lng: number;
95+
lat: number;
96+
}

0 commit comments

Comments
 (0)