Make torque_filters accept options param to add canvasClass
This commit is contained in:
parent
043e7b0090
commit
f2a4c22dc7
@ -2,7 +2,7 @@ var torque = require('../');
|
||||
var cartocss = require('./cartocss_render');
|
||||
var Profiler = require('../profiler');
|
||||
var carto = global.carto || require('carto');
|
||||
var filters = require('./torque_filters');
|
||||
var Filters = require('./torque_filters');
|
||||
|
||||
var TAU = Math.PI * 2;
|
||||
var DEFAULT_CARTOCSS = [
|
||||
@ -51,7 +51,7 @@ var filters = require('./torque_filters');
|
||||
this._sprites = []; // sprites per layer
|
||||
this._shader = null;
|
||||
this._icons = {};
|
||||
this._filters = filters(this._canvas);
|
||||
this._filters = new Filters(this._canvas, {canvasClass: options.canvasClass});
|
||||
this.setCartoCSS(this.options.cartocss || DEFAULT_CARTOCSS);
|
||||
this.TILE_SIZE = 256;
|
||||
this._style = null;
|
||||
|
@ -6,9 +6,11 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
function torque_filters(canvas) {
|
||||
function torque_filters(canvas, options) {
|
||||
// jshint newcap: false, validthis: true
|
||||
if (!(this instanceof torque_filters)) { return new torque_filters(canvas); }
|
||||
if (!(this instanceof torque_filters)) { return new torque_filters(canvas, options); }
|
||||
|
||||
options = options || {};
|
||||
|
||||
this._canvas = canvas = typeof canvas === 'string' ? document.getElementById(canvas) : canvas;
|
||||
|
||||
@ -18,6 +20,8 @@ function torque_filters(canvas) {
|
||||
|
||||
this._max = 1;
|
||||
this._data = [];
|
||||
|
||||
this.canvasClass = options.canvasClass;
|
||||
}
|
||||
|
||||
torque_filters.prototype = {
|
||||
@ -32,7 +36,7 @@ torque_filters.prototype = {
|
||||
|
||||
gradient: function (grad) {
|
||||
// create a 256x1 gradient that we'll use to turn a grayscale heatmap into a colored one
|
||||
var canvas = document.createElement('canvas'),
|
||||
var canvas = this._createCanvas(),
|
||||
ctx = canvas.getContext('2d'),
|
||||
gradient = ctx.createLinearGradient(0, 0, 0, 256);
|
||||
|
||||
@ -40,7 +44,7 @@ torque_filters.prototype = {
|
||||
canvas.height = 256;
|
||||
|
||||
for (var i in grad) {
|
||||
gradient.addColorStop(i, grad[i]);
|
||||
gradient.addColorStop(+i, grad[i]);
|
||||
}
|
||||
|
||||
ctx.fillStyle = gradient;
|
||||
@ -74,6 +78,12 @@ torque_filters.prototype = {
|
||||
pixels[i - 1] = gradient[j + 2];
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_createCanvas: function() {
|
||||
return this.canvasClass
|
||||
? new this.canvasClass()
|
||||
: document.createElement('canvas');
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user