Fix sprite and glyph loading from remote URLs
This commit is contained in:
parent
442baee1ce
commit
bbc14abb4a
2 changed files with 33 additions and 8 deletions
|
@ -144,9 +144,19 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
styleJSON = clone(require(path.join(options.paths.styles, styleFile)));
|
var styleJSONPath = path.join(options.paths.styles, styleFile);
|
||||||
styleJSON.sprite = 'sprites://' + path.basename(styleFile, '.json');
|
styleJSON = clone(require(styleJSONPath));
|
||||||
styleJSON.glyphs = 'fonts://{fontstack}/{range}.pbf';
|
|
||||||
|
var httpTester = /^(http(s)?:)?\/\//;
|
||||||
|
if (!httpTester.test(styleJSON.sprite)) {
|
||||||
|
styleJSON.sprite = 'sprites://' +
|
||||||
|
styleJSON.sprite
|
||||||
|
.replace('{style}', path.basename(styleFile, '.json'))
|
||||||
|
.replace('{styleJsonFolder}', path.relative(options.paths.sprites, path.dirname(styleJSONPath)));
|
||||||
|
}
|
||||||
|
if (!httpTester.test(styleJSON.glyphs)) {
|
||||||
|
styleJSON.glyphs = 'fonts://' + styleJSON.glyphs;
|
||||||
|
}
|
||||||
|
|
||||||
var tileJSON = {
|
var tileJSON = {
|
||||||
'tilejson': '2.0.0',
|
'tilejson': '2.0.0',
|
||||||
|
|
|
@ -43,11 +43,20 @@ module.exports = function(options, repo, params, id, reportTiles, reportFont) {
|
||||||
};
|
};
|
||||||
styleJSON.layers.forEach(findFontReferences);
|
styleJSON.layers.forEach(findFontReferences);
|
||||||
|
|
||||||
var spritePath = path.join(options.paths.sprites,
|
var spritePath;
|
||||||
path.basename(styleFile, '.json'));
|
|
||||||
|
|
||||||
|
var httpTester = /^(http(s)?:)?\/\//;
|
||||||
|
if (!httpTester.test(styleJSON.sprite)) {
|
||||||
|
spritePath = path.join(options.paths.sprites,
|
||||||
|
styleJSON.sprite
|
||||||
|
.replace('{style}', path.basename(styleFile, '.json'))
|
||||||
|
.replace('{styleJsonFolder}', path.relative(options.paths.sprites, path.dirname(styleFile)))
|
||||||
|
);
|
||||||
styleJSON.sprite = 'local://styles/' + id + '/sprite';
|
styleJSON.sprite = 'local://styles/' + id + '/sprite';
|
||||||
|
}
|
||||||
|
if (!httpTester.test(styleJSON.glyphs)) {
|
||||||
styleJSON.glyphs = 'local://fonts/{fontstack}/{range}.pbf';
|
styleJSON.glyphs = 'local://fonts/{fontstack}/{range}.pbf';
|
||||||
|
}
|
||||||
|
|
||||||
repo[id] = styleJSON;
|
repo[id] = styleJSON;
|
||||||
|
|
||||||
|
@ -57,7 +66,10 @@ module.exports = function(options, repo, params, id, reportTiles, reportFont) {
|
||||||
if (!opt_nokey && req.query.key) {
|
if (!opt_nokey && req.query.key) {
|
||||||
queryParams.unshift('key=' + req.query.key);
|
queryParams.unshift('key=' + req.query.key);
|
||||||
}
|
}
|
||||||
var query = '?' + queryParams.join('&');
|
var query = '';
|
||||||
|
if (!opt_nokey) {
|
||||||
|
query = '?' + queryParams.join('&');
|
||||||
|
}
|
||||||
return url.replace(
|
return url.replace(
|
||||||
'local://', req.protocol + '://' + req.headers.host + '/') + query;
|
'local://', req.protocol + '://' + req.headers.host + '/') + query;
|
||||||
};
|
};
|
||||||
|
@ -75,6 +87,9 @@ module.exports = function(options, repo, params, id, reportTiles, reportFont) {
|
||||||
|
|
||||||
app.get('/' + id + '/sprite:scale(@[23]x)?\.:format([\\w]+)',
|
app.get('/' + id + '/sprite:scale(@[23]x)?\.:format([\\w]+)',
|
||||||
function(req, res, next) {
|
function(req, res, next) {
|
||||||
|
if (!spritePath) {
|
||||||
|
return res.status(404).send('File not found');
|
||||||
|
}
|
||||||
var scale = req.params.scale,
|
var scale = req.params.scale,
|
||||||
format = req.params.format;
|
format = req.params.format;
|
||||||
var filename = spritePath + (scale || '') + '.' + format;
|
var filename = spritePath + (scale || '') + '.' + format;
|
||||||
|
|
Loading…
Reference in a new issue