<commit_before>var _ = require('underscore');
var GMapsLayerView = require('./gmaps-layer-view');
var CartoDBLayerGroupGmaps = require('./cartodb-layer-group-gmaps');

var GMapsCartoDBLayerGroupView = function(layerModel, gmapsMap) {
  var self = this;
  var hovers = [];

  _.bindAll(this, 'featureOut', 'featureOver', 'featureClick');

  var opts = _.clone(layerModel.attributes);

  opts.map =  gmapsMap;

  var // preserve the user's callbacks
  _featureOver  = opts.featureOver,
  _featureOut   = opts.featureOut,
  _featureClick = opts.featureClick;

  var previousEvent;
  var eventTimeout = -1;

  opts.featureOver  = function(e, latlon, pxPos, data, layer) {
    if (!hovers[layer]) {
      self.trigger('layerenter', e, latlon, pxPos, data, layer);
    }
    hovers[layer] = 1;
    _featureOver  && _featureOver.apply(this, arguments);
    self.featureOver  && self.featureOver.apply(this, arguments);

    // if the event is the same than before just cancel the event
    // firing because there is a layer on top of it
    if (e.timeStamp === previousEvent) {
      clearTimeout(eventTimeout);
    }
    eventTimeout = setTimeout(function() {
      self.trigger('mouseover', e, latlon, pxPos, data, layer);
      self.trigger('layermouseover', e, latlon, pxPos, data, layer);
    }, 0);
    previousEvent = e.timeStamp;
  };

  opts.featureOut  = function(m, layer) {
    if (hovers[layer]) {
      self.trigger('layermouseout', layer);
    }
    hovers[layer] = 0;
    if(!_.any(hovers)) {
      self.trigger('mouseout');
    }
    _featureOut  && _featureOut.apply(this, arguments);
    self.featureOut  && self.featureOut.apply(this, arguments);
  };

  opts.featureClick  = _.debounce(function() {
    _featureClick  && _featureClick.apply(this, arguments);
    self.featureClick  && self.featureClick.apply(opts, arguments);
  }, 10);


  this.model = layerModel;

  CartoDBLayerGroupGmaps.call(this, opts);
  GMapsLayerView.call(this, layerModel, this, gmapsMap);
};

_.extend(
  GMapsCartoDBLayerGroupView.prototype,
  GMapsLayerView.prototype,
  CartoDBLayerGroupGmaps.prototype,
  {

  reload: function() {
    this.model.invalidate();
  },

  remove: function() {
    GMapsLayerView.prototype.remove.call(this);
    this.clear();
  },

  featureOver: function(e, latlon, pixelPos, data, layer) {
    // dont pass gmaps LatLng
    this.trigger('featureOver', e, [latlon.lat(), latlon.lng()], pixelPos, data, layer);
  },

  featureOut: function(e, layer) {
    this.trigger('featureOut', e, layer);
  },<commit_msg>No need to set the model here<commit_after>var _ = require('underscore');
var GMapsLayerView = require('./gmaps-layer-view');
var CartoDBLayerGroupGmaps = require('./cartodb-layer-group-gmaps');

var GMapsCartoDBLayerGroupView = function(layerModel, gmapsMap) {
  var self = this;
  var hovers = [];

  _.bindAll(this, 'featureOut', 'featureOver', 'featureClick');

  var opts = _.clone(layerModel.attributes);

  opts.map =  gmapsMap;

  var // preserve the user's callbacks
  _featureOver  = opts.featureOver,
  _featureOut   = opts.featureOut,
  _featureClick = opts.featureClick;

  var previousEvent;
  var eventTimeout = -1;

  opts.featureOver  = function(e, latlon, pxPos, data, layer) {
    if (!hovers[layer]) {
      self.trigger('layerenter', e, latlon, pxPos, data, layer);
    }
    hovers[layer] = 1;
    _featureOver  && _featureOver.apply(this, arguments);
    self.featureOver  && self.featureOver.apply(this, arguments);

    // if the event is the same than before just cancel the event
    // firing because there is a layer on top of it
    if (e.timeStamp === previousEvent) {
      clearTimeout(eventTimeout);
    }
    eventTimeout = setTimeout(function() {
      self.trigger('mouseover', e, latlon, pxPos, data, layer);
      self.trigger('layermouseover', e, latlon, pxPos, data, layer);
    }, 0);
    previousEvent = e.timeStamp;
  };

  opts.featureOut  = function(m, layer) {
    if (hovers[layer]) {
      self.trigger('layermouseout', layer);
    }
    hovers[layer] = 0;
    if(!_.any(hovers)) {
      self.trigger('mouseout');
    }
    _featureOut  && _featureOut.apply(this, arguments);
    self.featureOut  && self.featureOut.apply(this, arguments);
  };

  opts.featureClick  = _.debounce(function() {
    _featureClick  && _featureClick.apply(this, arguments);
    self.featureClick  && self.featureClick.apply(opts, arguments);
  }, 10);


  GMapsLayerView.call(this, layerModel, this, gmapsMap);
  CartoDBLayerGroupGmaps.call(this, opts);
};

_.extend(
  GMapsCartoDBLayerGroupView.prototype,
  GMapsLayerView.prototype,
  CartoDBLayerGroupGmaps.prototype,
  {

  reload: function() {
    this.model.invalidate();
  },

  remove: function() {
    GMapsLayerView.prototype.remove.call(this);
    this.clear();
  },

  featureOver: function(e, latlon, pixelPos, data, layer) {
    // dont pass gmaps LatLng
    this.trigger('featureOver', e, [latlon.lat(), latlon.lng()], pixelPos, data, layer);
  },

  featureOut: function(e, layer) {
    this.trigger('featureOut', e, layer);
  },
{'fraction_non_alphanumeric': 0.14130434782608695, 'fraction_numerical': 0.0023715415019762848, 'mean_word_length': 3.6948051948051948, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7479619', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1665, 'n_words': 354}