<commit_before>goog.provide('olcs.OLImageryProvider');



/**
 * Special class derived from Cesium.ImageryProvider
 * that is connected to the given ol.source.TileImage.
 * @param {!ol.source.TileImage} source
 * @constructor
 * @extends {Cesium.ImageryProvider}
 */
olcs.OLImageryProvider = function(source) {
  /**
   * @type {!ol.source.TileImage}
   * @private
   */
  this.source_ = source;

  /**
   * @type {!ol.proj.Projection}
   * @private
   */
  this.projection_ = source.getProjection();

  var tileGrid = source.getTileGrid();

  this.tileSize_ = !goog.isNull(tileGrid) ? tileGrid.getTileSize(0) : 256;
  this.minimumLevel_ = !goog.isNull(tileGrid) ? tileGrid.getMinZoom() : 0;
  this.maximumLevel_ = !goog.isNull(tileGrid) ? tileGrid.getMaxZoom() : 18;

  this.credit_ = undefined; //TODO: create from attributions
  this.tilingScheme_ = new Cesium.WebMercatorTilingScheme(); //TODO:
  this.rectangle_ = this.tilingScheme_.rectangle;
  this.errorEvent_ = new Cesium.Event();

  this.emptyCanvas_ = goog.dom.createElement(goog.dom.TagName.CANVAS);
  this.emptyCanvas_.width = 1;
  this.emptyCanvas_.height = 1;
};
goog.inherits(olcs.OLImageryProvider, Cesium.ImageryProvider);


// definitions of getters that are required to be present
// in the Cesium.ImageryProvider instance:
Object.defineProperties(olcs.OLImageryProvider.prototype, {
  ready: {
    get: function() {return true;}
  },

  rectangle: {
    get: /** @this {olcs.OLImageryProvider} */
        function() {return this.rectangle_;}
  },

  tileWidth: {
    get: /** @this {olcs.OLImageryProvider} */
        function() {return this.tileSize_;}
  },

  tileHeight: {
    get: /** @this {olcs.OLImageryProvider} */
        function() {return this.tileSize_;}
  },

  maximumLevel: {
    get: /** @this {olcs.OLImageryProvider} */
        function() {return this.maximumLevel_;}
  },

  minimumLevel: {
    get: /** @this {olcs.OLImageryProvider} */
        function() {return this.minimumLevel_;}
  },

  tilingScheme: {
    get: /** @this {olcs.OLImageryProvider} */
        function() {return this.tilingScheme_;}
  },

  tileDiscardPolicy: {
    get: function() {return undefined;}
  },

  errorEvent: {
    get: /** @this {olcs.OLImageryProvider} */
        function() {return this.errorEvent_;}
  },

  credit: {
    get: /** @this {olcs.OLImageryProvider} */
        function() {return this.credit_;}
  },

  proxy: {
    get: function() {return undefined;}
  },

  hasAlphaChannel: {
    get: function() {return true;}
  }
});


/**
 * TODO: attributions for individual tile ranges
 * @override
 * @this {olcs.OLImageryProvider}
 */
olcs.OLImageryProvider.prototype['getTileCredits'] = function(x, y, level) {
  return undefined;
};


/**
 * @override
 * @this {olcs.OLImageryProvider}
 */
olcs.OLImageryProvider.prototype['requestImage'] =
    function(x, y, level) {
  var tileUrlFunction = this.source_.getTileUrlFunction();
  if (!goog.isNull(tileUrlFunction)) {
    var url = tileUrlFunction(new ol.TileCoord(level, x, -y - 1),
                              1, this.projection_);
    return goog.isDef(url) ?
           Cesium.ImageryProvider.loadImage(this, url) : this.emptyCanvas_;
  } else {
    // return empty canvas to stop Cesium from retrying later
    return this.emptyCanvas_;
  }
};
<commit_msg>Wait for the source to load before reading its properties (useful for TileJSONs)<commit_after>goog.provide('olcs.OLImageryProvider');



/**
 * Special class derived from Cesium.ImageryProvider
 * that is connected to the given ol.source.TileImage.
 * @param {!ol.source.TileImage} source
 * @constructor
 * @extends {Cesium.ImageryProvider}
 */
olcs.OLImageryProvider = function(source) {
  /**
   * @type {!ol.source.TileImage}
   * @private
   */
  this.source_ = source;

  /**
   * @type {!ol.proj.Projection}
   * @private
   */
  this.projection_ = source.getProjection();

  this.ready_ = false;

  this.errorEvent_ = new Cesium.Event();

  this.emptyCanvas_ = goog.dom.createElement(goog.dom.TagName.CANVAS);
  this.emptyCanvas_.width = 1;
  this.emptyCanvas_.height = 1;
};
goog.inherits(olcs.OLImageryProvider, Cesium.ImageryProvider);


// definitions of getters that are required to be present
// in the Cesium.ImageryProvider instance:
Object.defineProperties(olcs.OLImageryProvider.prototype, {
  ready: {
    get: /** @this {olcs.OLImageryProvider} */
        function() {return this.checkReady();}
  },

  rectangle: {
    get: /** @this {olcs.OLImageryProvider} */
        function() {return this.rectangle_;}
  },

  tileWidth: {
    get: /** @this {olcs.OLImageryProvider} */
        function() {return this.tileSize_;}
  },

  tileHeight: {
    get: /** @this {olcs.OLImageryProvider} */
        function() {return this.tileSize_;}
  },

  maximumLevel: {
    get: /** @this {olcs.OLImageryProvider} */
        function() {return this.maximumLevel_;}
  },

  minimumLevel: {
    get: /** @this {olcs.OLImageryProvider} */
        function() {return this.minimumLevel_;}
  },

  tilingScheme: {
    get: /** @this {olcs.OLImageryProvider} */
        function() {return this.tilingScheme_;}
  },

  tileDiscardPolicy: {
    get: function() {return undefined;}
  },

  errorEvent: {
    get: /** @this {olcs.OLImageryProvider} */
        function() {return this.errorEvent_;}
  },

  credit: {
    get: /** @this {olcs.OLImageryProvider} */
        function() {return this.credit_;}
  },

  proxy: {
    get: function() {return undefined;}
  },

  hasAlphaChannel: {
    get: function() {return true;}
  }
});


/**
 * Checks if the underlying source just got ready and cached required data.
 * @return {boolean} Ready state.
 */
olcs.OLImageryProvider.prototype.checkReady = function() {
  if (!this.ready_ && this.source_.getState() == 'ready') {
    this.projection_ = this.source_.getProjection();
    var tileGrid = this.source_.getTileGrid();
    if (!goog.isNull(tileGrid)) {
      this.tileSize_ = tileGrid.getTileSize(0);

      // WARNING: Do not use the minimum level (at least until the extent is
      // properly set). Cesium assumes the minimumLevel contains only
      // a few tiles and tries to load them all at once -- this can
      // freeze and/or crash the browser !
      this.minimumLevel_ = 0; //tileGrid.getMinZoom();
      this.maximumLevel_ = tileGrid.getMaxZoom();

      this.credit_ = undefined; //TODO: create from attributions
      this.tilingScheme_ = new Cesium.WebMercatorTilingScheme(); //TODO:
      this.rectangle_ = this.tilingScheme_.rectangle;

      this.ready_ = true;
    }
  }
  return this.ready_;
};


/**
 * TODO: attributions for individual tile ranges
 * @override
 * @this {olcs.OLImageryProvider}
 */
olcs.OLImageryProvider.prototype['getTileCredits'] = function(x, y, level) {
  return undefined;
};


/**
 * @override
 * @this {olcs.OLImageryProvider}
 */
olcs.OLImageryProvider.prototype['requestImage'] =
    function(x, y, level) {
  var tileUrlFunction = this.source_.getTileUrlFunction();
  if (!goog.isNull(tileUrlFunction)) {
    var url = tileUrlFunction(new ol.TileCoord(level, x, -y - 1),
                              1, this.projection_);
    return goog.isDef(url) ?
           Cesium.ImageryProvider.loadImage(this, url) : this.emptyCanvas_;
  } else {
    // return empty canvas to stop Cesium from retrying later
    return this.emptyCanvas_;
  }
};

{'fraction_non_alphanumeric': 0.1427987464232184, 'fraction_numerical': 0.0023163918790025887, 'mean_word_length': 3.225676453655728, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4193933', 'n_tokens_mistral': 2485, 'n_tokens_neox': 2396, 'n_words': 504}