Correctly serve sprites
This commit is contained in:
parent
d4fa224d04
commit
b98b7244f6
1 changed files with 24 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
var path = require('path');
|
||||
var path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
var clone = require('clone'),
|
||||
express = require('express');
|
||||
|
@ -23,8 +24,11 @@ module.exports = function(repo, options, id, reportVector) {
|
|||
source.url = 'local://vector/' + identifier + '.json';
|
||||
}
|
||||
});
|
||||
styleJSON.sprite = 'local://styles/{style_id}/sprite';
|
||||
styleJSON.glyphs = 'local://fonts/{fonstack}/{range}.pbf';
|
||||
|
||||
var spritePath = path.join(rootPath, styleJSON.sprite);
|
||||
|
||||
styleJSON.sprite = 'local://styles/' + id + '/sprite';
|
||||
styleJSON.glyphs = 'local://fonts/{fontstack}/{range}.pbf';
|
||||
|
||||
repo[id] = styleJSON;
|
||||
|
||||
|
@ -44,5 +48,22 @@ module.exports = function(repo, options, id, reportVector) {
|
|||
return res.send(styleJSON_);
|
||||
});
|
||||
|
||||
app.get('/styles/' + id + '/sprite:scale(@[23]x)?\.:format([\\w]+)',
|
||||
function(req, res, next) {
|
||||
var scale = req.params.scale,
|
||||
format = req.params.format;
|
||||
var filename = spritePath + (scale || '') + '.' + format;
|
||||
return fs.readFile(filename, function(err, data) {
|
||||
if (err) {
|
||||
console.log('Sprite load error:', filename);
|
||||
return res.status(404).send('File not found');
|
||||
} else {
|
||||
if (format == 'json') res.header('Content-type', 'application/json');
|
||||
if (format == 'png') res.header('Content-type', 'image/png');
|
||||
return res.send(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return app;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue