|
|
"use strict";
|
|
|
import { writeFile } from 'fs/promises';
|
|
|
import fetch from 'node-fetch';
|
|
|
|
|
|
async function main() {
|
|
|
// SET BASE-10 ID HERE
|
|
|
const id10 = 1248148552;
|
|
|
|
|
|
// Convert Decimal ID to Quaternary
|
|
|
const id4 = toBase(id10, 4);
|
|
|
|
|
|
for (let face = 1; face <= 6; face++) {
|
|
|
// Convert cube face number into quaternary and ensure it's two digits
|
|
|
const face4 = toBase(face, 4).padStart(2, "0");
|
|
|
|
|
|
// Loop though all 8×8=64 tiles.
|
|
|
for (let position = 0; position < 64; position++) {
|
|
|
// Convert position into quaternary and ensure it's three digits
|
|
|
const position4 = toBase(position, 4).padStart(3, "0");
|
|
|
// Format url with Image ID, Cube Face, and Tile Position, all in quaternary
|
|
|
const url = `https://t.ssl.ak.tiles.virtualearth.net/tiles/`
|
|
|
+ `hs${id4}${face4}${position4}.jpg?g=0`;
|
|
|
|
|
|
// Download tile
|
|
|
const response = await fetch(url);
|
|
|
const imageData = response.body;
|
|
|
console.log("downloaded: ", url);
|
|
|
|
|
|
// Save tile into out directory
|
|
|
const filename = `out/${face4}${position4}.jpg`;
|
|
|
await writeFile(filename, imageData);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Function to clarify when base conversions are happening as JavaScript's way of doing this is unintuitive
|
|
|
function toBase(number, base) {
|
|
|
return number.toString(base);
|
|
|
}
|
|
|
|
|
|
main(); |