-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddExtraLevelsToPlanet.js
59 lines (51 loc) · 1.64 KB
/
addExtraLevelsToPlanet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const fs = require('fs');
const path = require('path');
const syncEach = require('sync-each');
const UtilsMbtiles = require('./utilsMbtiles');
const _f = require('./config');
const hrstart = process.hrtime();
const mbtiles_ori = _f.mbtiles_ori;
const mbtiles_dest = _f.mbtiles_dest;
const zoom_levels = _f.zoom_levels_extra;
async function writeAddTiles(origen_mbt, destino_mbt, z_levels){
z_levels.forEach(async (item) => {
try{
const tiles = await UtilsMbtiles.leerJson('tiles'+item+'.geojson');
console.info(tiles.features.length);
let i=0;
syncEach(tiles.features,
function(feat, next){
(async () => {
if(!feat.properties.id){
feat.properties.id = feat.id;
}
const tilezxy = UtilsMbtiles.idTile2ZXY(feat.properties.id);
let tileid;
tileid = await UtilsMbtiles.addNewTile(origen_mbt, destino_mbt, tilezxy);
i=i+1;
console.info(i + " de " +tiles.features.length);
tileid = await UtilsMbtiles.replaceTilePlanet(origen_mbt, destino_mbt, tilezxy);
next(null,tileid);
})();
},
function(err, transformedItems){
console.log(transformedItems);
}
);
}catch(err){
console.log(err);
}
});
}
async function writeMbTiles(uri_origen, uri_destino, z_levels){
console.log(uri_origen);
console.log(uri_destino);
try{
const origen = await UtilsMbtiles.getMbtile(uri_origen);
const destino = await UtilsMbtiles.getMbtile(uri_destino);
writeAddTiles(origen, destino, z_levels);
}catch(err){
console.log(err);
}
}
writeMbTiles(mbtiles_ori, mbtiles_dest, zoom_levels);