Add support for watermarks (close #130)

This commit is contained in:
Petr Sloup committed 2017-03-15 17:06:26 +01:00
1 parent 49a8562441
commit 640038a115
2 files changed
+22

No files matched your search

+7
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.
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``
==========
+15
View File
@@ -50,6 +50,8 @@ module.exports = function(options, repo, params, id, dataResolver) {
var rootPath = options.paths.root;
var watermark = params.watermark || options.watermark;
var styleFile = params.style;
var map = {
renderers: [],
@@ -357,6 +359,19 @@ module.exports = function(options, repo, params, id, dataResolver) {
if (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] ||
(options.formatQuality || {})[format];