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

master
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) { function writeDir(json) {
json_str = JSON.stringify(json, "", " "); json_str = JSON.stringify(json, "", " ");
dirent = '' + json_str.length; dirent = '' + json_str.length;
while (dirent.length < 6) while (dirent.length < 6)
dirent = dirent + ' '; dirent = dirent + ' ';
return dirent + json_str; return dirent + json_str;
} }
@ -29,23 +27,23 @@ function writeTar(tar, dir) {
var directory = ''; var directory = '';
var json = {}; var json = {};
for (f of files) { for (f of files) {
d = fs.readFileSync(dir+f); d = fs.readFileSync(dir+f);
cs = d; cs = d;
//cs = String.fromCharCode.apply(null, hs.compress(d)) //cs = String.fromCharCode.apply(null, hs.compress(d))
print("Processing", f, cur, d.length, cs.length); print("Processing", f, cur, d.length, cs.length);
//if (d.length == 42) continue; //if (d.length == 42) continue;
data = data + cs; data = data + cs;
var f_rec = {}; var f_rec = {};
f_rec.st = cur; f_rec.st = cur;
var len = d.length; var len = d.length;
f_rec.si = len; f_rec.si = len;
cur = cur + len; cur = cur + len;
json[f] = f_rec; json[f] = f_rec;
json_str = JSON.stringify(json, "", " "); json_str = JSON.stringify(json, "", " ");
if (json_str.length < 16000) if (json_str.length < 16000)
continue; continue;
directory += writeDir(json); directory += writeDir(json);
json = {}; json = {};
} }
directory += writeDir(json); directory += writeDir(json);
directory += '-1 '; directory += '-1 ';
@ -53,12 +51,12 @@ function writeTar(tar, dir) {
size = cur; size = cur;
header = '' + size; header = '' + size;
while (header.length < h_len) { while (header.length < h_len) {
header = header+' '; header = header+' ';
} }
if (!hack) if (!hack)
fs.writeFileSync(tar, header+data+directory); fs.writeFileSync(tar, header+data+directory);
else else
fs.writeFileSync(tar, directory); fs.writeFileSync(tar, directory);
} }
function readTarFile(tar, f) { function readTarFile(tar, f) {
@ -66,9 +64,7 @@ function readTarFile(tar, f) {
json_off = st.read(tar, 0, 16) * 1; json_off = st.read(tar, 0, 16) * 1;
print(json_off); print(json_off);
json = st.read(tar, json_off, -1); json = st.read(tar, json_off, -1);
//print(json);
files = JSON.parse(json); files = JSON.parse(json);
//print(files);
rec = files[f]; rec = files[f];
return st.read(tar, rec.st, rec.si); 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 [ w, s, e, n ] = merc.bbox(x, y, z);
var lon = (e - w) * (x_ / 4096) + w; var lon = (e - w) * (x_ / 4096) + w;
var lat = (n - s) * (1-(y_ / 4096)) + s; var lat = (n - s) * (1-(y_ / 4096)) + s;
//console.log("to ", lon, lat);
return [ lon, lat ]; return [ lon, lat ];
} }
function convGeom(tile, geom) { function convGeom(tile, geom) {
var g = []; var g = [];
for (i = 0; i< geom.length; i++) { for (i = 0; i< geom.length; i++) {
var x = geom[i][0]; var x = geom[i][0];
var y = geom[i][1]; 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);
var pos = tileToLatLon(tile.x, tile.y, tile.z, x, y); g.push(pos);
g.push(pos);
} }
return g; return g;
} }
@ -91,36 +89,36 @@ function toGjson(name, d, tile) {
var cnt = 0; var cnt = 0;
var feat = []; var feat = [];
for (var a of d) { for (var a of d) {
var f = {}; var f = {};
var zoom = 99; var zoom = 99;
var p = {}; var p = {};
f.properties = a.tags; f.properties = a.tags;
f.type = "Feature"; f.type = "Feature";
f.geometry = {}; f.geometry = {};
if (a.type == 1) { if (a.type == 1) {
f.geometry.type = "Point"; f.geometry.type = "Point";
f.geometry.coordinates = convGeom(tile, a.geometry)[0]; f.geometry.coordinates = convGeom(tile, a.geometry)[0];
zoom = zoomPoint(a.tags); zoom = zoomPoint(a.tags);
p = paintPoint(a.tags); p = paintPoint(a.tags);
} else if (a.type == 2) { } else if (a.type == 2) {
f.geometry.type = "LineString"; f.geometry.type = "LineString";
f.geometry.coordinates = convGeom(tile, a.geometry[0]); f.geometry.coordinates = convGeom(tile, a.geometry[0]);
zoom = zoomWay(a.tags); zoom = zoomWay(a.tags);
p = paintWay(a.tags); p = paintWay(a.tags);
} else { } else {
//console.log("Unknown type", a.type); //console.log("Unknown type", a.type);
} }
//zoom -= 4; // Produces way nicer map, at expense of space. //zoom -= 4; // Produces way nicer map, at expense of space.
if (tile.z < zoom) if (tile.z < zoom)
continue; continue;
f.properties = Object.assign({}, f.properties, p); f.properties = Object.assign({}, f.properties, p);
feat.push(f); feat.push(f);
var s = JSON.stringify(feat); var s = JSON.stringify(feat);
if (s.length > 6000) { if (s.length > 6000) {
console.log("tile too big, splitting", cnt); console.log("tile too big, splitting", cnt);
writeFeatures(name+'-'+cnt++, feat); writeFeatures(name+'-'+cnt++, feat);
feat = []; feat = [];
} }
} }
writeFeatures(name+'-'+cnt, feat); writeFeatures(name+'-'+cnt, feat);
return n; return n;
@ -136,11 +134,6 @@ var merc = new sphm({
antimeridian: true 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"); console.log("Splitting data");
var meta = {} var meta = {}
meta.min_zoom = 0; meta.min_zoom = 0;
@ -167,10 +160,7 @@ for (const id in index.tiles) {
const z = tile.z; const z = tile.z;
console.log(num++, ":", tile.x, tile.y, z); console.log(num++, ":", tile.x, tile.y, z);
var d = index.getTile(z, tile.x, tile.y).features; var d = index.getTile(z, tile.x, tile.y).features;
//console.log(d);
var n = `delme/z${z}-${tile.x}-${tile.y}` ; var n = `delme/z${z}-${tile.x}-${tile.y}` ;
//output[n] = d;
//console.log(n);
writeTile(n, d, tile) writeTile(n, d, tile)
} }