kopia lustrzana https://github.com/rastapasta/mapscii
Remove bluebird (#94)
rodzic
a7e7621705
commit
247122f684
|
@ -91,7 +91,6 @@ If your terminal supports mouse events you can drag the map and use your scroll
|
||||||
* [`simplify-js`](https://github.com/mourner/simplify-js) for polyline simplifications
|
* [`simplify-js`](https://github.com/mourner/simplify-js) for polyline simplifications
|
||||||
|
|
||||||
#### Handling the flow
|
#### Handling the flow
|
||||||
* [`bluebird`](https://github.com/petkaantonov/bluebird) for all the asynchronous [Promise](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Promise) magic
|
|
||||||
* [`node-fetch`](https://github.com/bitinn/node-fetch) for HTTP requests
|
* [`node-fetch`](https://github.com/bitinn/node-fetch) for HTTP requests
|
||||||
* [`env-paths`](https://github.com/sindresorhus/env-paths) to determine where to persist downloaded tiles
|
* [`env-paths`](https://github.com/sindresorhus/env-paths) to determine where to persist downloaded tiles
|
||||||
|
|
||||||
|
|
|
@ -1107,11 +1107,6 @@
|
||||||
"tweetnacl": "^0.14.3"
|
"tweetnacl": "^0.14.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"bluebird": {
|
|
||||||
"version": "3.7.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz",
|
|
||||||
"integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg=="
|
|
||||||
},
|
|
||||||
"brace-expansion": {
|
"brace-expansion": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.11",
|
||||||
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mapbox/vector-tile": "^1.3.1",
|
"@mapbox/vector-tile": "^1.3.1",
|
||||||
"bluebird": "^3.7.2",
|
|
||||||
"bresenham": "0.0.4",
|
"bresenham": "0.0.4",
|
||||||
"earcut": "^2.2.2",
|
"earcut": "^2.2.2",
|
||||||
"env-paths": "^2.2.0",
|
"env-paths": "^2.2.0",
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
The Console Vector Tile renderer - bäm!
|
The Console Vector Tile renderer - bäm!
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
const Promise = require('bluebird');
|
|
||||||
const x256 = require('x256');
|
const x256 = require('x256');
|
||||||
const simplify = require('simplify-js');
|
const simplify = require('simplify-js');
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@ class Renderer {
|
||||||
this.canvas = new Canvas(width, height);
|
this.canvas = new Canvas(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
draw(center, zoom) {
|
async draw(center, zoom) {
|
||||||
if (this.isDrawing) return Promise.reject();
|
if (this.isDrawing) return Promise.reject();
|
||||||
this.isDrawing = true;
|
this.isDrawing = true;
|
||||||
|
|
||||||
|
@ -49,21 +48,20 @@ class Renderer {
|
||||||
|
|
||||||
this.canvas.clear();
|
this.canvas.clear();
|
||||||
|
|
||||||
return Promise.resolve(this._visibleTiles(center, zoom)).map((tile) => {
|
try {
|
||||||
return this._getTile(tile);
|
let tiles = this._visibleTiles(center, zoom);
|
||||||
}).map((tile) => {
|
await Promise.all(tiles.map(async(tile) => {
|
||||||
return this._getTileFeatures(tile, zoom);
|
await this._getTile(tile);
|
||||||
}).then((tiles) => {
|
this._getTileFeatures(tile, zoom);
|
||||||
this._renderTiles(tiles);
|
}));
|
||||||
}).then(() => {
|
await this._renderTiles(tiles);
|
||||||
return this._getFrame();
|
return this._getFrame();
|
||||||
}).catch((e) => {
|
} catch(e) {
|
||||||
return console.log(e);
|
console.error(e);
|
||||||
}).finally((frame) => {
|
} finally {
|
||||||
this.isDrawing = false;
|
this.isDrawing = false;
|
||||||
this.lastDrawAt = Date.now();
|
this.lastDrawAt = Date.now();
|
||||||
return frame;
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_visibleTiles(center, zoom) {
|
_visibleTiles(center, zoom) {
|
||||||
|
@ -104,13 +102,9 @@ class Renderer {
|
||||||
return tiles;
|
return tiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
_getTile(tile) {
|
async _getTile(tile) {
|
||||||
return this.tileSource
|
tile.data = await this.tileSource.getTile(tile.xyz.z, tile.xyz.x, tile.xyz.y);
|
||||||
.getTile(tile.xyz.z, tile.xyz.x, tile.xyz.y)
|
return tile;
|
||||||
.then((data) => {
|
|
||||||
tile.data = data;
|
|
||||||
return tile;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_getTileFeatures(tile, zoom) {
|
_getTileFeatures(tile, zoom) {
|
||||||
|
@ -140,6 +134,7 @@ class Renderer {
|
||||||
|
|
||||||
_renderTiles(tiles) {
|
_renderTiles(tiles) {
|
||||||
const labels = [];
|
const labels = [];
|
||||||
|
if (tiles.length === 0) return;
|
||||||
|
|
||||||
const drawOrder = this._generateDrawOrder(tiles[0].xyz.z);
|
const drawOrder = this._generateDrawOrder(tiles[0].xyz.z);
|
||||||
for (const layerId of drawOrder) {
|
for (const layerId of drawOrder) {
|
||||||
|
|
Ładowanie…
Reference in New Issue