<commit_before>// FIXME handle rotation
// FIXME handle date line wrap
// FIXME handle layer order
// FIXME check clean-up code

goog.provide('ol.control.Attribution');

goog.require('goog.dom');
goog.require('goog.dom.TagName');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('goog.object');
goog.require('goog.style');
goog.require('ol.Collection');
goog.require('ol.Control');
goog.require('ol.CoverageArea');
goog.require('ol.Layer');
goog.require('ol.MapProperty');
goog.require('ol.TileCoverageArea');



/**
 * @constructor
 * @extends {ol.Control}
 * @param {ol.Map} map Map.
 */
ol.control.Attribution = function(map) {

  goog.base(this, map);

  /**
   * @private
   * @type {Element}
   */
  this.ulElement_ = goog.dom.createElement(goog.dom.TagName.UL);

  /**
   * @private
   * @type {Array.<number>}
   */
  this.layersListenerKeys_ = null;

  /**
   * @private
   * @type {Object.<number, ?number>}
   */
  this.layerVisibleChangeListenerKeys_ = {};

  /**
   * @private
   * @type {Object.<number, Element>}
   */
  this.attributionElements_ = {};

  /**
   * @private
   * @type {Object.<number, Array.<ol.CoverageArea>>}
   */
  this.coverageAreass_ = {};

  goog.events.listen(map, ol.Object.getChangedEventType(ol.MapProperty.CENTER),
      this.handleMapChanged, false, this);

  goog.events.listen(map, ol.Object.getChangedEventType(ol.MapProperty.LAYERS),
      this.handleMapLayersChanged, false, this);

  goog.events.listen(map,
      ol.Object.getChangedEventType(ol.MapProperty.RESOLUTION),
      this.handleMapChanged, false, this);

  goog.events.listen(map, ol.Object.getChangedEventType(ol.MapProperty.SIZE),
      this.handleMapChanged, false, this);

  this.handleMapLayersChanged();

};
goog.inherits(ol.control.Attribution, ol.Control);


/**
 * @param {ol.Layer} layer Layer.
 * @private
 */
ol.control.Attribution.prototype.createAttributionElementsForLayer_ =
    function(layer) {

  var store = layer.getStore();
  var attributions = store.getAttributions();
  if (goog.isNull(attributions)) {
    return;
  }

  var map = this.getMap();
  var mapIsDef = map.isDef();
  var mapExtent = /** @type {ol.Extent} */ map.getExtent();
  var mapProjection = /** @type {ol.Projection} */ map.getProjection();
  var mapResolution = /** @type {number} */ map.getResolution();

  var layerVisible = layer.getVisible();

  var attributionVisibilities;
  if (mapIsDef && layerVisible) {
    attributionVisibilities = this.getLayerAttributionVisiblities_(
        layer, mapExtent, mapResolution, mapProjection);
  } else {
    attributionVisibilities = null;
  }

  goog.array.forEach(attributions, function(attribution) {

    var attributionKey = goog.getUid(attribution);

    var attributionElement = goog.dom.createElement(goog.dom.TagName.LI);
    attributionElement.innerHTML = attribution.getHtml();

    if (!map.isDef ||
        !layerVisible ||
        !attributionVisibilities[attributionKey]) {
      goog.style.showElement(attributionElement, false);
    }

    goog.dom.appendChild(this.ulElement_, attributionElement);

    this.attributionElements_[attributionKey] = attributionElement;

  }, this);

};

<commit_msg>Add missing check<commit_after>// FIXME handle rotation
// FIXME handle date line wrap
// FIXME handle layer order
// FIXME check clean-up code

goog.provide('ol.control.Attribution');

goog.require('goog.dom');
goog.require('goog.dom.TagName');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('goog.object');
goog.require('goog.style');
goog.require('ol.Collection');
goog.require('ol.Control');
goog.require('ol.CoverageArea');
goog.require('ol.Layer');
goog.require('ol.MapProperty');
goog.require('ol.TileCoverageArea');



/**
 * @constructor
 * @extends {ol.Control}
 * @param {ol.Map} map Map.
 */
ol.control.Attribution = function(map) {

  goog.base(this, map);

  /**
   * @private
   * @type {Element}
   */
  this.ulElement_ = goog.dom.createElement(goog.dom.TagName.UL);

  /**
   * @private
   * @type {Array.<number>}
   */
  this.layersListenerKeys_ = null;

  /**
   * @private
   * @type {Object.<number, ?number>}
   */
  this.layerVisibleChangeListenerKeys_ = {};

  /**
   * @private
   * @type {Object.<number, Element>}
   */
  this.attributionElements_ = {};

  /**
   * @private
   * @type {Object.<number, Array.<ol.CoverageArea>>}
   */
  this.coverageAreass_ = {};

  goog.events.listen(map, ol.Object.getChangedEventType(ol.MapProperty.CENTER),
      this.handleMapChanged, false, this);

  goog.events.listen(map, ol.Object.getChangedEventType(ol.MapProperty.LAYERS),
      this.handleMapLayersChanged, false, this);

  goog.events.listen(map,
      ol.Object.getChangedEventType(ol.MapProperty.RESOLUTION),
      this.handleMapChanged, false, this);

  goog.events.listen(map, ol.Object.getChangedEventType(ol.MapProperty.SIZE),
      this.handleMapChanged, false, this);

  this.handleMapLayersChanged();

};
goog.inherits(ol.control.Attribution, ol.Control);


/**
 * @param {ol.Layer} layer Layer.
 * @private
 */
ol.control.Attribution.prototype.createAttributionElementsForLayer_ =
    function(layer) {

  var store = layer.getStore();
  var attributions = store.getAttributions();
  if (goog.isNull(attributions)) {
    return;
  }

  var map = this.getMap();
  var mapIsDef = map.isDef();
  var mapExtent = /** @type {ol.Extent} */ map.getExtent();
  var mapProjection = /** @type {ol.Projection} */ map.getProjection();
  var mapResolution = /** @type {number} */ map.getResolution();

  var layerVisible = layer.getVisible();

  var attributionVisibilities;
  if (mapIsDef && layerVisible) {
    attributionVisibilities = this.getLayerAttributionVisiblities_(
        layer, mapExtent, mapResolution, mapProjection);
  } else {
    attributionVisibilities = null;
  }

  goog.array.forEach(attributions, function(attribution) {

    var attributionKey = goog.getUid(attribution);

    var attributionElement = goog.dom.createElement(goog.dom.TagName.LI);
    attributionElement.innerHTML = attribution.getHtml();

    if (!map.isDef ||
        !layerVisible ||
        goog.isNull(attributionVisibilities) ||
        !attributionVisibilities[attributionKey]) {
      goog.style.showElement(attributionElement, false);
    }

    goog.dom.appendChild(this.ulElement_, attributionElement);

    this.attributionElements_[attributionKey] = attributionElement;

  }, this);

};


{'fraction_non_alphanumeric': 0.15435929258454856, 'fraction_numerical': 0.0, 'mean_word_length': 3.959230769230769, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4096560', 'n_tokens_mistral': 2193, 'n_tokens_neox': 2052, 'n_words': 331}