Configurable scale factors (close #121)
Also changes default maximum from `4x` to `3x`
This commit is contained in:
parent
7b952ee5c0
commit
f8949c1aa9
3 changed files with 32 additions and 9 deletions
|
@ -25,6 +25,7 @@ Example::
|
||||||
"pngQuantization": false,
|
"pngQuantization": false,
|
||||||
"png": 90
|
"png": 90
|
||||||
},
|
},
|
||||||
|
"maxScaleFactor": 3,
|
||||||
"maxSize": 2048,
|
"maxSize": 2048,
|
||||||
"pbfAlias": "pbf",
|
"pbfAlias": "pbf",
|
||||||
"serveAllFonts": false,
|
"serveAllFonts": false,
|
||||||
|
@ -76,10 +77,19 @@ Quality of the compression of individual image formats. [0-100]
|
||||||
|
|
||||||
The value for ``png`` is only used when ``pngQuantization`` is ``true``.
|
The value for ``png`` is only used when ``pngQuantization`` is ``true``.
|
||||||
|
|
||||||
|
``maxScaleFactor``
|
||||||
|
-----------
|
||||||
|
|
||||||
|
Maximum scale factor to allow in raster tile and static maps requests (e.g. ``@3x`` suffix).
|
||||||
|
Also see ``maxSize`` below.
|
||||||
|
Default value is ``3``, maximum ``9``.
|
||||||
|
|
||||||
``maxSize``
|
``maxSize``
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
Maximum image side length to be allowed to be rendered (including scale factor). Default is ``2048``.
|
Maximum image side length to be allowed to be rendered (including scale factor).
|
||||||
|
Be careful when changing this value since there are hardware limits that need to be considered.
|
||||||
|
Default is ``2048``.
|
||||||
|
|
||||||
``styles``
|
``styles``
|
||||||
==========
|
==========
|
||||||
|
|
|
@ -24,7 +24,6 @@ var Canvas = require('canvas'),
|
||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
|
|
||||||
var FLOAT_PATTERN = '[+-]?(?:\\d+|\\d+\.?\\d+)';
|
var FLOAT_PATTERN = '[+-]?(?:\\d+|\\d+\.?\\d+)';
|
||||||
var SCALE_PATTERN = '@[234]x';
|
|
||||||
|
|
||||||
var getScale = function(scale) {
|
var getScale = function(scale) {
|
||||||
return (scale || '@1x').slice(1, 2) | 0;
|
return (scale || '@1x').slice(1, 2) | 0;
|
||||||
|
@ -39,6 +38,13 @@ mbgl.on('message', function(e) {
|
||||||
module.exports = function(options, repo, params, id, dataResolver) {
|
module.exports = function(options, repo, params, id, dataResolver) {
|
||||||
var app = express().disable('x-powered-by');
|
var app = express().disable('x-powered-by');
|
||||||
|
|
||||||
|
var maxScaleFactor = Math.min(Math.floor(options.maxScaleFactor || 3), 9);
|
||||||
|
var scalePattern = '';
|
||||||
|
for (var i = 2; i <= maxScaleFactor; i++) {
|
||||||
|
scalePattern += i.toFixed();
|
||||||
|
}
|
||||||
|
scalePattern = '@[' + scalePattern + ']x';
|
||||||
|
|
||||||
var lastModified = new Date().toUTCString();
|
var lastModified = new Date().toUTCString();
|
||||||
|
|
||||||
var rootPath = options.paths.root;
|
var rootPath = options.paths.root;
|
||||||
|
@ -267,16 +273,24 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||||
|
|
||||||
async.parallel(queue, function(err, results) {
|
async.parallel(queue, function(err, results) {
|
||||||
// TODO: make pool sizes configurable
|
// TODO: make pool sizes configurable
|
||||||
map.renderers[1] = createPool(1, 4, 16);
|
for (var s = 1; s <= maxScaleFactor; s++) {
|
||||||
map.renderers[2] = createPool(2, 2, 8);
|
var minPoolSize = 2;
|
||||||
map.renderers[3] = createPool(3, 2, 4);
|
|
||||||
map.renderers[4] = createPool(4, 2, 4);
|
// standard and @2x tiles are much more usual -> create larger pools
|
||||||
|
if (s <= 2) {
|
||||||
|
minPoolSize *= 2;
|
||||||
|
if (s <= 1) {
|
||||||
|
minPoolSize *= 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
map.renderers[s] = createPool(s, minPoolSize, 2 * minPoolSize);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
repo[id] = tileJSON;
|
repo[id] = tileJSON;
|
||||||
|
|
||||||
var tilePattern = '/rendered/:z(\\d+)/:x(\\d+)/:y(\\d+)' +
|
var tilePattern = '/rendered/:z(\\d+)/:x(\\d+)/:y(\\d+)' +
|
||||||
':scale(' + SCALE_PATTERN + ')?\.:format([\\w]+)';
|
':scale(' + scalePattern + ')?\.:format([\\w]+)';
|
||||||
|
|
||||||
var respondImage = function(z, lon, lat, bearing, pitch,
|
var respondImage = function(z, lon, lat, bearing, pitch,
|
||||||
width, height, scale, format, res, next,
|
width, height, scale, format, res, next,
|
||||||
|
@ -477,7 +491,7 @@ module.exports = function(options, repo, params, id, dataResolver) {
|
||||||
if (options.serveStaticMaps !== false) {
|
if (options.serveStaticMaps !== false) {
|
||||||
var staticPattern =
|
var staticPattern =
|
||||||
'/static/:raw(raw)?/%s/:width(\\d+)x:height(\\d+)' +
|
'/static/:raw(raw)?/%s/:width(\\d+)x:height(\\d+)' +
|
||||||
':scale(' + SCALE_PATTERN + ')?\.:format([\\w]+)';
|
':scale(' + scalePattern + ')?\.:format([\\w]+)';
|
||||||
|
|
||||||
var centerPattern =
|
var centerPattern =
|
||||||
util.format(':x(%s),:y(%s),:z(%s)(@:bearing(%s)(,:pitch(%s))?)?',
|
util.format(':x(%s),:y(%s),:z(%s)(@:bearing(%s)(,:pitch(%s))?)?',
|
||||||
|
|
|
@ -26,7 +26,6 @@ describe('Raster tiles', function() {
|
||||||
testTile(prefix, 0, 0, 0, 'png', 200, 2);
|
testTile(prefix, 0, 0, 0, 'png', 200, 2);
|
||||||
testTile(prefix, 0, 0, 0, 'png', 200, 3);
|
testTile(prefix, 0, 0, 0, 'png', 200, 3);
|
||||||
testTile(prefix, 2, 1, 1, 'png', 200, 3);
|
testTile(prefix, 2, 1, 1, 'png', 200, 3);
|
||||||
testTile(prefix, 0, 0, 0, 'png', 200, 4);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue