<commit_before>require('leaflet.label');
var Handlebars = require('handlebars');

var log = require('./log')('map-views');
var utils = require('./utils');

/** Map Views **/

var legFromBubbleTemplate = Handlebars.compile(require('./leg-from-bubble.html'));
var mapContextMenuTemplate = Handlebars.compile(require('./map-context-menu.html'));

module.exports.ItineraryMapView = Backbone.View.extend({

  initialize: function(options) {
    var self = this;

    this.options = options || {};

    this.attachedToMap = false;
    this.pathLayer = new L.LayerGroup();
    this.pathMarkerLayer = new L.LayerGroup();
    this.highlightLayer = new L.LayerGroup();

    this.listenTo(this.model, 'activate', function() {
      self.preview = false;
      self.render();
    });

    this.listenTo(this.model, 'mouseenter', function() {
      self.preview = true;
      self.render();
    });

    this.listenTo(this.model, 'deactivate', function() {
      self.clearLayers();
    });

    this.model.get('legs').each(function(leg) {
      self.initializeLeg(leg);
    });
  },

  initializeLeg: function(leg) {
    var self = this;

    this.listenTo(leg, 'mouseenter', function() {
      self.highlightLeg = leg;
      self.render();
    });

    this.listenTo(leg, 'mouseleave', function() {
      self.highlightLeg = null;
      self.render();
    });

    this.listenTo(leg, 'fromclick', function() {
      var from = leg.get('from');
      self.view.options.map.panTo([from.lat, from.lon]);
    });

    this.listenTo(leg, 'toclick', function() {
      var to = leg.get('to');
      self.view.options.map.panTo([to.lat, to.lon]);
    });

    var steps = leg.get('steps');
    if (!steps || !steps.length) return;

    steps.forEach(function(step) {
      self.initializeStep(step);
    });
  },

  initializeStep: function(step) {
    var self = this;
    this.listenTo(step, 'click', function() {
      self.view.options.map.panTo([step.get('lat'), step.get('lon')]);
    });

    this.listenTo(step, 'mouseleave', function() {
      self.view.options.map.closePopup();
    });
  },

  attachToMap: function() {
    this.options.map.addLayer(this.highlightLayer);
    this.options.map.addLayer(this.pathLayer);
    this.options.map.addLayer(this.pathMarkerLayer);
    this.attachedToMap = true;
  },

  detachFromMap: function() {
    this.options.map.removeLayer(this.highlightLayer);
    this.options.map.removeLayer(this.pathLayer);
    this.options.map.removeLayer(this.pathMarkerLayer);
    this.attachedToMap = false;
  },

  render: function() {
    if (!this.attachedToMap) this.attachToMap();
    this.clearLayers();

    this.mapBounds = new L.LatLngBounds();<commit_msg>Fix references to options in listeners<commit_after>require('leaflet.label');
var Handlebars = require('handlebars');

var log = require('./log')('map-views');
var utils = require('./utils');

/** Map Views **/

var legFromBubbleTemplate = Handlebars.compile(require('./leg-from-bubble.html'));
var mapContextMenuTemplate = Handlebars.compile(require('./map-context-menu.html'));

module.exports.ItineraryMapView = Backbone.View.extend({

  initialize: function(options) {
    var self = this;

    this.options = options || {};

    this.attachedToMap = false;
    this.pathLayer = new L.LayerGroup();
    this.pathMarkerLayer = new L.LayerGroup();
    this.highlightLayer = new L.LayerGroup();

    this.listenTo(this.model, 'activate', function() {
      self.preview = false;
      self.render();
    });

    this.listenTo(this.model, 'mouseenter', function() {
      self.preview = true;
      self.render();
    });

    this.listenTo(this.model, 'deactivate', function() {
      self.clearLayers();
    });

    this.model.get('legs').each(function(leg) {
      self.initializeLeg(leg);
    });
  },

  initializeLeg: function(leg) {
    var self = this;

    this.listenTo(leg, 'mouseenter', function() {
      self.highlightLeg = leg;
      self.render();
    });

    this.listenTo(leg, 'mouseleave', function() {
      self.highlightLeg = null;
      self.render();
    });

    this.listenTo(leg, 'fromclick', function() {
      var from = leg.get('from');
      self.options.map.panTo([from.lat, from.lon]);
    });

    this.listenTo(leg, 'toclick', function() {
      var to = leg.get('to');
      self.options.map.panTo([to.lat, to.lon]);
    });

    var steps = leg.get('steps');
    if (!steps || !steps.length) return;

    steps.forEach(function(step) {
      self.initializeStep(step);
    });
  },

  initializeStep: function(step) {
    var self = this;
    this.listenTo(step, 'click', function() {
      self.options.map.panTo([step.get('lat'), step.get('lon')]);
    });

    this.listenTo(step, 'mouseleave', function() {
      self.options.map.closePopup();
    });
  },

  attachToMap: function() {
    this.options.map.addLayer(this.highlightLayer);
    this.options.map.addLayer(this.pathLayer);
    this.options.map.addLayer(this.pathMarkerLayer);
    this.attachedToMap = true;
  },

  detachFromMap: function() {
    this.options.map.removeLayer(this.highlightLayer);
    this.options.map.removeLayer(this.pathLayer);
    this.options.map.removeLayer(this.pathMarkerLayer);
    this.attachedToMap = false;
  },

  render: function() {
    if (!this.attachedToMap) this.attachToMap();
    this.clearLayers();

    this.mapBounds = new L.LatLngBounds();
{'fraction_non_alphanumeric': 0.17209908735332463, 'fraction_numerical': 0.0, 'mean_word_length': 3.241706161137441, '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': '757848', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1705, 'n_words': 274}