function onTileLoad(tile, time) {
        var i;

        if (midUpdate) {
            console.error('Tile load callback in the middle of drawing routine.');
            return;
        } else if (!tile.loaded) {
            console.error('Tile ' + tile + ' failed to load: ' + tile.url);
            return;
        } else if (time < lastResetTime) {
            that.log('Ignoring tile ' + tile + ' loaded before reset: ' + tile.url);
            return;
        }

        var insertionIndex = tilesLoaded.length;

        if (tilesLoaded.length >= that.config.imageCacheSize) {
            var worstTile = null;
            var worstTileIndex = -1;

            for (i = tilesLoaded.length - 1; i >= 0; i--) {
                var prevTile = tilesLoaded[i];

                if (prevTile.beingDrawn) {
                    continue;
                } else if (!worstTile) {
                    worstTile = prevTile;
                    worstTileIndex = i;
                    continue;
                }

                var prevTime = prevTile.lastTouchTime;
                var worstTime = worstTile.lastTouchTime;
                var prevLevel = prevTile.level;
                var worstLevel = worstTile.level;

                if (prevTime < worstTime || (prevTime === worstTime && prevLevel > worstLevel)) {
                    worstTile = prevTile;
                    worstTileIndex = i;
                }
            }

            if (worstTile && worstTileIndex >= 0) {
                worstTile.unload();
                insertionIndex = worstTileIndex;
                // Note: we don't want or need to delete the actual Tile
                // object from tilesMatrix; that's negligible memory.
            }
        }

        tilesLoaded[insertionIndex] = tile;
        that.$container.trigger('malakh:force_redraw');
    }
/**
     * Handles actions performed on tile image file load. Sets tile's <code>image</code> parameter, marks it as loaded
     * (unless an error occured) and adds the tile to a table of tiles to draw. If the table exceedes the
     * given <code>that.config.imageCacheSize</code> length, one of existing tiles is removed from the table.
     * This is determined by tiles' levels and times they were "touched" for the last time.
     *
     * @param {Malakh.Tile} tile
     * @param {number} time
     * @param {Image} image
     * @private
     */
Handles actions performed on tile image file load. Sets tile's image parameter, marks it as loaded
(unless an error occured) and adds the tile to a table of tiles to draw. If the table exceedes the
given that.config.imageCacheSize length, one of existing tiles is removed from the table.
This is determined by tiles' levels and times they were "touched" for the last time.

@param {Malakh.Tile} tile
@param {number} time
@param {Image} image
@private
Handles actions performed on tile image file load . Sets tile ' s image parameter marks it as loaded ( unless an error occured ) and adds the tile to a table of tiles to draw . If the table exceedes the given that . config . imageCacheSize length one of existing tiles is removed from the table . This is determined by tiles ' levels and times they were " touched " for the last time . @param { Malakh . Tile } tile @param { number } time @param { Image } image @private
function onTileLoad(tile, time) {
        var i;
        if (midUpdate) {
            console.error('Tile load callback in the middle of drawing routine.');
            return;
        } else if (!tile.loaded) {
            console.error('Tile ' + tile + ' failed to load: ' + tile.url);
            return;
        } else if (time < lastResetTime) {
            that.log('Ignoring tile ' + tile + ' loaded before reset: ' + tile.url);
            return;
        }
        var insertionIndex = tilesLoaded.length;
        if (tilesLoaded.length >= that.config.imageCacheSize) {
            var worstTile = null;
            var worstTileIndex = -1;
            for (i = tilesLoaded.length - 1; i >= 0; i--) {
                var prevTile = tilesLoaded[i];
                if (prevTile.beingDrawn) {
                    continue;
                } else if (!worstTile) {
                    worstTile = prevTile;
                    worstTileIndex = i;
                    continue;
                }
                var prevTime = prevTile.lastTouchTime;
                var worstTime = worstTile.lastTouchTime;
                var prevLevel = prevTile.level;
                var worstLevel = worstTile.level;
                if (prevTime < worstTime || (prevTime === worstTime && prevLevel > worstLevel)) {
                    worstTile = prevTile;
                    worstTileIndex = i;
                }
            }
            if (worstTile && worstTileIndex >= 0) {
                worstTile.unload();
                insertionIndex = worstTileIndex;
            }
        }
        tilesLoaded[insertionIndex] = tile;
        that.$container.trigger('malakh:force_redraw');
    }
function onTileLoad ( tile , time ) { var i ; if ( midUpdate ) { console . error ( 'Tile load callback in the middle of drawing routine.' ) ; return ; } else if ( ! tile . loaded ) { console . error ( 'Tile ' + tile + ' failed to load: ' + tile . url ) ; return ; } else if ( time < lastResetTime ) { that . log ( 'Ignoring tile ' + tile + ' loaded before reset: ' + tile . url ) ; return ; } var insertionIndex = tilesLoaded . length ; if ( tilesLoaded . length >= that . config . imageCacheSize ) { var worstTile = null ; var worstTileIndex = - 1 ; for ( i = tilesLoaded . length - 1 ; i >= 0 ; i -- ) { var prevTile = tilesLoaded [ i ] ; if ( prevTile . beingDrawn ) { continue ; } else if ( ! worstTile ) { worstTile = prevTile ; worstTileIndex = i ; continue ; } var prevTime = prevTile . lastTouchTime ; var worstTime = worstTile . lastTouchTime ; var prevLevel = prevTile . level ; var worstLevel = worstTile . level ; if ( prevTime < worstTime || ( prevTime === worstTime && prevLevel > worstLevel ) ) { worstTile = prevTile ; worstTileIndex = i ; } } if ( worstTile && worstTileIndex >= 0 ) { worstTile . unload ( ) ; insertionIndex = worstTileIndex ; } } tilesLoaded [ insertionIndex ] = tile ; that . $container . trigger ( 'malakh:force_redraw' ) ; }
Handles actions performed on tile image file load.
Handles actions performed on tile image file load .
// Note: we don't want or need to delete the actual Tile // object from tilesMatrix; that's negligible memory.