# all files / ol/ tilecache.js

48% Statements 12/25
25% Branches 2/8
50% Functions 2/4
48% Lines 12/25

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    691×

    1×
    1×
    1×

    1×

    120×

    120×

    1×

    1×
    7×

    1×

    1×

     goog.provide('ol.TileCache');

    goog.require('ol.TileRange');
    goog.require('ol.structs.LRUCache');
    goog.require('ol.tilecoord');

    /**
     * @constructor
     * @extends {ol.structs.LRUCache.<ol.Tile>}
     * @param {number=} opt_highWaterMark High water mark.
     * @struct
     */
    ol.TileCache = function(opt_highWaterMark) {

      goog.base(this);

      /**
       * @private
       * @type {number}
       */
      this.highWaterMark_ = opt_highWaterMark !== undefined ? opt_highWaterMark : 2048;

    };
    goog.inherits(ol.TileCache, ol.structs.LRUCache);

    /**
     * @return {boolean} Can expire cache.
     */
    ol.TileCache.prototype.canExpireCache = function() {
      return this.getCount() > this.highWaterMark_;
    };

    /**
     * @param {Object.<string, ol.TileRange>} usedTiles Used tiles.
     */
    ol.TileCache.prototype.expireCache = function(usedTiles) {
      var tile, zKey;
      while (this.canExpireCache()) {
        tile = this.peekLast();
        zKey = tile.tileCoord[0].toString();
        if (zKey in usedTiles && usedTiles[zKey].contains(tile.tileCoord)) {
          break;
        } else {
          this.pop().dispose();
        }
      }
    };

    /**
     * Remove a tile range from the cache, e.g. to invalidate tiles.
     * @param {ol.TileRange} tileRange The tile range to prune.
     */
    ol.TileCache.prototype.pruneTileRange = function(tileRange) {
      var i = this.getCount(),
          key;
      while (i--) {
        key = this.peekLastKey();
        if (tileRange.contains(ol.tilecoord.createFromString(key))) {
          this.pop().dispose();
        } else {
          this.get(key);
        }
      }
    };