@@ -7,18 +7,22 @@ import {
7
7
type TypedArray
8
8
} from '@openmeteo/file-reader' ;
9
9
10
- import { getIndexFromLatLong , interpolate2DHermite } from './utils/math' ;
10
+ import {
11
+ interpolate2DHermite ,
12
+ getBorderPoints ,
13
+ getBoundsFromGrid ,
14
+ getIndexFromLatLong ,
15
+ getBoundsFromBorderPoints
16
+ } from './utils/math' ;
11
17
12
18
import { domains } from './utils/domains' ;
13
- import { variables } from './utils/variables' ;
19
+ import { variables , requestMultiple } from './utils/variables' ;
14
20
15
21
import TileWorker from './worker?worker' ;
16
22
17
- import type { TileJSON , TileIndex , Domain , Variable } from './types' ;
23
+ import type { TileJSON , TileIndex , Domain , Variable , Bounds } from './types' ;
18
24
import { DynamicProjection , ProjectionGrid , type Projection } from './utils/projection' ;
19
25
20
- const ONE_HOUR_IN_MILLISECONDS = 60 * 60 * 1000 ;
21
-
22
26
let domain : Domain ;
23
27
let variable : Variable ;
24
28
@@ -144,75 +148,13 @@ const renderTile = async (url: string) => {
144
148
return tile ;
145
149
} ;
146
150
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
-
177
151
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 ;
184
153
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 ) ;
210
156
} 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 ) ;
216
158
}
217
159
218
160
return {
@@ -277,7 +219,7 @@ const initOMFile = async (url: string) => {
277
219
) ;
278
220
}
279
221
280
- if ( variable . value === 'wind' ) {
222
+ if ( requestMultiple . includes ( variable . value ) ) {
281
223
fileReader . backendu = new MemoryHttpBackend ( {
282
224
url : omUrl . replace ( 'wind.om' , 'wind_u_component_10m.om' ) ,
283
225
maxFileSize : 500 * 1024 * 1024 // 500 MB
0 commit comments