<commit_before>Teikei.module("Places", function(Places, Teikei, Backbone, Marionette, $, _) {

  var DEFAULT_ZOOM = 10;
  var MIN_ZOOM = 6;
  var MAX_ZOOM = 12;

  Places.MapView = Marionette.ItemView.extend({

    element: "#map",

    markers: [],

    initialize: function(options) {
      this.defaultBounds = options.defaultBounds;
      this.collection.once("reset", this.initMap, this);
      this.collection.bind("change", this.updateMap, this);
      this.collection.bind("add", this.add, this);
    },

    showTip: function(id) {
      var marker = _.find(this.markers, function(item) {
        return Number(id) === item.model.id;
      });
      this.initTip(marker);
      marker.openPopup();
    },

    initTip: function(marker) {
      if (marker === undefined) {
        return;
      }
      var model = marker.model;
      var mapItemView = new Places.MapItemView({model: model});
      mapItemView.render();
      marker.bindPopup(mapItemView.el, {offset: L.point(0, -55)});

      this.listenTo(mapItemView, "select:details", function() {
        this.trigger("select:details", model.id, model.get("type"));
      }, this);

      this.listenTo(mapItemView, "select:network", function() {
        this.trigger("select:network", model.id, model.get("type"));
      }, this);
    },

    add: function(model) {
      this.updateMap();
      this.map.setView(this.getLatLng(model), DEFAULT_ZOOM);
      this.showTip(model.id);
    },

    updateMap: function(model) {
      this.markerLayer.clearLayers();
      this.markers = this.initMarkers(this.collection);
      this.markerLayer = this.initMarkerLayer(this.markers);
      this.map.addLayer(this.markerLayer);
    },

    hilightMarkers: function(places) {
      var bounds = [];
      _.each(this.markers, function(marker) {
        marker.setOpacity(0.3);
        _.each(places, function(place){
          if (place.id === marker.model.id) {
            marker.setOpacity(1);
            bounds.push(marker.getLatLng());
          }
        });
      });
      this.map.fitBounds(bounds);
    },

    drawNetwork: function(places) {
      var networkLayer = this.networkLayer;
      var farms = _.filter(places, function(item) {
        return item.type === "Farm";
      });
      var depots = _.filter(places, function(item) {
        return item.type === "Depot";
      });

      _.each(farms, function(farm) {
        _.each(depots, function(depot) {
          var latlngs = [
            new L.LatLng(farm.latitude, farm.longitude),
            new L.LatLng(depot.latitude, depot.longitude)
          ];
          var polyline = L.polyline(latlngs, {color: '#a00e46', weight: 2});
          polyline.addTo(networkLayer);
        });
      });
    },

    hilightNetwork: function(model) {
      var places = _.map(model.get("places"), function(item) {
        return item.place;
      });
      places.push(model.attributes);
      this.drawNetwork(places);
      this.hilightMarkers(places);
    },

    unHilightNetwork: function() {
      _.each(this.markers, function(marker) {
        _.defer(function(){
          marker.setOpacity(1);
        });
      });
      this.networkLayer.clearLayers();
      Backbone.history.navigate('/');
    },

    showArea: function(bounds) {
      this.map.fitBounds(bounds);
    },

    initMap: function() {
      this.markers = this.initMarkers(this.collection);
      this.tileLayer = this.initTileLayer();
      this.networkLayer = L.layerGroup();
      this.markerLayer = this.initMarkerLayer(this.markers);
      this.map = L.map("map", {
        attributionControl: false,
        maxZoom: MAX_ZOOM,
        minZoom: MIN_ZOOM
      });
      this.map.fitBounds(this.defaultBounds);
      this.map.addLayer(this.tileLayer);
      this.map.addLayer(this.networkLayer);
      this.map.addLayer(this.markerLayer);
      this.map.addControl(this.initFooter());
      this.map.on("popupclose", _.bind(this.unHilightNetwork, this));
    },<commit_msg>Map: Auto-offset to prevent the header from overlaying map content.<commit_after>Teikei.module("Places", function(Places, Teikei, Backbone, Marionette, $, _) {

  var DEFAULT_ZOOM = 10;
  var MIN_ZOOM = 6;
  var MAX_ZOOM = 12;
  var PADDING = L.point(0, 120); // offset for header bar

  Places.MapView = Marionette.ItemView.extend({

    element: "#map",

    markers: [],

    initialize: function(options) {
      this.defaultBounds = options.defaultBounds;
      this.collection.once("reset", this.initMap, this);
      this.collection.bind("change", this.updateMap, this);
      this.collection.bind("add", this.add, this);
    },

    showTip: function(id) {
      var marker = _.find(this.markers, function(item) {
        return Number(id) === item.model.id;
      });
      this.initTip(marker);
      marker.openPopup();
    },

    initTip: function(marker) {
      if (marker === undefined) {
        return;
      }
      var model = marker.model;
      var mapItemView = new Places.MapItemView({model: model});
      mapItemView.render();
      marker.bindPopup(mapItemView.el, {
        offset: L.point(0, -55),
        autoPanPaddingTopLeft: PADDING
      });

      this.listenTo(mapItemView, "select:details", function() {
        this.trigger("select:details", model.id, model.get("type"));
      }, this);

      this.listenTo(mapItemView, "select:network", function() {
        this.trigger("select:network", model.id, model.get("type"));
      }, this);
    },

    add: function(model) {
      this.updateMap();
      this.map.setView(this.getLatLng(model), DEFAULT_ZOOM);
      this.showTip(model.id);
    },

    updateMap: function(model) {
      this.markerLayer.clearLayers();
      this.markers = this.initMarkers(this.collection);
      this.markerLayer = this.initMarkerLayer(this.markers);
      this.map.addLayer(this.markerLayer);
    },

    hilightMarkers: function(places) {
      var bounds = [];
      _.each(this.markers, function(marker) {
        marker.setOpacity(0.3);
        _.each(places, function(place){
          if (place.id === marker.model.id) {
            marker.setOpacity(1);
            bounds.push(marker.getLatLng());
          }
        });
      });
      this.map.fitBounds(bounds, {paddingTopLeft: PADDING});
    },

    drawNetwork: function(places) {
      var networkLayer = this.networkLayer;
      var farms = _.filter(places, function(item) {
        return item.type === "Farm";
      });
      var depots = _.filter(places, function(item) {
        return item.type === "Depot";
      });

      _.each(farms, function(farm) {
        _.each(depots, function(depot) {
          var latlngs = [
            new L.LatLng(farm.latitude, farm.longitude),
            new L.LatLng(depot.latitude, depot.longitude)
          ];
          var polyline = L.polyline(latlngs, {color: '#a00e46', weight: 2});
          polyline.addTo(networkLayer);
        });
      });
    },

    hilightNetwork: function(model) {
      var places = _.map(model.get("places"), function(item) {
        return item.place;
      });
      places.push(model.attributes);
      this.drawNetwork(places);
      this.hilightMarkers(places);
    },

    unHilightNetwork: function() {
      _.each(this.markers, function(marker) {
        _.defer(function(){
          marker.setOpacity(1);
        });
      });
      this.networkLayer.clearLayers();
      Backbone.history.navigate('/');
    },

    showArea: function(bounds) {
      this.map.fitBounds(bounds, {paddingTopLeft: PADDING});
    },

    initMap: function() {
      this.markers = this.initMarkers(this.collection);
      this.tileLayer = this.initTileLayer();
      this.networkLayer = L.layerGroup();
      this.markerLayer = this.initMarkerLayer(this.markers);
      this.map = L.map("map", {
        attributionControl: false,
        maxZoom: MAX_ZOOM,
        minZoom: MIN_ZOOM
      });
      this.map.fitBounds(this.defaultBounds, {paddingTopLeft: PADDING});
      this.map.addLayer(this.tileLayer);
      this.map.addLayer(this.networkLayer);
      this.map.addLayer(this.markerLayer);
      this.map.addControl(this.initFooter());
      this.map.on("popupclose", _.bind(this.unHilightNetwork, this));
    },
{'fraction_non_alphanumeric': 0.150384193194292, 'fraction_numerical': 0.004634711550189048, 'mean_word_length': 2.5390591281829953, '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': '817464', 'n_tokens_mistral': 2666, 'n_tokens_neox': 2563, 'n_words': 409}