preloads all icons before the animation is started

This commit is contained in:
Francisco Dans 2015-01-08 16:25:42 +01:00
parent 8241bd6c8c
commit d1c224ff13

View File

@ -124,18 +124,34 @@ var carto = global.carto || require('carto');
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(typeof this._icons[img_name] === 'undefined'){
var new_img = this._createImage();
new_img.onload = function(){
self._icons[img_name] = new_img;
self.clearSpriteCache();
var img_names = this._shader.getIconURLs();
if(img_names.length > 0){
if(Object.keys(this._icons).length === 0){
for (var i = 0; i<img_names.length; i++){
var new_img = this._createImage();
self._icons[img_names[i]] = null;
if (typeof self._icons.itemsToLoad === 'undefined'){
self._icons.itemsToLoad = img_names.length;
}
new_img.onload = function(e){
self._icons[this.src] = this;
if(Object.keys(self._icons).length === img_names.length + 1){
self._icons.itemsToLoad--;
if(self._icons.itemsToLoad === 0){
self.clearSpriteCache();
self.fire("allIconsLoaded");
}
}
};
new_img.onerror = function(){
};
new_img.src = img_names[i];
}
};
new_img.src = img_name;
}
else {
if(this._icons.itemsToLoad==0) {
var img_name = st["marker-file"] || st["point-file"];
var img = this._icons[img_name];
img.w = st['marker-width'] || img.width;
img.h = st['marker-width'] || st['marker-height'];