-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (33 loc) · 874 Bytes
/
index.js
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
const fs = require('fs');
const path = require('path');
const readLookupSync = () => {
let raw = fs.readFileSync(
path.resolve(__dirname, 'lookup.csv'),
'utf8'
);
let lookup = raw.split('\n');
// Remove headers
lookup.shift();
// Structure data
lookup = lookup.map(tile => {
tile = tile.split(',');
return {
x: parseInt(tile[0], 10),
y: parseInt(tile[1], 10),
lonMin: parseFloat(tile[2], 10),
lonMax: parseFloat(tile[3], 10),
latMin: parseFloat(tile[4], 10),
latMax: parseFloat(tile[5], 10)
};
});
return lookup;
};
const lookup = readLookupSync();
const findByCoords = coords => {
let [lon, lat] = coords;
return lookup.find(tile => {
return (lon >= tile.lonMin && lon <= tile.lonMax) &&
(lat >= tile.latMin && lat <= tile.latMax);
});
};
module.exports = findByCoords;