-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.ts
86 lines (77 loc) · 2.61 KB
/
options.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import path from 'path';
const __dirname = path.resolve();
// const BOUNDS = { north: 53, west: 0, south: 72.7, east: 35.5 };
const BOUNDS = { north: 65.7, west: 0, south: 57.95, east: 18 };
const ZOOM_LEVEL = 5;
const TILE_SIZE = 256;
// We are not providing a real URL here, so if you want to play around with this code you need to find
// or build a raster tile server that can provide the tiles for the background.
const BACKGROUND_URL_TEMPLATE = 'some-raster-tile-server/tiles/{z}/{x}/{y}.png';
const WIND_SOURCE = 'https://beta.yr-maps.met.no/api/wind/';
const TEMPERATURE_SOURCE = 'https://beta.yr-maps.met.no/api/air-temperature/';
export interface IOptions {
bounds: { north: number; west: number; south: number; east: number };
zoomLevel: number;
tileSize: number;
backgroundTiles: {
tempFilePathTemplate: string;
urlTemplate: string;
fileName: string;
};
windTiles: {
tempFilePathTemplate: string;
urlTemplate: string;
fileName: string;
};
temperatureTiles: {
tempFilePathTemplate: string;
urlTemplate: string;
fileName: string;
};
}
export async function getOptions(): Promise<IOptions> {
const windData = await fetchTileData(WIND_SOURCE);
const temperatureData = await fetchTileData(TEMPERATURE_SOURCE);
const windUrlTemplate = windData.times[0].tiles.png;
const temperatureUrlTemplate = temperatureData.times[0].tiles.png;
return {
bounds: BOUNDS,
zoomLevel: ZOOM_LEVEL,
tileSize: TILE_SIZE,
backgroundTiles: {
tempFilePathTemplate: __dirname + '/scripts/temp/backgroundTiles/{z}-{x}-{y}.png',
urlTemplate: BACKGROUND_URL_TEMPLATE,
fileName: __dirname + '/public/background.png',
},
windTiles: {
tempFilePathTemplate: __dirname + '/scripts/temp/windTiles/{z}-{x}-{y}.png',
urlTemplate: windUrlTemplate,
fileName: __dirname + '/public/wind.png',
},
temperatureTiles: {
tempFilePathTemplate: __dirname + '/scripts/temp/temperatureTiles/{z}-{x}-{y}.png',
urlTemplate: temperatureUrlTemplate,
fileName: __dirname + '/public/temperature.png',
},
};
}
// Function for calling the Met sources wich has an available.json file where we can find the base url for the images
async function fetchTileData(url: string): Promise<IApiTileData> {
const response = await fetch(url);
const data = (await response.json()) as IApiTileData;
return data;
}
export interface IApiTileData {
bounds: [number, number, number, number];
minZoom: number;
maxZoom: number;
scheme: 'xyz';
times: Array<{
time: string;
tiles: {
jpeg: string;
png: string;
webp: string;
};
}>;
}