Add support for watermarks (close #130)

This commit is contained in:
Petr Sloup 2017-03-15 17:06:26 +01:00
parent 49a8562441
commit 640038a115
2 changed files with 22 additions and 0 deletions

View file

@ -99,6 +99,13 @@ 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. Be careful when changing this value since there are hardware limits that need to be considered.
Default is ``2048``. Default is ``2048``.
``watermark``
-----------
Optional string to be rendered into the raster tiles (and static maps) as watermark (bottom-left corner).
Can be used for hard-coding attributions etc. (can also be specified per-style).
Not used by default.
``styles`` ``styles``
========== ==========

View file

@ -50,6 +50,8 @@ module.exports = function(options, repo, params, id, dataResolver) {
var rootPath = options.paths.root; var rootPath = options.paths.root;
var watermark = params.watermark || options.watermark;
var styleFile = params.style; var styleFile = params.style;
var map = { var map = {
renderers: [], renderers: [],
@ -357,6 +359,19 @@ module.exports = function(options, repo, params, id, dataResolver) {
if (opt_overlay) { if (opt_overlay) {
image.overlayWith(opt_overlay); image.overlayWith(opt_overlay);
} }
if (watermark) {
var canvas = new Canvas(scale * width, scale * height);
var ctx = canvas.getContext('2d');
ctx.scale(scale, scale);
ctx.font = '10px sans-serif';
ctx.strokeWidth = '1px';
ctx.strokeStyle = 'rgba(255,255,255,.4)';
ctx.strokeText(watermark, 5, height - 5);
ctx.fillStyle = 'rgba(0,0,0,.4)';
ctx.fillText(watermark, 5, height - 5);
image.overlayWith(canvas.toBuffer());
}
var formatQuality = (params.formatQuality || {})[format] || var formatQuality = (params.formatQuality || {})[format] ||
(options.formatQuality || {})[format]; (options.formatQuality || {})[format];