This repository has been archived by the owner on Aug 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 215
/
Copy pathlat_long_to_octant.js
53 lines (43 loc) · 1.52 KB
/
lat_long_to_octant.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
42
43
44
45
46
47
48
49
50
51
52
53
"use strict"
/**************************** config ****************************/
const PLANET = 'earth';
const URL_PREFIX = `https://kh.google.com/rt/${PLANET}/`;
const MAX_LEVEL = 18;
/****************************************************************/
const utils = require('./lib/utils')({
URL_PREFIX, DUMP_JSON_DIR: null, DUMP_RAW_DIR: null, DUMP_JSON: false, DUMP_RAW: false
});
const latLongToOctant = require('./lib/convert-lat-long-to-octant')(utils);
/***************************** main *****************************/
async function run() {
let [lat, lon] = [process.argv[2], process.argv[3]];
if ([lat, lon].includes(undefined)) {
const invoc = `node ${require('path').basename(__filename)}`;
console.error(`Usage:`);
console.error(` ${invoc} [latitude] [longitude]`);
console.error(` ${invoc} 37.420806884765625 -122.08419799804688`);
process.exit(1);
}
[lat, lon] = [parseFloat(lat), parseFloat(lon)];
const foundOctants = await latLongToOctant(lat, lon, MAX_LEVEL);
console.log(lat + ', ' + lon);
console.log('-------------');
for (let octantLevel in foundOctants) {
let octants = foundOctants[octantLevel].octants;
let box = foundOctants[octantLevel].box;
console.log("Octant Level:", octantLevel);
console.log(box);
for (let i = 0; i < octants.length; i++) {
console.log(" " + octants[i]);
}
}
}
/****************************************************************/
(async function program() {
await run();
})().then(() => {
process.exit(0);
}).catch(e => {
console.error(e);
process.exit(1);
});