<commit_before>/**
 * The MapView class for the Google Map.
 *
 * @return MapView class (extends Backbone.View)
 */

define([
  'backbone',
  'underscore',
  'mps',
  'cookie',
  'map/presenters/MapPresenter',
  'map/views/maptypes/grayscaleMaptype',
  'map/views/maptypes/treeheightMaptype',
  'map/views/maptypes/darkMaptype',
  'map/views/maptypes/positronMaptype',
  'map/views/maptypes/landsatMaptype',
  'map/helpers/layersHelper'
], function(Backbone, _, mps, Cookies, Presenter, grayscaleMaptype, treeheightMaptype, darkMaptype, positronMaptype, landsatMaptype, layersHelper) {

  'use strict';

  var MapView = Backbone.View.extend({

    el: '#map',

    /**
     * Google Map Options.
     */
    options: {
      minZoom: 3,
      backgroundColor: '#99b3cc',
      disableDefaultUI: true,
      panControl: false,
      zoomControl: false,
      mapTypeControl: false,
      scaleControl: true,
      streetViewControl: false,
      overviewMapControl: false
    },

    /**
     * Constructs a new MapView and its presenter.
     */
    initialize: function() {
      this.presenter = new Presenter(this);
      this.layerInst = {};
      this.$maplngLng = $('.map-container .map-latlng');
      this.$viewFinder = $('#viewfinder');
      this.$overlayMobile = $('#overlay-mobile');
      this.embed = $('body').hasClass('is-embed-action');
      this.lastValidCenter = null;
      this.allowedBounds = null;

      enquire.register("screen and (min-width:"+window.gfw.config.GFW_MOBILE+"px)", {
        match: _.bind(function(){
          this.mobile = false;
          this.render(3);
          this.presenter._resizeSetLayers();
        },this)
      });
      enquire.register("screen and (max-width:"+window.gfw.config.GFW_MOBILE+"px)", {
        match: _.bind(function(){
          this.mobile = true;
          this.render(2);
          this.presenter._resizeSetLayers();
        },this)
      });


    },

    /**
     * Creates the Google Maps and attaches it to the DOM.
     */
    render: function(zoom) {
      var params = {
        zoom: zoom,
        minZoom: zoom,
        mapTypeId: 'grayscale',
        center: new google.maps.LatLng(15, 27),
      };

      this.map = new google.maps.Map(this.el, _.extend({}, this.options, params));
      this.allowedBounds = new google.maps.LatLngBounds(
         new google.maps.LatLng(-85, -180),
         new google.maps.LatLng(85, 180)
      ); // why (-85, -180)? Well, because f*ck you, Google: http://stackoverflow.com/questions/5405539/google-maps-v3-why-is-latlngbounds-contains-returning-false
      this.lastValidCenter = this.map.getCenter();

      this._checkDialogs();

      this.resize();
      this._setMaptypes();
      this._addListeners();
      // Node
      this.createMaptypeNode();

    },

    /**
     * Wires up Google Maps API listeners so that the view can respond to user
     * events fired by the UI.
     */
    _addListeners: function() {
      google.maps.event.addListener(this.map, 'zoom_changed',
        _.bind(function() {
          this.onCenterChange();
        }, this)
      );
      google.maps.event.addListener(this.map, 'bounds_changed', _.bind(function() {
        if(!this.center_moved && this.mobile){
          this.offsetCenter(this.map.getCenter(), 0, 270/2);
          this.center_moved = true;
        }
      }, this ));
      google.maps.event.addListener(this.map, 'dragend',
        _.bind(function() {
          this.onCenterChange();
      }, this));

      google.maps.event.addListenerOnce(this.map, 'idle', _.bind(function() {
        this.$el.addClass('is-loaded');
      }, this));

      google.maps.event.addListener(this.map, 'click', _.bind(function(wdpa) {
        if (!!wdpa && !!wdpa.wdpaid) {
          // TODO => No mps here!
          mps.publish('AnalysisTool/analyze-wdpaid', [wdpa]);
        }
      }, this));

      google.maps.event.addListener(this.map, 'maptypeid_changed', _.bind(function() {
        this.setCredit('Map tiles by <a href="http://cartodb.com/attributions#basemaps">CartoDB</a>, under <a href="https://creativecommons.org/licenses/by/3.0/">CC BY 3.0</a>. Data by <a href="http://www.openstreetmap.org/">OpenStreetMap</a>, under ODbL.');<commit_msg>Embed: center map without substract the analysis module height<commit_after>/**
 * The MapView class for the Google Map.
 *
 * @return MapView class (extends Backbone.View)
 */

define([
  'backbone',
  'underscore',
  'mps',
  'cookie',
  'map/presenters/MapPresenter',
  'map/views/maptypes/grayscaleMaptype',
  'map/views/maptypes/treeheightMaptype',
  'map/views/maptypes/darkMaptype',
  'map/views/maptypes/positronMaptype',
  'map/views/maptypes/landsatMaptype',
  'map/helpers/layersHelper'
], function(Backbone, _, mps, Cookies, Presenter, grayscaleMaptype, treeheightMaptype, darkMaptype, positronMaptype, landsatMaptype, layersHelper) {

  'use strict';

  var MapView = Backbone.View.extend({

    el: '#map',

    /**
     * Google Map Options.
     */
    options: {
      minZoom: 3,
      backgroundColor: '#99b3cc',
      disableDefaultUI: true,
      panControl: false,
      zoomControl: false,
      mapTypeControl: false,
      scaleControl: true,
      streetViewControl: false,
      overviewMapControl: false
    },

    /**
     * Constructs a new MapView and its presenter.
     */
    initialize: function() {
      this.presenter = new Presenter(this);
      this.layerInst = {};
      this.$maplngLng = $('.map-container .map-latlng');
      this.$viewFinder = $('#viewfinder');
      this.$overlayMobile = $('#overlay-mobile');
      this.embed = $('body').hasClass('is-embed-action');
      this.lastValidCenter = null;
      this.allowedBounds = null;

      enquire.register("screen and (min-width:"+window.gfw.config.GFW_MOBILE+"px)", {
        match: _.bind(function(){
          this.mobile = false;
          this.render(3);
          this.presenter._resizeSetLayers();
        },this)
      });
      enquire.register("screen and (max-width:"+window.gfw.config.GFW_MOBILE+"px)", {
        match: _.bind(function(){
          this.mobile = true;
          this.render(2);
          this.presenter._resizeSetLayers();
        },this)
      });


    },

    /**
     * Creates the Google Maps and attaches it to the DOM.
     */
    render: function(zoom) {
      var params = {
        zoom: zoom,
        minZoom: zoom,
        mapTypeId: 'grayscale',
        center: new google.maps.LatLng(15, 27),
      };

      this.map = new google.maps.Map(this.el, _.extend({}, this.options, params));
      this.allowedBounds = new google.maps.LatLngBounds(
         new google.maps.LatLng(-85, -180),
         new google.maps.LatLng(85, 180)
      ); // why (-85, -180)? Well, because f*ck you, Google: http://stackoverflow.com/questions/5405539/google-maps-v3-why-is-latlngbounds-contains-returning-false
      this.lastValidCenter = this.map.getCenter();

      this._checkDialogs();

      this.resize();
      this._setMaptypes();
      this._addListeners();
      // Node
      this.createMaptypeNode();

    },

    /**
     * Wires up Google Maps API listeners so that the view can respond to user
     * events fired by the UI.
     */
    _addListeners: function() {
      google.maps.event.addListener(this.map, 'zoom_changed',
        _.bind(function() {
          this.onCenterChange();
        }, this)
      );
      google.maps.event.addListener(this.map, 'bounds_changed', _.bind(function() {
        // This function will center the map when it's a small screen in the center - analysis module height
        // 270 is magic number... We should get rid of it
        if(!this.center_moved && !this.embed && this.mobile){
          this.offsetCenter(this.map.getCenter(), 0, 270/2);
          this.center_moved = true;
        }
      }, this ));
      google.maps.event.addListener(this.map, 'dragend',
        _.bind(function() {
          this.onCenterChange();
      }, this));

      google.maps.event.addListenerOnce(this.map, 'idle', _.bind(function() {
        this.$el.addClass('is-loaded');
      }, this));

      google.maps.event.addListener(this.map, 'click', _.bind(function(wdpa) {
        if (!!wdpa && !!wdpa.wdpaid) {
          // TODO => No mps here!
          mps.publish('AnalysisTool/analyze-wdpaid', [wdpa]);
        }
      }, this));

      google.maps.event.addListener(this.map, 'maptypeid_changed', _.bind(function() {
        this.setCredit('Map tiles by <a href="http://cartodb.com/attributions#basemaps">CartoDB</a>, under <a href="https://creativecommons.org/licenses/by/3.0/">CC BY 3.0</a>. Data by <a href="http://www.openstreetmap.org/">OpenStreetMap</a>, under ODbL.');
{'fraction_non_alphanumeric': 0.15311887466851148, 'fraction_numerical': 0.010031131096506399, 'mean_word_length': 2.557834290401969, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4218496', 'n_tokens_mistral': 2845, 'n_tokens_neox': 2771, 'n_words': 525}