loads async icon files as they are needed

This commit is contained in:
Francisco Dans 2015-01-07 17:42:50 +01:00
parent 1113a100d1
commit 37c35732d7

View File

@ -104,6 +104,7 @@ var carto = global.carto || require('carto');
// generate sprite based on cartocss style
//
generateSprite: function(shader, value, shaderVars) {
var self = this;
var prof = Profiler.metric('torque.renderer.point.generateSprite').start();
var st = shader.getStyle({
value: value
@ -124,18 +125,26 @@ var carto = global.carto || require('carto');
var ctx = canvas.getContext('2d');
var w = ctx.width = canvas.width = ctx.height = canvas.height = Math.ceil(canvasSize);
ctx.translate(w/2, w/2);
var img_name = st['point-file'] || st['marker-file'];
if(img_name) {
if(!(img_name in this._icons)){
var new_img = new Image();
if(img_name){
if(typeof this._icons[img_name] === 'undefined'){
var new_img = this._createImage();
new_img.onload = function(){
self._icons[img_name] = new_img;
self.clearSpriteCache();
};
new_img.src = img_name;
this._icons[img_name] = new_img;
}
var img = this._icons[img_name];
img.w = st['marker-width'] || img.width;
img.h = st['marker-width'] || st['marker-height'];
cartocss.renderSprite(ctx, img);
} else {
else {
var img = this._icons[img_name];
img.w = st['marker-width'] || img.width;
img.h = st['marker-width'] || st['marker-height'];
cartocss.renderSprite(ctx, img);
}
}
else {
var mt = st['marker-type'];
if (mt && mt === 'rectangle') {
cartocss.renderRectangle(ctx, st);