Skip to content

Commit 8b75cca

Browse files
committed
Add skipEncoding callback option
If skipEncoding is set return raw image buffer instead of encoded png.
1 parent abcc364 commit 8b75cca

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

dist/render.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ var getRemoteAsset = function getRemoteAsset(url, callback) {
377377
* @param {number} width - width of output map (default: 1024)
378378
* @param {number} height - height of output map (default: 1024)
379379
* @param {Object} - configuration object containing style, zoom, center: [lng, lat],
380-
* width, height, bounds: [west, south, east, north], ratio, padding
380+
* width, height, bounds: [west, south, east, north], ratio, padding, skipEncoding
381381
* @param {String} tilePath - path to directory containing local mbtiles files that are
382382
* referenced from the style.json as "mbtiles://<tileset>"
383383
*/
@@ -399,7 +399,9 @@ var render = function render(style) {
399399
_options$ratio = options.ratio,
400400
ratio = _options$ratio === void 0 ? 1 : _options$ratio,
401401
_options$padding = options.padding,
402-
padding = _options$padding === void 0 ? 0 : _options$padding;
402+
padding = _options$padding === void 0 ? 0 : _options$padding,
403+
_options$skipEncoding = options.skipEncoding,
404+
skipEncoding = _options$skipEncoding === void 0 ? false : _options$skipEncoding;
403405
var _options$center = options.center,
404406
center = _options$center === void 0 ? null : _options$center,
405407
_options$zoom = options.zoom,
@@ -621,6 +623,10 @@ var render = function render(style) {
621623
buffer[i + 1] = buffer[i + 1] / norm;
622624
buffer[i + 2] = buffer[i + 2] / norm;
623625
}
626+
}
627+
628+
if (skipEncoding) {
629+
return resolve(buffer);
624630
} // Convert raw image buffer to PNG
625631

626632

src/render.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ const getRemoteAsset = (url, callback) => {
320320
* @param {number} width - width of output map (default: 1024)
321321
* @param {number} height - height of output map (default: 1024)
322322
* @param {Object} - configuration object containing style, zoom, center: [lng, lat],
323-
* width, height, bounds: [west, south, east, north], ratio, padding
323+
* width, height, bounds: [west, south, east, north], ratio, padding, skipEncoding
324324
* @param {String} tilePath - path to directory containing local mbtiles files that are
325325
* referenced from the style.json as "mbtiles://<tileset>"
326326
*/
@@ -333,6 +333,7 @@ export const render = (style, width = 1024, height = 1024, options) =>
333333
token = null,
334334
ratio = 1,
335335
padding = 0,
336+
skipEncoding = false,
336337
} = options
337338
let { center = null, zoom = null, tilePath = null } = options
338339

@@ -589,6 +590,10 @@ export const render = (style, width = 1024, height = 1024, options) =>
589590
}
590591
}
591592

593+
if (skipEncoding) {
594+
return resolve(buffer)
595+
}
596+
592597
// Convert raw image buffer to PNG
593598
try {
594599
return sharp(buffer, {

0 commit comments

Comments
 (0)