Compare commits

..

3 Commits

Author SHA1 Message Date
Petr Sloup
5a20bf4fac Update version to 0.8.2 2016-07-26 18:57:39 +07:00
Petr Sloup
a0fbf7fb79 Fix font compositing (close #32) 2016-07-26 18:56:32 +07:00
Petr Sloup
ed0af943da New design (close #31) 2016-07-26 17:27:08 +07:00
18 changed files with 227 additions and 132 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "tileserver-gl",
"version": "0.8.1",
"version": "0.8.2",
"description": "Map tile server for JSON GL styles - serverside generated raster tiles",
"main": "src/main.js",
"bin": "src/main.js",
@@ -24,6 +24,7 @@
"color": "0.11.3",
"cors": "2.7.1",
"express": "4.14.0",
"glyph-pbf-composite": "0.0.2",
"handlebars": "4.0.5",
"mapbox-gl-native": "3.2.1",
"mbtiles": "0.9.0",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 171 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 530 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,12 +1,9 @@
'use strict';
var async = require('async'),
path = require('path'),
fs = require('fs');
var clone = require('clone'),
express = require('express');
var utils = require('./utils');
module.exports = function(options, allowedFonts) {
var app = express().disable('x-powered-by');
@@ -15,41 +12,14 @@ module.exports = function(options, allowedFonts) {
var fontPath = options.paths.fonts;
var getFontPbf = function(name, range, callback) {
// if some of the files failed to load (does not exist or not allowed),
// return empty buffer so the other fonts can still work
if (allowedFonts[name]) {
var filename = path.join(fontPath, name, range + '.pbf');
return fs.readFile(filename, function(err, data) {
if (err) {
console.log('Font load error:', filename);
return callback(null, new Buffer([]));
} else {
return callback(null, data);
}
});
} else {
return callback(null, new Buffer([]));
}
};
app.get('/:fontstack/:range([\\d]+-[\\d]+).pbf',
function(req, res, next) {
var fontstack = decodeURI(req.params.fontstack);
var range = req.params.range;
var fonts = fontstack.split(',');
var queue = [];
fonts.forEach(function(font) {
queue.push(function(callback) {
getFontPbf(font, range, callback);
});
});
return async.parallel(queue, function(err, results) {
var concated = Buffer.concat(results);
if (err || concated.length == 0) {
return utils.getFontsPbf(allowedFonts, fontPath, fontstack, range,
function(err, concated) {
if (err || concated.length === 0) {
return res.status(400).send('');
} else {
res.header('Content-type', 'application/x-protobuf');

View File

@@ -56,12 +56,20 @@ module.exports = function(options, repo, params, id) {
request: function(req, callback) {
var protocol = req.url.split(':')[0];
//console.log('Handling request:', req);
if (protocol == 'sprites' || protocol == 'fonts') {
if (protocol == 'sprites') {
var dir = options.paths[protocol];
var file = unescape(req.url).substring(protocol.length + 3);
fs.readFile(path.join(dir, file), function(err, data) {
callback(err, { data: data });
});
} else if (protocol == 'fonts') {
var parts = req.url.split('/');
var fontstack = unescape(parts[2]);
var range = parts[3].split('.')[0];
utils.getFontsPbf(null, options.paths[protocol], fontstack, range,
function(err, concated) {
callback(err, {data: concated});
});
} else if (protocol == 'mbtiles') {
var parts = req.url.split('/');
var source = map.sources[parts[2]];

View File

@@ -1,5 +1,11 @@
'use strict';
var async = require('async'),
path = require('path'),
fs = require('fs');
var glyphCompose = require('glyph-pbf-composite');
module.exports.getTileUrls = function(req, domains, path, format) {
if (domains) {
@@ -37,3 +43,36 @@ module.exports.fixTileJSONCenter = function(tileJSON) {
];
}
};
module.exports.getFontsPbf = function(allowedFonts, fontPath, names, range, callback) {
var getFontPbf = function(name, range, callback) {
if (!allowedFonts || allowedFonts[name]) {
var filename = path.join(fontPath, name, range + '.pbf');
return fs.readFile(filename, function(err, data) {
if (err) {
return callback(new Error('Font load error: ' + name));
} else {
return callback(null, data);
}
});
} else {
return callback(new Error('Font not allowed: ' + name));
}
};
var fonts = names.split(',');
var queue = [];
fonts.forEach(function(font) {
queue.push(function(callback) {
getFontPbf(font, range, callback);
});
});
return async.parallel(queue, function(err, results) {
if (err) {
callback(err, new Buffer([]));
} else {
callback(err, glyphCompose.combine(results));
}
});
};

View File

@@ -42,7 +42,7 @@ describe('Fonts', function() {
testIs('/fonts/Open Sans Regular/65280-65533.pbf', /application\/x-protobuf/);
testIs('/fonts/Open Sans Bold,Open Sans Regular/0-255.pbf',
/application\/x-protobuf/);
testIs('/fonts/Nonsense,Open Sans Bold/0-255.pbf', /application\/x-protobuf/);
testIs('/fonts/Nonsense,Open Sans Bold/0-255.pbf', /./, 400);
testIs('/fonts/Nonsense/0-255.pbf', /./, 400);
testIs('/fonts/Nonsense1,Nonsense2/0-255.pbf', /./, 400);