Abstract canvas/image creation, if a class is provided it will use that as constructor.

Otherwise it will fallback to browser implementation.
This commit is contained in:
Raul Ochoa 2014-12-09 16:23:18 +01:00
parent 3471a2ac6d
commit 7499e8cf6a

View File

@ -77,8 +77,7 @@ var carto = require('carto');
return null; return null;
} }
var canvas = document.createElement('canvas'); var canvas = this._createCanvas();
// take into account the exterior ring to calculate the size // take into account the exterior ring to calculate the size
var canvasSize = (st.lineWidth || 0) + pointSize*2; var canvasSize = (st.lineWidth || 0) + pointSize*2;
var ctx = canvas.getContext('2d'); var ctx = canvas.getContext('2d');
@ -97,7 +96,7 @@ var carto = require('carto');
} }
prof.end(true); prof.end(true);
if (torque.flags.sprites_to_images) { if (torque.flags.sprites_to_images) {
var i = new Image(); var i = this._createImage();
i.src = canvas.toDataURL(); i.src = canvas.toDataURL();
return i; return i;
} }
@ -125,6 +124,18 @@ var carto = require('carto');
prof.end(true); prof.end(true);
}, },
_createCanvas: function() {
return this.options.canvasClass
? new this.options.canvasClass()
: document.createElement('canvas');
},
_createImage: function() {
return this.options.imageClass
? new this.options.imageClass()
: new Image();
},
// //
// renders a tile in the canvas for key defined in // renders a tile in the canvas for key defined in
// the torque tile // the torque tile