UNPKG

@watergis/postgis2mbtiles

Version:

A module extracting the data from PostGIS to mbtiles by using tippecanoe.

45 lines 1.61 kB
import fs from 'fs'; import { execSync } from 'child_process'; import { postgis2geojson } from '@watergis/postgis2geojson'; class postgis2mbtiles { constructor(config) { this.config = config; } run() { return new Promise((resolve, reject) => { const pg2json = new postgis2geojson(this.config); pg2json .run() .then((geojsonfiles) => { return this.createMbtiles(geojsonfiles, this.config.mbtiles); }) .then((file) => { resolve(file); }) .catch((err) => { reject(err); }); }); } createMbtiles(geojsonfiles, mbtiles) { return new Promise((resolve, reject) => { try { if (fs.existsSync(mbtiles)) { fs.unlinkSync(mbtiles); } const cmd = `tippecanoe -rg -z${this.config.maxzoom} -Z${this.config.minzoom} --name="${this.config.name}" --description="${this.config.description}" --attribution="${this.config.attribution}" -o ${mbtiles} ${geojsonfiles.join(' ')}`; execSync(cmd).toString(); geojsonfiles.forEach((f) => { fs.unlinkSync(f); }); console.log(`Creating voctor tile was done successfully at ${mbtiles}`); resolve(mbtiles); } catch (err) { reject(err); } }); } } export default postgis2mbtiles; //# sourceMappingURL=postgis2mbtiles.js.map