<commit_before>/**
 * The Sentinel layer module for use on canvas.
 *
 * @return SentinelLayer class (extends CartoDBLayerClass)
 */
define([
  'abstract/layer/ImageLayerClass',
  'uri',
  'moment',
  'map/views/layers/CustomInfowindow',

], function(ImageLayerClass, UriTemplate, moment, CustomInfowindow) {

  'use strict';

  var SENTINEL_URL = 'http://services.sentinel-hub.com/v1/{provider}/9f85dfae-bf90-4638-81d3-dc9925dd5b26/';
  var LANDSAT_URL = 'http://services-uswest2.sentinel-hub.com/v1/{provider}/0e8c6cde-ff77-4e38-aba8-33b171896972/';
  var TILE_SIZE = 256;
  var MAX_ZOOM = 9;

  var TILES_PARAMS = '?SERVICE=WMS&REQUEST=GetMap&LAYERS=TRUE_COLOR&BBOX={bbox}&MAXCC={cloud}&CLOUDCORRECTION=none&WIDTH=512&HEIGHT=512&FORMAT=image/png&TIME={mindate}/{maxdate}&CRS=CRS:84&TRANSPARENT=TRUE';

  var METADATA_PARAMS = '?service=WFS&version=2.0.0&request=GetFeature&time={mindate}/{maxdate}&typenames=TILE&maxfeatures=1&srsname=CRS:84&LAYERS=TRUE_COLOR&MAXCC={cloud}&CLOUDCORRECTION=none&&bbox={bbox}&outputformat=application/json';

  var SentinelLayer = ImageLayerClass.extend({
    options: {
      dataMaxZoom: {
        'rgb': 14,
        'ndvi': 13,
        'evi': 13,
        'ndwi': 13,
        'false-color-nir' : 13
      },
      infowindowImagelayer: true
    },

    init: function(layer, options, map) {
      this._super(layer, options, map);
      this.addEvents();
    },

    _getParams: function() {
      var params = {};
      if (window.location.search.contains('hresolution=') && window.location.search.indexOf('=', window.location.search.indexOf('hresolution=') + 11) !== -1) {
        var params_new_url = {};
        var parts = location.search.substring(1).split('&');
        for (var i = 0; i < parts.length; i++) {
          var nv = parts[i].split('=');
          if (!nv[0]) continue;
            params_new_url[nv[0]] = nv[1] || true;
        }
        params = JSON.parse(atob(params_new_url.hresolution));
      }
      else if (!!sessionStorage.getItem('high-resolution')) {
        params = JSON.parse(atob(sessionStorage.getItem('high-resolution')));
      }

      return {
        'color_filter': params.color_filter || 'rgb',
        'cloud':        params.cloud        || '100',
        'mindate':      params.mindate      || '2000-09-01',
        'maxdate':      params.maxdate      || '2015-09-01',
        'sensor_platform' : params.sensor_platform || 'landsat-8'
      }
    },

    calcBboxFromXY: function(x, y, z) {
      var proj = this.map.getProjection();
      var tileSize = TILE_SIZE / Math.pow(2,z);
      var tileBounds = new google.maps.LatLngBounds(
        proj.fromPointToLatLng(new google.maps.Point(x*tileSize, (y+1)*tileSize)),
        proj.fromPointToLatLng(new google.maps.Point((x+1)*tileSize, y*tileSize))
      );
      var parsedB = tileBounds.toJSON();
      return [parsedB.west, parsedB.north, parsedB.east, parsedB.south].join(',');
    },


    _getUrlTemplateBySensor: function(sensor) {
      this.sensor = sensor;
      return sensor === 'sentinel-2' ? SENTINEL_URL
        : LANDSAT_URL;
    },

    _getUrl: function(x, y, z, params) {
      var urlTemplate = this._getUrlTemplateBySensor(params.sensor_platform) + TILES_PARAMS;
      var urlParams = {
        sat: params.color_filter,
        cloud: params.cloud,
        mindate: params.mindate,
        maxdate: params.maxdate,
        bbox: this.calcBboxFromXY(x, y, z),
        provider: 'wms'
      }
      return new UriTemplate(urlTemplate).fillFromObject(urlParams);
    },<commit_msg>Feat: Sentinel - fix dates<commit_after>/**
 * The Sentinel layer module for use on canvas.
 *
 * @return SentinelLayer class (extends CartoDBLayerClass)
 */
define([
  'abstract/layer/ImageLayerClass',
  'uri',
  'moment',
  'map/views/layers/CustomInfowindow',

], function(ImageLayerClass, UriTemplate, moment, CustomInfowindow) {

  'use strict';

  var SENTINEL_URL = 'http://services.sentinel-hub.com/v1/{provider}/9f85dfae-bf90-4638-81d3-dc9925dd5b26/';
  var LANDSAT_URL = 'http://services-uswest2.sentinel-hub.com/v1/{provider}/0e8c6cde-ff77-4e38-aba8-33b171896972/';
  var TILE_SIZE = 256;
  var MAX_ZOOM = 9;

  var TILES_PARAMS = '?SERVICE=WMS&REQUEST=GetMap&LAYERS=TRUE_COLOR&BBOX={bbox}&MAXCC={cloud}&CLOUDCORRECTION=none&WIDTH=512&HEIGHT=512&FORMAT=image/png&TIME={mindate}/{maxdate}&CRS=CRS:84&TRANSPARENT=TRUE&PRIORITY=mostRecent';

  var METADATA_PARAMS = '?service=WFS&version=2.0.0&request=GetFeature&time={mindate}/{maxdate}&typenames=TILE&maxfeatures=1&srsname=CRS:84&LAYERS=TRUE_COLOR&MAXCC={cloud}&CLOUDCORRECTION=none&&bbox={bbox}&PRIORITY=mostRecent&outputformat=application/json';

  var SentinelLayer = ImageLayerClass.extend({
    options: {
      dataMaxZoom: {
        'rgb': 14,
        'ndvi': 13,
        'evi': 13,
        'ndwi': 13,
        'false-color-nir' : 13
      },
      infowindowImagelayer: true
    },

    init: function(layer, options, map) {
      this._super(layer, options, map);
      this.addEvents();
    },

    _getParams: function() {
      var params = {};
      if (window.location.search.contains('hresolution=') && window.location.search.indexOf('=', window.location.search.indexOf('hresolution=') + 11) !== -1) {
        var params_new_url = {};
        var parts = location.search.substring(1).split('&');
        for (var i = 0; i < parts.length; i++) {
          var nv = parts[i].split('=');
          if (!nv[0]) continue;
            params_new_url[nv[0]] = nv[1] || true;
        }
        params = JSON.parse(atob(params_new_url.hresolution));
      }
      else if (!!sessionStorage.getItem('high-resolution')) {
        params = JSON.parse(atob(sessionStorage.getItem('high-resolution')));
      }

      return {
        'color_filter': params.color_filter || 'rgb',
        'cloud':        params.cloud        || '100',
        'mindate':      params.mindate      || '2000-09-01',
        'maxdate':      params.maxdate      || '2015-09-01',
        'sensor_platform' : params.sensor_platform || 'landsat-8'
      }
    },

    calcBboxFromXY: function(x, y, z) {
      var proj = this.map.getProjection();
      var tileSize = TILE_SIZE / Math.pow(2,z);
      var tileBounds = new google.maps.LatLngBounds(
        proj.fromPointToLatLng(new google.maps.Point(x*tileSize, (y+1)*tileSize)),
        proj.fromPointToLatLng(new google.maps.Point((x+1)*tileSize, y*tileSize))
      );
      var parsedB = tileBounds.toJSON();
      return [parsedB.west, parsedB.north, parsedB.east, parsedB.south].join(',');
    },


    _getUrlTemplateBySensor: function(sensor) {
      this.sensor = sensor;
      return sensor === 'sentinel-2' ? SENTINEL_URL
        : LANDSAT_URL;
    },

    _getUrl: function(x, y, z, params) {
      var urlTemplate = this._getUrlTemplateBySensor(params.sensor_platform) + TILES_PARAMS;
      var urlParams = {
        sat: params.color_filter,
        cloud: params.cloud,
        mindate: params.mindate,
        maxdate: params.maxdate,
        bbox: this.calcBboxFromXY(x, y, z),
        provider: 'wms'
      };

      return new UriTemplate(urlTemplate).fillFromObject(urlParams);
    },
{'fraction_non_alphanumeric': 0.1542456140350877, 'fraction_numerical': 0.02863157894736842, 'mean_word_length': 3.1072046109510087, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4040294', 'n_tokens_mistral': 2626, 'n_tokens_neox': 2473, 'n_words': 379}