<commit_before>/**
* map tab shown in cartodb admin
*/

cdb.admin.MapTab = cdb.core.View.extend({

  events: {
    'click .share a': 'shareMap'
  },

  className: 'map',
  animation_time: 300,

  initialize: function() {
    this.template = this.getTemplate('table/views/maptab');
    this.map = this.model;
    this.map_enabled = false;
    this.featureHovered = null;
    this.infowindowModel = this.options.infowindow;
    this.georeferenced = false;

    //this.add_related_model(this.options.dataLayer);
    this.add_related_model(this.map);
    this.add_related_model(this.options.table);
    this.add_related_model(this.infowindowModel);

    var self = this;

    cdb.god.bind("hidePanel", function(ev) {
      self._moveRightButtons("hide");
    });
    cdb.god.bind("showPanel", function(ev) {
      self._moveRightButtons("show");
    });
    cdb.god.bind("narrowPanel", function(ev) {
      self._moveRightButtons("narrow");
    });

    this.map.bind('change:provider', this.switchMapType, this);
    this.options.table.bind('change:privacy', this._setPrivacy, this);
    this.options.table.bind('change:dataSource', this._hideInfowindow, this);

    this.options.table.bind('data:saved', function() {
      this.updateDataLayerView();
    }, this)

    // menu entries

    this.newGeomDropdown = new cdb.admin.NewGeometryDropdown({
        position: 'position',
        template_base: "table/views/table_new_geom",
        tick: "bottom",
        horizontal_position: "right",
    });
    this.newGeomDropdown.render();

    var addGeom = this.options.menu.addToolButton('add_feature', ['map']);
    $('body').append(this.newGeomDropdown.el);

    this.newGeomDropdown.bind('newGeometry', function(geomType) {
      this.addGeometry(geomType);
    }, this);

    addGeom.bind('click', function(e) {
      if(this.options.table.isGeoreferenced()) {
        this.addGeometry();
      } else {
        var pos = addGeom.$el.offset()
        this.newGeomDropdown.openAt(pos.left - 165, pos.top - 77);
      }
    }, this);


    _.bindAll(this, 'showNoGeoRefWarning');
  },

  deactivated: function() {
    if(this.map_enabled) {
      this.clearMap();
    }
  },

  clearMap: function() {
    clearTimeout(this.autoSaveBoundsTimer);
    this.mapView.clean();
    this.baseLayerChooser.clean();
    this.zoom.clean();
    this.infowindow.clean();

    delete this.mapView;
    delete this.baseLayerChooser;
    delete this.zoom;
    delete this.infowindow;

    this.map_enabled = false;

    // place the map DOM object again
    this.render();
  },


  /**
   *  Hide the infowindow when a query is applied or cleared
   */
  _hideInfowindow: function() {
    if(this.infowindow) {
      this.infowindow.model.set('visibility', false);
    }
  },


  _setPrivacy: function() {
    if (this.options.table.get('privacy').toLowerCase() != "public") {
      this.$el.find('div.share a').addClass('disabled');
    } else {
      this.$el.find('div.share a').removeClass('disabled');
    }
  },


  /**
  * this function is used when the map library is changed. Each map library
  * works in different way and need to recreate all the components again
  */
  switchMapType: function() {
    if (this.map_enabled) {
      this.clearMap();
      this.render();
      this.enableMap();
    }
  },


  /**
  * map can't be loaded from the beggining, it needs the DOM to be loaded
  * so we wait until is actually shown to create the mapview and show it
  */
  enableMap: function() {

    this.$('.tipsy').remove();
    var self = this;
    if (!this.map_enabled) {
      var div = this.$('#map')
      , base_maps = this.$('.base_maps');

      // use zoom and center instead of bounds
      self.map.unset('view_bounds_sw', { silent: true });
      self.map.unset('view_bounds_ne', { silent: true });


      var mapViewClass = cdb.geo.LeafletMapView;
      if(this.map.get('provider') === 'googlemaps') {
        mapViewClass = cdb.geo.GoogleMapsMapView;
      }

      this.mapView = new mapViewClass({
        el: div,
        map: this.map
      });

      this.clickTimeout = null;
      this._bindMissingClickEvents();

      this.map_enabled = true;
<commit_msg>undo fixing problem with zoom #1513<commit_after>/**
* map tab shown in cartodb admin
*/

cdb.admin.MapTab = cdb.core.View.extend({

  events: {
    'click .share a': 'shareMap'
  },

  className: 'map',
  animation_time: 300,

  initialize: function() {
    this.template = this.getTemplate('table/views/maptab');
    this.map = this.model;
    this.map_enabled = false;
    this.featureHovered = null;
    this.infowindowModel = this.options.infowindow;
    this.georeferenced = false;

    //this.add_related_model(this.options.dataLayer);
    this.add_related_model(this.map);
    this.add_related_model(this.options.table);
    this.add_related_model(this.infowindowModel);

    var self = this;

    cdb.god.bind("hidePanel", function(ev) {
      self._moveRightButtons("hide");
    });
    cdb.god.bind("showPanel", function(ev) {
      self._moveRightButtons("show");
    });
    cdb.god.bind("narrowPanel", function(ev) {
      self._moveRightButtons("narrow");
    });

    this.map.bind('change:provider', this.switchMapType, this);
    this.options.table.bind('change:privacy', this._setPrivacy, this);
    this.options.table.bind('change:dataSource', this._hideInfowindow, this);

    this.options.table.bind('data:saved', function() {
      this.updateDataLayerView();
    }, this)

    // menu entries

    this.newGeomDropdown = new cdb.admin.NewGeometryDropdown({
        position: 'position',
        template_base: "table/views/table_new_geom",
        tick: "bottom",
        horizontal_position: "right",
    });
    this.newGeomDropdown.render();

    var addGeom = this.options.menu.addToolButton('add_feature', ['map']);
    $('body').append(this.newGeomDropdown.el);

    this.newGeomDropdown.bind('newGeometry', function(geomType) {
      this.addGeometry(geomType);
    }, this);

    addGeom.bind('click', function(e) {
      if(this.options.table.isGeoreferenced()) {
        this.addGeometry();
      } else {
        var pos = addGeom.$el.offset()
        this.newGeomDropdown.openAt(pos.left - 165, pos.top - 77);
      }
    }, this);


    _.bindAll(this, 'showNoGeoRefWarning');
  },

  deactivated: function() {
    if(this.map_enabled) {
      this.clearMap();
    }
  },

  clearMap: function() {
    clearTimeout(this.autoSaveBoundsTimer);
    this.mapView.clean();
    this.baseLayerChooser.clean();
    this.zoom.clean();
    this.infowindow.clean();

    delete this.mapView;
    delete this.baseLayerChooser;
    delete this.zoom;
    delete this.infowindow;

    this.map_enabled = false;

    // place the map DOM object again
    this.render();
  },


  /**
   *  Hide the infowindow when a query is applied or cleared
   */
  _hideInfowindow: function() {
    if(this.infowindow) {
      this.infowindow.model.set('visibility', false);
    }
  },


  _setPrivacy: function() {
    if (this.options.table.get('privacy').toLowerCase() != "public") {
      this.$el.find('div.share a').addClass('disabled');
    } else {
      this.$el.find('div.share a').removeClass('disabled');
    }
  },


  /**
  * this function is used when the map library is changed. Each map library
  * works in different way and need to recreate all the components again
  */
  switchMapType: function() {
    if (this.map_enabled) {
      this.clearMap();
      this.render();
      this.enableMap();
    }
  },


  /**
  * map can't be loaded from the beggining, it needs the DOM to be loaded
  * so we wait until is actually shown to create the mapview and show it
  */
  enableMap: function() {

    this.$('.tipsy').remove();
    var self = this;
    if (!this.map_enabled) {
      var div = this.$('#map')
      , base_maps = this.$('.base_maps');

      var mapViewClass = cdb.geo.LeafletMapView;
      if(this.map.get('provider') === 'googlemaps') {
        mapViewClass = cdb.geo.GoogleMapsMapView;
      }

      this.mapView = new mapViewClass({
        el: div,
        map: this.map
      });

      this.clickTimeout = null;
      this._bindMissingClickEvents();

      this.map_enabled = true;

{'fraction_non_alphanumeric': 0.1473491773308958, 'fraction_numerical': 0.002437538086532602, 'mean_word_length': 2.8634651600753296, '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': '246193', 'n_tokens_mistral': 2738, 'n_tokens_neox': 2641, 'n_words': 506}