Skip to content

Commit

Permalink
Fix tabs-vs-spaces warning, remove extra debugging.
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelmachek committed Aug 18, 2023
1 parent 3158d94 commit 1c96a66
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 69 deletions.
46 changes: 21 additions & 25 deletions apps/spacew/prep/minitar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ if (pc) {

}

print("hello world");

function writeDir(json) {
json_str = JSON.stringify(json, "", " ");
dirent = '' + json_str.length;
while (dirent.length < 6)
dirent = dirent + ' ';
dirent = dirent + ' ';
return dirent + json_str;
}

Expand All @@ -29,46 +27,44 @@ function writeTar(tar, dir) {
var directory = '';
var json = {};
for (f of files) {
d = fs.readFileSync(dir+f);
cs = d;
//cs = String.fromCharCode.apply(null, hs.compress(d))
print("Processing", f, cur, d.length, cs.length);
//if (d.length == 42) continue;
data = data + cs;
var f_rec = {};
f_rec.st = cur;
var len = d.length;
f_rec.si = len;
cur = cur + len;
json[f] = f_rec;
json_str = JSON.stringify(json, "", " ");
if (json_str.length < 16000)
continue;
directory += writeDir(json);
json = {};
d = fs.readFileSync(dir+f);
cs = d;
//cs = String.fromCharCode.apply(null, hs.compress(d))
print("Processing", f, cur, d.length, cs.length);
//if (d.length == 42) continue;
data = data + cs;
var f_rec = {};
f_rec.st = cur;
var len = d.length;
f_rec.si = len;
cur = cur + len;
json[f] = f_rec;
json_str = JSON.stringify(json, "", " ");
if (json_str.length < 16000)
continue;
directory += writeDir(json);
json = {};
}
directory += writeDir(json);
directory += '-1 ';

size = cur;
header = '' + size;
while (header.length < h_len) {
header = header+' ';
header = header+' ';
}
if (!hack)
fs.writeFileSync(tar, header+data+directory);
fs.writeFileSync(tar, header+data+directory);
else
fs.writeFileSync(tar, directory);
fs.writeFileSync(tar, directory);
}

function readTarFile(tar, f) {
const st = require('Storage');
json_off = st.read(tar, 0, 16) * 1;
print(json_off);
json = st.read(tar, json_off, -1);
//print(json);
files = JSON.parse(json);
//print(files);
rec = files[f];
return st.read(tar, rec.st, rec.si);
}
Expand Down
78 changes: 34 additions & 44 deletions apps/spacew/prep/split.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ function tileToLatLon(x, y, z, x_, y_) {
var [ w, s, e, n ] = merc.bbox(x, y, z);
var lon = (e - w) * (x_ / 4096) + w;
var lat = (n - s) * (1-(y_ / 4096)) + s;
//console.log("to ", lon, lat);
return [ lon, lat ];
}

function convGeom(tile, geom) {
var g = [];
for (i = 0; i< geom.length; i++) {
var x = geom[i][0];
var y = geom[i][1];
//console.log("Geometry: ", geom, geom.length, "X,y", x, y);
var pos = tileToLatLon(tile.x, tile.y, tile.z, x, y);
g.push(pos);
var x = geom[i][0];
var y = geom[i][1];
var pos = tileToLatLon(tile.x, tile.y, tile.z, x, y);
g.push(pos);
}
return g;
}
Expand Down Expand Up @@ -91,36 +89,36 @@ function toGjson(name, d, tile) {
var cnt = 0;
var feat = [];
for (var a of d) {
var f = {};
var zoom = 99;
var p = {};
f.properties = a.tags;
f.type = "Feature";
f.geometry = {};
if (a.type == 1) {
f.geometry.type = "Point";
f.geometry.coordinates = convGeom(tile, a.geometry)[0];
zoom = zoomPoint(a.tags);
p = paintPoint(a.tags);
} else if (a.type == 2) {
f.geometry.type = "LineString";
f.geometry.coordinates = convGeom(tile, a.geometry[0]);
zoom = zoomWay(a.tags);
p = paintWay(a.tags);
} else {
//console.log("Unknown type", a.type);
}
//zoom -= 4; // Produces way nicer map, at expense of space.
if (tile.z < zoom)
continue;
f.properties = Object.assign({}, f.properties, p);
feat.push(f);
var s = JSON.stringify(feat);
if (s.length > 6000) {
console.log("tile too big, splitting", cnt);
writeFeatures(name+'-'+cnt++, feat);
feat = [];
}
var f = {};
var zoom = 99;
var p = {};
f.properties = a.tags;
f.type = "Feature";
f.geometry = {};
if (a.type == 1) {
f.geometry.type = "Point";
f.geometry.coordinates = convGeom(tile, a.geometry)[0];
zoom = zoomPoint(a.tags);
p = paintPoint(a.tags);
} else if (a.type == 2) {
f.geometry.type = "LineString";
f.geometry.coordinates = convGeom(tile, a.geometry[0]);
zoom = zoomWay(a.tags);
p = paintWay(a.tags);
} else {
//console.log("Unknown type", a.type);
}
//zoom -= 4; // Produces way nicer map, at expense of space.
if (tile.z < zoom)
continue;
f.properties = Object.assign({}, f.properties, p);
feat.push(f);
var s = JSON.stringify(feat);
if (s.length > 6000) {
console.log("tile too big, splitting", cnt);
writeFeatures(name+'-'+cnt++, feat);
feat = [];
}
}
writeFeatures(name+'-'+cnt, feat);
return n;
Expand All @@ -136,11 +134,6 @@ var merc = new sphm({
antimeridian: true
});

//console.log(merc.ll([124, 123], 15));
//console.log(merc.px([17734, 11102], 15));
//console.log(merc.bbox(17734, 11102, 15));
//return;

console.log("Splitting data");
var meta = {}
meta.min_zoom = 0;
Expand All @@ -167,10 +160,7 @@ for (const id in index.tiles) {
const z = tile.z;
console.log(num++, ":", tile.x, tile.y, z);
var d = index.getTile(z, tile.x, tile.y).features;
//console.log(d);
var n = `delme/z${z}-${tile.x}-${tile.y}` ;
//output[n] = d;
//console.log(n);
writeTile(n, d, tile)
}

Expand Down

0 comments on commit 1c96a66

Please sign in to comment.