@watergis/postgis2mbtiles
Version:
A module extracting the data from PostGIS to mbtiles by using tippecanoe.
50 lines • 1.92 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const child_process_1 = require("child_process");
const postgis2geojson_1 = require("@watergis/postgis2geojson");
class postgis2mbtiles {
constructor(config) {
this.config = config;
}
run() {
return new Promise((resolve, reject) => {
const pg2json = new postgis2geojson_1.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_1.default.existsSync(mbtiles)) {
fs_1.default.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(' ')}`;
child_process_1.execSync(cmd).toString();
geojsonfiles.forEach((f) => {
fs_1.default.unlinkSync(f);
});
console.log(`Creating voctor tile was done successfully at ${mbtiles}`);
resolve(mbtiles);
}
catch (err) {
reject(err);
}
});
}
}
exports.default = postgis2mbtiles;
//# sourceMappingURL=postgis2mbtiles.js.map