tileblaster 0.3.6 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/tileblaster.js +1 -1
- package/config.js.dist +6 -0
- package/lib/tileblaster.js +39 -7
- package/package.json +4 -3
- package/readme.md +1 -1
package/bin/tileblaster.js
CHANGED
|
@@ -4,7 +4,7 @@ var watch = require('node-watch');
|
|
|
4
4
|
var configfile = require("path").resolve.apply(global, (!!argv._[0]) ? [ process.cwd(), argv._[0] ] : [ "../config.js" ]);
|
|
5
5
|
var tb = require("../lib/tileblaster.js")(
|
|
6
6
|
(function(config){
|
|
7
|
-
["socket","tiles","queue","id"].forEach(function(n){
|
|
7
|
+
["socket","tiles","queue","id","port"].forEach(function(n){
|
|
8
8
|
if (!!argv[n]) config[n] = argv[n];
|
|
9
9
|
});
|
|
10
10
|
// watch changes in config file
|
package/config.js.dist
CHANGED
|
@@ -34,6 +34,12 @@ module.exports = {
|
|
|
34
34
|
// * {r} resolution marker
|
|
35
35
|
"url": "https://{s}.tiles.example.com/tiles/{z}/{x}/{y}{r}.{e}",
|
|
36
36
|
|
|
37
|
+
// url points to cloudtiles container (→ https://github.com/OpenCloudTiles/opencloudtiles-specification)
|
|
38
|
+
"cloudtiles": false,
|
|
39
|
+
|
|
40
|
+
// backend uses tms instead of zxy
|
|
41
|
+
"tms": false,
|
|
42
|
+
|
|
37
43
|
// possible extensions
|
|
38
44
|
"ext": ["mvt","json","topojson","png","jpg"],
|
|
39
45
|
|
package/lib/tileblaster.js
CHANGED
|
@@ -19,6 +19,7 @@ var dur = require("dur");
|
|
|
19
19
|
try { var pnck = require("pnck"); } catch (err) { var pnck = null; }
|
|
20
20
|
try { var jpck = require("jpck"); } catch (err) { var jpck = null; }
|
|
21
21
|
try { var zopfli = require("node-zopfli"); } catch (err) { var zopfli = null; }
|
|
22
|
+
try { var cloudtiles = require("cloudtiles"); } catch (err) { var cloudtiles = null; }
|
|
22
23
|
|
|
23
24
|
// load package
|
|
24
25
|
var pckg = require("../package.json");
|
|
@@ -180,6 +181,9 @@ tileblaster.prototype.reconfigure = function(config){
|
|
|
180
181
|
// compression
|
|
181
182
|
map.compress = map.compress.filter(function(c){ return (self.comp.indexOf(c) >= 0) });
|
|
182
183
|
|
|
184
|
+
// is cloudtile
|
|
185
|
+
map.cloudtiles = (map.cloudtiles === true);
|
|
186
|
+
|
|
183
187
|
return map;
|
|
184
188
|
|
|
185
189
|
})(self.config.maps[id],id), maps;
|
|
@@ -266,6 +270,12 @@ tileblaster.prototype.listen = function(){
|
|
|
266
270
|
// wait for server to be ready
|
|
267
271
|
if (!self.srvr) return (self.listentome = true), this;
|
|
268
272
|
|
|
273
|
+
// omit socket if port specified
|
|
274
|
+
if (self.config.port) return self.srvr.listen(self.config.port, function(err){
|
|
275
|
+
if (err) debug("<listen> unable to listen on port %d", self.config.port), process.exit(1);
|
|
276
|
+
debug("<listen> listening on port %d", self.config.port);
|
|
277
|
+
}), self;
|
|
278
|
+
|
|
269
279
|
// listen on socket
|
|
270
280
|
(function(fn){
|
|
271
281
|
(function(next){
|
|
@@ -409,7 +419,13 @@ tileblaster.prototype.tile = function(mapid, z, x, y, r, e, fn){
|
|
|
409
419
|
// construct upstream tile url
|
|
410
420
|
var tileurl = self._tileurl(mapid, z, x, y, r, e);
|
|
411
421
|
|
|
412
|
-
|
|
422
|
+
(function(next){
|
|
423
|
+
|
|
424
|
+
// cloudtile branch
|
|
425
|
+
if (self.maps[mapid].cloudtiles) return self.cloudtile(tileurl, mapid, z, x, y, next);
|
|
426
|
+
self.fetchtile(tileurl, mapid, next);
|
|
427
|
+
|
|
428
|
+
})(function(err, tilestream, meta){
|
|
413
429
|
|
|
414
430
|
if (err) {
|
|
415
431
|
if (stream !== null) {
|
|
@@ -428,14 +444,14 @@ tileblaster.prototype.tile = function(mapid, z, x, y, r, e, fn){
|
|
|
428
444
|
|
|
429
445
|
var streams = [];
|
|
430
446
|
|
|
431
|
-
streams.push(function(
|
|
447
|
+
streams.push(function(tilestream){
|
|
432
448
|
// call back with stream
|
|
433
|
-
fn(null,
|
|
449
|
+
fn(null, tilestream, {
|
|
434
450
|
'content-type': (self.mime[e])
|
|
435
451
|
});
|
|
436
452
|
});
|
|
437
453
|
|
|
438
|
-
if (!!self.config.maps[mapid].cache) streams.push(function(
|
|
454
|
+
if (!!self.config.maps[mapid].cache) streams.push(function(tilestream){
|
|
439
455
|
|
|
440
456
|
// don't overwrite if tile exists
|
|
441
457
|
fs.access(tilepath, fs.constants.F_OK, function(err){
|
|
@@ -444,7 +460,7 @@ tileblaster.prototype.tile = function(mapid, z, x, y, r, e, fn){
|
|
|
444
460
|
mkdirp(path.dirname(tilepath)).then(function(err){
|
|
445
461
|
|
|
446
462
|
// save to tmp file, rename when done
|
|
447
|
-
|
|
463
|
+
tilestream.pipe(fs.createWriteStream(tilepath+".tmp").on('finish', function(){
|
|
448
464
|
fs.rename(tilepath+".tmp", tilepath, function(){
|
|
449
465
|
|
|
450
466
|
// compress
|
|
@@ -463,7 +479,7 @@ tileblaster.prototype.tile = function(mapid, z, x, y, r, e, fn){
|
|
|
463
479
|
});
|
|
464
480
|
|
|
465
481
|
// stream mux
|
|
466
|
-
|
|
482
|
+
tilestream.pipe(self.optimize(mapid, e)).pipe(self._mux.apply(self, streams));
|
|
467
483
|
|
|
468
484
|
});
|
|
469
485
|
|
|
@@ -517,6 +533,18 @@ tileblaster.prototype.fetchtile = function(tileurl, mapid, fn){
|
|
|
517
533
|
|
|
518
534
|
};
|
|
519
535
|
|
|
536
|
+
// get cloudtile
|
|
537
|
+
tileblaster.prototype.cloudtile = function(tileurl, mapid, z, x, y, fn) {
|
|
538
|
+
const self = this;
|
|
539
|
+
if (!cloudtiles) return fn(new Error("Missing dependency: cloudtiles"));
|
|
540
|
+
if (!self.maps[mapid].c) self.maps[mapid].c = cloudtiles(tileurl, { tms: !!self.maps[mapid].tms });
|
|
541
|
+
self.maps[mapid].c.getTile(z,x,y, function(err, buffer){
|
|
542
|
+
if (err) return fn(err);
|
|
543
|
+
return fn(null, stream.Readable.from(buffer));
|
|
544
|
+
});
|
|
545
|
+
return self;
|
|
546
|
+
};
|
|
547
|
+
|
|
520
548
|
// optimization
|
|
521
549
|
tileblaster.prototype.optimize = function(mapid, ext){
|
|
522
550
|
var self = this;
|
|
@@ -527,7 +555,7 @@ tileblaster.prototype.optimize = function(mapid, ext){
|
|
|
527
555
|
case "png":
|
|
528
556
|
if (!pnck) break;
|
|
529
557
|
debug("<optimize> [%s] png", mapid);
|
|
530
|
-
|
|
558
|
+
return strm.pipe(pnck(['-o7','-zc8','-zm8','-f5','-quiet','-fix']));
|
|
531
559
|
break;
|
|
532
560
|
case "jpg":
|
|
533
561
|
case "jpeg":
|
|
@@ -679,6 +707,10 @@ tileblaster.prototype._checktile = function(mapid, z, x, y, r, ext, fn){
|
|
|
679
707
|
// transform parameters to url
|
|
680
708
|
tileblaster.prototype._tileurl = function(mapid, z, x, y, r, e){
|
|
681
709
|
var self = this;
|
|
710
|
+
|
|
711
|
+
// when backend uses tms
|
|
712
|
+
if (!!self.maps[mapid].tms) y = Math.pow(2,z)-y-1;
|
|
713
|
+
|
|
682
714
|
return self.maps[mapid].url
|
|
683
715
|
.replace("{s}", (self.maps[mapid].sub !== false) ? self.maps[mapid].sub[Math.floor(Math.random()*self.maps[mapid].sub.length)] : "")
|
|
684
716
|
.replace("{x}", x.toFixed(0))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tileblaster",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "pretty fast optimizing & compressing tile caching proxy",
|
|
5
5
|
"main": "lib/tileblaster.js",
|
|
6
6
|
"bin": {
|
|
@@ -19,15 +19,16 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"debug": "^4.3.4",
|
|
21
21
|
"dur": "^0.0.3",
|
|
22
|
-
"glob": "^8.0
|
|
22
|
+
"glob": "^8.1.0",
|
|
23
23
|
"minimist": "^1.2.7",
|
|
24
|
-
"mkdirp": "^
|
|
24
|
+
"mkdirp": "^2.0.0",
|
|
25
25
|
"node-watch": "^0.7.3",
|
|
26
26
|
"nsa": "^0.2",
|
|
27
27
|
"quu": "^0.4.3",
|
|
28
28
|
"request": "^2.88"
|
|
29
29
|
},
|
|
30
30
|
"optionalDependencies": {
|
|
31
|
+
"cloudtiles": "^0.0.6",
|
|
31
32
|
"jpck": "^1.0.2",
|
|
32
33
|
"node-zopfli": "^2.1.4",
|
|
33
34
|
"pnck": "^1.0.1"
|
package/readme.md
CHANGED
|
@@ -6,7 +6,7 @@ tileblaster is a map tile caching (and optimizing) proxy, designed to run with n
|
|
|
6
6
|
|
|
7
7
|
`npm i tileblaster -g`
|
|
8
8
|
|
|
9
|
-
use `--no-optional` if you don't want tile optimization.
|
|
9
|
+
use `--no-optional` if you don't want tile optimization or [opencloudtiles](https://github.com/OpenCloudTiles/opencloudtiles-specification) support.
|
|
10
10
|
|
|
11
11
|
## run
|
|
12
12
|
|