Fix tabs-vs-spaces warning, remove extra debugging.

pull/2981/head
Pavel Machek 2023-08-18 22:49:30 +02:00
parent 3158d945aa
commit 1c96a66db9
2 changed files with 55 additions and 69 deletions

View File

@ -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;
}
@ -29,23 +27,23 @@ 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 ';
@ -53,12 +51,12 @@ function writeTar(tar, dir) {
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) {
@ -66,9 +64,7 @@ function readTarFile(tar, f) {
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);
}

View File

@ -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;
}
@ -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;
@ -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;
@ -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)
}