Be more flexible validating buffer-size customization
This commit is contained in:
parent
55a351d751
commit
2c9d30e042
@ -1,35 +1,22 @@
|
||||
var _ = require('underscore');
|
||||
|
||||
function MapConfigNamedMapAdapter() {
|
||||
}
|
||||
|
||||
module.exports = MapConfigNamedMapAdapter;
|
||||
|
||||
var formats = ['png', 'png32', 'mvt', 'grid.json', 'geojson'];
|
||||
|
||||
MapConfigNamedMapAdapter.prototype.getMapConfig = function (user, requestMapConfig, params, context, callback) {
|
||||
if (context.templateParams &&
|
||||
context.templateParams.buffersize &&
|
||||
isValidBufferSize(context.templateParams.buffersize)) {
|
||||
requestMapConfig.buffersize = context.templateParams.buffersize;
|
||||
if (!context.templateParams || !context.templateParams.buffersize) {
|
||||
return callback(null, requestMapConfig);
|
||||
}
|
||||
|
||||
formats.forEach(function (format) {
|
||||
if (Number.isFinite(context.templateParams.buffersize[format])) {
|
||||
requestMapConfig.buffersize[format] = context.templateParams.buffersize[format];
|
||||
}
|
||||
});
|
||||
|
||||
process.nextTick(function () {
|
||||
callback(null, requestMapConfig);
|
||||
});
|
||||
};
|
||||
|
||||
function isValidBufferSize (bufferSize) {
|
||||
var formats = ['png', 'png32', 'mvt', 'grid.json', 'geojson'];
|
||||
|
||||
if (!_.isObject(bufferSize) || (_.isArray(bufferSize) || _.isFunction(bufferSize))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var index = 0; index < formats.length; index++) {
|
||||
var bufferSizeByFormat = bufferSize[formats[index]];
|
||||
if (bufferSizeByFormat && !Number.isFinite(bufferSizeByFormat)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user