<commit_before>/**
 * @name cartodb-leaflet
 * @author: <EMAIL>
 * @fileoverview <b>Author:</b> Vizzuality.com<br/> <b>Licence:</b>
 *               Licensed under <a
 *               href="http://opensource.org/licenses/mit-license.php">MIT</a>
 *               license.<br/> This library lets you to use CartoDB with Leaflet.
 *
 */


(function() {

if(typeof(L) == "undefined")
  return;

L.CartoDBLayer = L.TileLayer.extend({

  options: {
    query:          "SELECT * FROM {{table_name}}",
    opacity:        0.99,
    auto_bound:     false,
    attribution:    "CartoDB",
    debug:          false,
    visible:        true,
    added:          false,
    tiler_domain:   "cartodb.com",
    tiler_port:     "80",
    tiler_protocol: "http",
    sql_domain:     "cartodb.com",
    sql_port:       "80",
    sql_protocol:   "http",
    extra_params:   {},
    cdn_url:        null,
    subdomains:     null
  },


  initialize: function (options) {
    // Set options
    L.Util.setOptions(this, options);

    // Some checks
    if (!options.table_name || !options.map) {
      if (options.debug) {
        throw('cartodb-leaflet needs at least a CartoDB table name and the Leaflet map object :(');
      } else { return }
    }

    // Bounds? CartoDB does it
    if (options.auto_bound)
      this.setBounds();

    // Add cartodb logo, yes sir!
    this._addWadus({left:8, bottom:8}, 0, this.options.map._container);

    this.fire = this.trigger;

    L.TileLayer.prototype.initialize.call(this);
  },


  // overwrite getTileUrl in order to
  // support different tiles subdomains in tilejson way
  getTileUrl: function (tilePoint) {
    this._adjustTilePoint(tilePoint);

    var tiles = this.tilejson.tiles;

    var index = (tilePoint.x + tilePoint.y) % tiles.length;

    return L.Util.template(tiles[index], L.Util.extend({
      z: this._getZoomForUrl(),
      x: tilePoint.x,
      y: tilePoint.y
    }, this.options));
  },

  /**
   * Change opacity of the layer
   * @params {Integer} New opacity
   */
  setOpacity: function(opacity) {

    this._checkLayer();

    if (isNaN(opacity) || opacity>1 || opacity<0) {
      throw new Error(opacity + ' is not a valid value');
    }

    // Leaflet only accepts 0-0.99... Weird!
    this.options.opacity = Math.min(opacity, 0.99);

    if (this.options.visible) {
      L.TileLayer.prototype.setOpacity.call(this,  opacity);
      this.fire('updated');
    }
  },


  /**
   * When Leaflet adds the layer... go!
   * @params {map}
   */
  onAdd: function(map) {
    this.__update();
    this.fire('added');
    this.options.added = true;<commit_msg>fixed setOpacity in leeaflet cartodb layer<commit_after>/**
 * @name cartodb-leaflet
 * @author: Vizzuality.com
 * @fileoverview <b>Author:</b> Vizzuality.com<br/> <b>Licence:</b>
 *               Licensed under <a
 *               href="http://opensource.org/licenses/mit-license.php">MIT</a>
 *               license.<br/> This library lets you to use CartoDB with Leaflet.
 *
 */


(function() {

if(typeof(L) == "undefined")
  return;

L.CartoDBLayer = L.TileLayer.extend({

  options: {
    query:          "SELECT * FROM {{table_name}}",
    opacity:        0.99,
    auto_bound:     false,
    attribution:    "CartoDB",
    debug:          false,
    visible:        true,
    added:          false,
    tiler_domain:   "cartodb.com",
    tiler_port:     "80",
    tiler_protocol: "http",
    sql_domain:     "cartodb.com",
    sql_port:       "80",
    sql_protocol:   "http",
    extra_params:   {},
    cdn_url:        null,
    subdomains:     null
  },


  initialize: function (options) {
    // Set options
    L.Util.setOptions(this, options);

    // Some checks
    if (!options.table_name || !options.map) {
      if (options.debug) {
        throw('cartodb-leaflet needs at least a CartoDB table name and the Leaflet map object :(');
      } else { return }
    }

    // Bounds? CartoDB does it
    if (options.auto_bound)
      this.setBounds();

    // Add cartodb logo, yes sir!
    this._addWadus({left:8, bottom:8}, 0, this.options.map._container);

    this.fire = this.trigger;

    L.TileLayer.prototype.initialize.call(this);
  },


  // overwrite getTileUrl in order to
  // support different tiles subdomains in tilejson way
  getTileUrl: function (tilePoint) {
    this._adjustTilePoint(tilePoint);

    var tiles = this.tilejson.tiles;

    var index = (tilePoint.x + tilePoint.y) % tiles.length;

    return L.Util.template(tiles[index], L.Util.extend({
      z: this._getZoomForUrl(),
      x: tilePoint.x,
      y: tilePoint.y
    }, this.options));
  },

  /**
   * Change opacity of the layer
   * @params {Integer} New opacity
   */
  setOpacity: function(opacity) {

    this._checkLayer();

    if (isNaN(opacity) || opacity>1 || opacity<0) {
      throw new Error(opacity + ' is not a valid value');
    }

    // Leaflet only accepts 0-0.99... Weird!
    this.options.opacity = Math.min(opacity, 0.99);

    if (this.options.visible) {
      L.TileLayer.prototype.setOpacity.call(this, this.options.opacity);
      this.fire('updated');
    }
  },


  /**
   * When Leaflet adds the layer... go!
   * @params {map}
   */
  onAdd: function(map) {
    this.__update();
    this.fire('added');
    this.options.added = true;
{'fraction_non_alphanumeric': 0.14369556985990156, 'fraction_numerical': 0.007194244604316547, 'mean_word_length': 2.3521573604060912, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, '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': '4427915', 'n_tokens_mistral': 1820, 'n_tokens_neox': 1730, 'n_words': 396}