Skip to content

Commit

Permalink
Merge pull request #9 from maptastik/grayscale-options
Browse files Browse the repository at this point in the history
Fix access to quota values
  • Loading branch information
Zverik committed Dec 8, 2015
2 parents 69b57d8 + 178b42d commit f71e72e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions TileLayer.Grayscale.js
Expand Up @@ -8,7 +8,10 @@ L.TileLayer.Grayscale = L.TileLayer.extend({
quotaRed: 3,
quotaGreen: 4,
quotaBlue: 1,
quotaDivider: quotaRed + quotaGreen + quotaBlue,
quotaDividerTune: 0,
quotaDivider: function() {
return this.quotaRed + this.quotaGreen + this.quotaBlue + this.quotaDividerTune;
}
},

initialize: function (url, options) {
Expand Down Expand Up @@ -39,7 +42,7 @@ L.TileLayer.Grayscale = L.TileLayer.extend({
var imgd = ctx.getImageData(0, 0, this._layer.options.tileSize, this._layer.options.tileSize);
var pix = imgd.data;
for (var i = 0, n = pix.length; i < n; i += 4) {
pix[i] = pix[i + 1] = pix[i + 2] = (quotaRed * pix[i] + quotaGreen * pix[i + 1] + quotaBlue * pix[i + 2]) / quotaDivider;
pix[i] = pix[i + 1] = pix[i + 2] = (this._layer.options.quotaRed * pix[i] + this._layer.options.quotaGreen * pix[i + 1] + this._layer.options.quotaBlue * pix[i + 2]) / this._layer.options.quotaDivider();
}
ctx.putImageData(imgd, 0, 0);
this.removeAttribute("crossorigin");
Expand Down

0 comments on commit f71e72e

Please sign in to comment.