promisify some Tile creation
This commit is contained in:
parent
4a88523eab
commit
ae927972ae
|
@ -358,15 +358,15 @@ export async function createZoomedTile(
|
|||
|
||||
const startTime = Date.now();
|
||||
const na = [];
|
||||
for (let dy = 0; dy < TILE_ZOOM_LEVEL; dy += 1) {
|
||||
for (let dx = 0; dx < TILE_ZOOM_LEVEL; dx += 1) {
|
||||
|
||||
const prom = async (dx, dy) => {
|
||||
// eslint-disable-next-line max-len
|
||||
const chunkfile = `${canvasTileFolder}/${z + 1}/${x * TILE_ZOOM_LEVEL + dx}/${y * TILE_ZOOM_LEVEL + dy}.png`;
|
||||
try {
|
||||
if (!fs.existsSync(chunkfile)) {
|
||||
na.push([dx, dy]);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const chunk = await sharp(chunkfile).removeAlpha().raw().toBuffer();
|
||||
addShrunkenSubtileToTile(
|
||||
TILE_ZOOM_LEVEL,
|
||||
|
@ -375,13 +375,21 @@ export async function createZoomedTile(
|
|||
tileRGBBuffer,
|
||||
);
|
||||
} catch (error) {
|
||||
na.push([dx, dy]);
|
||||
console.error(
|
||||
// eslint-disable-next-line max-len
|
||||
`Tiling: Error on createZoomedTile on chunk ${chunkfile}: ${error.message}`,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const promises = [];
|
||||
for (let dy = 0; dy < TILE_ZOOM_LEVEL; dy += 1) {
|
||||
for (let dx = 0; dx < TILE_ZOOM_LEVEL; dx += 1) {
|
||||
promises.push(prom(dx, dy));
|
||||
}
|
||||
}
|
||||
await Promise.all(promises);
|
||||
|
||||
if (na.length !== TILE_ZOOM_LEVEL * TILE_ZOOM_LEVEL) {
|
||||
na.forEach((element) => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user