<commit_before>if (typeof Number.prototype.toRadians == 'undefined') {
    Number.prototype.toRadians = function() {
        return this * Math.PI / 180;
    }
}

window.markerData = [];
window.Markers = {};

$(function() {

  self = this;

  map = document.getElementById('map-contours');
  this.mapBBox = map.getBoundingClientRect();

  this.mapLatLngBBox = [
    {lat: 60.9518, lng: -14.8535},
    {lat: 35.1379, lng: 42.4512}
  ];

  this.markerPrototype = $('#marker-prototype');
  this.markerSize = {
    w: this.markerPrototype.children('img').width(),
    h: this.markerPrototype.children('img').height()
  }

  this.markerLayer = $('#marker-layer');
  this.markers = [];

  this.update = function() {
    self.clearAllMarkers();

    markerData.forEach(function(obj) {
      if ($('#minbeds').val() == obj.year) {
        self.placeMarker(self.latLngToXY(obj.latitude, obj.longitude));
      }
    })
 };

	
  this.placeMarker = function(pos) {
    var marker = self.markerPrototype.clone(),
        w = self.markerSize.w,
        h = self.markerSize.h;
    marker.removeAttr("id");

    self.markers.push(marker);
    self.markerLayer.append(marker);

    //x = self.mapBBox.left + pos.x - w / 2;
    //y = self.mapBBox.top + pos.y - h;
    dx = self.mapBBox.left - w/2;
    dy = self.mapBBox.top - h*2;
    x = pos.x + dx;
    y = pos.y + dy;

    marker.offset({ top: y, left: x });
    console.log(pos, marker.offset());
  };

  this.clearAllMarkers = function() {
    self.markers.length = 0;
    self.markerLayer.empty();
  };

  this.latLngToXY = function(lat, lng) {
    var dy, dx, verticalFactor, pos;

    xKmPerPx = self.mapWidthAtLat(lat) / self.mapBBox.width;
    yKmPerPx = self.mapHeightAtLng(lng) / self.mapBBox.width;

    dy = self.sphericalDistance(
      {lat: self.mapLatLngBBox[0].lat, lng: lng},
      {lat: lat, lng: lng}
    );
    dx = self.sphericalDistance(
      {lat: lat, lng: self.mapLatLngBBox[0].lng},
      {lat: lat, lng: lng}
    );

    pos = {
      x: dx / xKmPerPx,
      y: dy / yKmPerPx
    };

    return pos;
  };

  this.sphericalDistance = function(from, to) {
    var φ1 = from.lat.toRadians(),
        φ2 = to.lat.toRadians(),
        Δλ = (to.lng - from.lng).toRadians(),
        R = 6378.137; // gives d in km

    return Math.acos( Math.sin(φ1)*Math.sin(φ2) + Math.cos(φ1)*Math.cos(φ2) * Math.cos(Δλ) ) * R;
  };

  this.mapWidthAtLat = function(lat) {
    return self.sphericalDistance(
      {lat: lat, lng: self.mapLatLngBBox[0].lng},
      {lat: lat, lng: self.mapLatLngBBox[1].lng}
    );
  };

  this.mapHeightAtLng = function(lng) {
    return self.sphericalDistance(
      {lat: self.mapLatLngBBox[0].lat, lng: lng},
      {lat: self.mapLatLngBBox[1].lat, lng: lng}
    );
  };

  //$(window).resize(this.resize);
  this.update();
  window.Markers.update = this.update;
});


/* jquery slider */

$(function() {
  var select = $( "#minbeds" );
  var slider = $( "<div id='slider'></div>" ).insertAfter( select ).slider({
    min: 1,
    max: 6,
    range: "min",
    value: select[ 0 ].selectedIndex + 1,
    slide: function( event, ui ) {
      select[ 0 ].selectedIndex = ui.value - 1;
      updateYear();
    }
  });
  $( "#minbeds" ).change(function() {
    slider.slider( "value", this.selectedIndex + 1 );

    updateYear();
  });

  function updateYear() {
    console.log($( "#minbeds" ).val());
    Markers.update();
  }<commit_msg>update marker positions on resize<commit_after>if (typeof Number.prototype.toRadians == 'undefined') {
    Number.prototype.toRadians = function() {
        return this * Math.PI / 180;
    }
}

window.markerData = [];
window.Markers = {};

$(function() {

  self = this;

  map = document.getElementById('map-contours');
  this.mapBBox = map.getBoundingClientRect();

  this.mapLatLngBBox = [
    {lat: 60.9518, lng: -14.8535},
    {lat: 35.1379, lng: 42.4512}
  ];

  this.markerPrototype = $('#marker-prototype');
  this.markerSize = {
    w: this.markerPrototype.children('img').width(),
    h: this.markerPrototype.children('img').height()
  }

  this.markerLayer = $('#marker-layer');
  this.markers = [];

  this.update = function() {
    self.clearAllMarkers();

    markerData.forEach(function(obj) {
      if ($('#minbeds').val() == obj.year) {
        self.placeMarker({lat: obj.latitude, lng: obj.longitude});
      }
    })
  };

  this.onResize = function() {
    self.mapBBox = map.getBoundingClientRect();
    self.markers.forEach(self.setMarkerPosition);
  };

  this.setMarkerPosition = function(marker) {
    var dx, dy, w, h, x, y, pos;

    pos = self.latLngToXY(marker.data("latitude"), marker.data("longitude"));
    w = self.markerSize.w,
    h = self.markerSize.h;
    dx = self.mapBBox.left - w/2;
    dy = self.mapBBox.top - h*2;
    x = pos.x + dx;
    y = pos.y + dy;

    marker.offset({ top: y, left: x });
  };

  this.placeMarker = function(coords) {
    var marker = self.markerPrototype.clone();
    marker.removeAttr("id");
    marker.attr("data-latitude", coords.lat);
    marker.attr("data-longitude", coords.lng);

    self.markers.push(marker);
    self.markerLayer.append(marker);
    self.setMarkerPosition(marker);
  };

  this.clearAllMarkers = function() {
    self.markers.length = 0;
    self.markerLayer.empty();
  };

  this.latLngToXY = function(lat, lng) {
    var dy, dx, verticalFactor, pos;

    xKmPerPx = self.mapWidthAtLat(lat) / self.mapBBox.width;
    yKmPerPx = self.mapHeightAtLng(lng) / self.mapBBox.width;

    dy = self.sphericalDistance(
      {lat: self.mapLatLngBBox[0].lat, lng: lng},
      {lat: lat, lng: lng}
    );
    dx = self.sphericalDistance(
      {lat: lat, lng: self.mapLatLngBBox[0].lng},
      {lat: lat, lng: lng}
    );

    pos = {
      x: dx / xKmPerPx,
      y: dy / yKmPerPx
    };

    return pos;
  };

  this.sphericalDistance = function(from, to) {
    var φ1 = from.lat.toRadians(),
        φ2 = to.lat.toRadians(),
        Δλ = (to.lng - from.lng).toRadians(),
        R = 6378.137; // gives d in km

    return Math.acos( Math.sin(φ1)*Math.sin(φ2) + Math.cos(φ1)*Math.cos(φ2) * Math.cos(Δλ) ) * R;
  };

  this.mapWidthAtLat = function(lat) {
    return self.sphericalDistance(
      {lat: lat, lng: self.mapLatLngBBox[0].lng},
      {lat: lat, lng: self.mapLatLngBBox[1].lng}
    );
  };

  this.mapHeightAtLng = function(lng) {
    return self.sphericalDistance(
      {lat: self.mapLatLngBBox[0].lat, lng: lng},
      {lat: self.mapLatLngBBox[1].lat, lng: lng}
    );
  };

  $(window).resize(this.onResize);
  this.update();
  window.Markers.update = this.update;
});


/* jquery slider */

$(function() {
  var select = $( "#minbeds" );
  var slider = $( "<div id='slider'></div>" ).insertAfter( select ).slider({
    min: 1,
    max: 6,
    range: "min",
    value: select[ 0 ].selectedIndex + 1,
    slide: function( event, ui ) {
      select[ 0 ].selectedIndex = ui.value - 1;
      updateYear();
    }
  });
  $( "#minbeds" ).change(function() {
    slider.slider( "value", this.selectedIndex + 1 );

    updateYear();
  });

  function updateYear() {
    console.log($( "#minbeds" ).val());
    Markers.update();
  }
{'fraction_non_alphanumeric': 0.1784412671712924, 'fraction_numerical': 0.01583964115503224, 'mean_word_length': 2.7316945606694563, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7672333', 'n_tokens_mistral': 2792, 'n_tokens_neox': 2663, 'n_words': 484}