<commit_before><% content_for :head do %>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<% end %>


<div id="main-container">
  <!--nav-->
 <nav class="bg-blue">
    <div class="container-fluid">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>

          <img class="logo" src="/assets/logo-01.png"><h2>LibraryMapping&middot; User map</h2>
        </div>
        <div class="collapse navbar-collapse" id="myNavbar">
          <ul class="nav navbar-nav navbar-right ">
              <li><a class="white-font" href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
              <li><a class="white-font" href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
          </ul>
        </div>
   </div>
  </nav>
  <!--[if IE]><script src="http://fabricjs.com/lib/fonts/Delicious.font.js"></script><![endif]-->



  <link href='http://fonts.googleapis.com/css?family=Plaster' rel='stylesheet' type='text/css'>
  <link href='http://fonts.googleapis.com/css?family=Engagement' rel='stylesheet' type='text/css'>
<!--   <div id="tipbtn" class="hidden">
    <p class="tip-btn" onclick=showTip();>Tips</p>
  </div>
  <div id="tip-div" class="navbar-collapse tip">
    <p id="i-label">Here is the tip for the users</p>
    <p id="tip-close" onclick=hideTip();>x</p> -->
  <div class="navbar-collapse optionsTopBar">
    <label> Library: </label>
    <select id="library_option">
      <option value="main">Main Library</option>
      <option value="murray">Murray Library</option>
    </select>

    <label> Floors: </label>
    <%= link_to "Lower Ground", {controller: "map_display", action: "map", floor: 0, library: @library}, class: "btn btn-default btn-sm btn-floor", data: { no_turbolink: true, floor: 0 } %>
    <%= link_to "Ground", {controller: "map_display", action: "map", floor: 1, library: @library}, class: "btn btn-default btn-sm btn-floor", data: { no_turbolink: true, floor: 1 } %>
    <%= link_to "First", {controller: "map_display", action: "map", floor: 2, library: @library}, class: "btn btn-default btn-sm btn-floor", data: { no_turbolink: true, floor: 2 } %>
    <%= link_to "Second", {controller: "map_display", action: "map", floor: 3, library: @library}, class: "btn btn-default btn-sm btn-floor", data: { no_turbolink: true, floor: 3  } %>
    <%= link_to "Third", {controller: "map_display", action: "map", floor: 4, library: @library}, class: "btn btn-default btn-sm btn-floor", data: { no_turbolink: true, floor: 4  } %>
    <%= link_to "Fourth", {controller: "map_display", action: "map", floor: 5, library: @library}, class: "btn btn-default btn-sm btn-floor", data: { no_turbolink: true, floor: 5  } %>

    <% if @title %>
      <label> Title: </label>
      <span><%= @title %></span>
    <% end %>

    <% if @author %>
      <label> Author: </label>
      <span><%= @author %></span>
    <% end %>
  </div>
<!--Image map canvas-->
<div id="image-map"></div>
<!--Footer-->
<div class="footerHolder">
  <p>
      Unless explicitly stated otherwise, all material is copyright © The University of Edinburgh

      <script type="text/javascript">
      var currentTime = new Date()
      var year = currentTime.getFullYear()
      document.write(+ year)
      </script>
              
    </p>
</div>
</div>
<script>
  var map = L.map('image-map', {
    minZoom: 0.2,
    maxZoom: 4,
    center: [0, 0],
    zoom: 1,
    attributionControl: false,
    crs: L.CRS.Simple
  });

  // dimensions of the image
  var w = 6000,
      h = 4000,
      url = '/assets/' + '<%= @library %>' + '_' + '<%= @floor %>' + '.svg';

  // calculate the edges of the image, in coordinate space
  var southWest = map.unproject([0, h], map.getMaxZoom()-1);
  var northEast = map.unproject([w, 0], map.getMaxZoom()-1);
  var bounds = new L.LatLngBounds(southWest, northEast);

  // add the image overlay,
  // so that it covers the entire map
  L.imageOverlay(url, bounds).addTo(map);

  // tell leaflet that the map is exactly as big as the image
  map.setMaxBounds(bounds);

  var _br = fromLatLngToVectorPoint(55.942517,-3.188288);
  var _bl = fromLatLngToVectorPoint(55.942326,-3.189546);
  var _tr = fromLatLngToVectorPoint(55.942999,-3.188516);
  var _tl = fromLatLngToVectorPoint(55.942811,-3.189775);

  var br = reflectYaxis(_bl.subtract(_br));
  var bl = reflectYaxis(_bl.subtract(_bl));
  var tr = reflectYaxis(_bl.subtract(_tr));
  var tl = reflectYaxis(_bl.subtract(_tl));

  var marker;
  function addPin(lat, lng, accuracy) {
    console.log(accuracy / (80/6000));
    var _newPoint = fromLatLngToVectorPoint(lat, lng);
    var newPoint = reflectYaxis(_bl.subtract(_newPoint));

    var m = {
      x: project(newPoint, br).modulus() * 6473394.1008608695,
      y: 4000 - project(newPoint, tl).modulus() * 6279304.20368495
    }

    console.log(m);
    if(marker){
      marker.setLatLng(map.unproject([m.x, m.y], map.getMaxZoom()-1))
    }else{
      marker = L.marker(map.unproject([m.x, m.y], map.getMaxZoom()-1));
      marker.addTo(map);
    }
  }

  function project(b, a) {
    return a.multiply(a.dot(b) / (a.modulus() * a.modulus()))
  }

  function reflectYaxis(v) {
    return Vector.create([v.e(1)*-1, v.e(2)]);
  }

  function fromLatLngToVectorPoint(lat, long) {
    var x = (long + 180) / 360 * 256;
    var y = ((1 - Math.log(Math.tan(lat * Math.PI / 180) + 1 / Math.cos(lat * Math.PI / 180)) / Math.PI) / 2 * Math.pow(2, 0)) * 256;
    return Vector.create([x, y]);
  }



  function successCallback(position) {
    console.log(position.coords.latitude, position.coords.longitude, position.coords.altitude)
    addPin(position.coords.latitude, position.coords.longitude, position.coords.accuracy);
  }

  function errorCallback(error){
    console.log("- It didn't work.\n");
    switch(error.code){
      case error.PERMISSION_DENIED:
        console.log("- Permission denied.\n");
        break;
      case error.POSITION_UNAVAILABLE:
        console.log("- Position unavailable.\n");
        break;
      case error.TIMEOUT:
        console.log("- Timeout.\n");
        break;
      case error.UNKNOW_ERROR:
        console.log("- Unknown error.\n");
        break;
    }
  }

  if (navigator.geolocation) {
    $('#console').append("- Retrieving position.\n");
    var options = {
      enableHighAccuracy : true,
      timeout : 10000, // 10s
      maximumAge : 0
    };

    navigator.geolocation.watchPosition(successCallback, errorCallback, options);

  } else {
    $('#console').append("- Geo Location is not supported.\n");
  }

  <% @elements.each do |element| %>
    L.marker(map.unproject([<%= element.left %>, <%= element.top %>], map.getMaxZoom()-1)).addTo(map).bindPopup("<b>To kill a mockingbird</b><br> <NAME>").openPopup();
  <% end %>

  function showTip(){
    $('#tip-div').removeClass('hidden').animate(500);
    $('#tipbtn').addClass('hidden');
  };<commit_msg>Fix duplicate elements code<commit_after><% content_for :head do %>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<% end %>


<div id="main-container">
  <!--nav-->
 <nav class="bg-blue">
    <div class="container-fluid">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>

          <img class="logo" src="/assets/logo-01.png"><h2>LibraryMapping&middot; User map</h2>
        </div>
        <div class="collapse navbar-collapse" id="myNavbar">
          <ul class="nav navbar-nav navbar-right ">
              <li><a class="white-font" href="#"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
              <li><a class="white-font" href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
          </ul>
        </div>
   </div>
  </nav>
  <!--[if IE]><script src="http://fabricjs.com/lib/fonts/Delicious.font.js"></script><![endif]-->



  <link href='http://fonts.googleapis.com/css?family=Plaster' rel='stylesheet' type='text/css'>
  <link href='http://fonts.googleapis.com/css?family=Engagement' rel='stylesheet' type='text/css'>
<!--   <div id="tipbtn" class="hidden">
    <p class="tip-btn" onclick=showTip();>Tips</p>
  </div>
  <div id="tip-div" class="navbar-collapse tip">
    <p id="i-label">Here is the tip for the users</p>
    <p id="tip-close" onclick=hideTip();>x</p> -->
  <div class="navbar-collapse optionsTopBar">
    <label> Library: </label>
    <select id="library_option">
      <option value="main">Main Library</option>
      <option value="murray">Murray Library</option>
    </select>

    <label> Floors: </label>
    <%= link_to "Lower Ground", {controller: "map_display", action: "map", floor: 0, library: @library}, class: "btn btn-default btn-sm btn-floor", data: { no_turbolink: true, floor: 0 } %>
    <%= link_to "Ground", {controller: "map_display", action: "map", floor: 1, library: @library}, class: "btn btn-default btn-sm btn-floor", data: { no_turbolink: true, floor: 1 } %>
    <%= link_to "First", {controller: "map_display", action: "map", floor: 2, library: @library}, class: "btn btn-default btn-sm btn-floor", data: { no_turbolink: true, floor: 2 } %>
    <%= link_to "Second", {controller: "map_display", action: "map", floor: 3, library: @library}, class: "btn btn-default btn-sm btn-floor", data: { no_turbolink: true, floor: 3  } %>
    <%= link_to "Third", {controller: "map_display", action: "map", floor: 4, library: @library}, class: "btn btn-default btn-sm btn-floor", data: { no_turbolink: true, floor: 4  } %>
    <%= link_to "Fourth", {controller: "map_display", action: "map", floor: 5, library: @library}, class: "btn btn-default btn-sm btn-floor", data: { no_turbolink: true, floor: 5  } %>

    <% if @title %>
      <label> Title: </label>
      <span><%= @title %></span>
    <% end %>

    <% if @author %>
      <label> Author: </label>
      <span><%= @author %></span>
    <% end %>
  </div>
<!--Image map canvas-->
<div id="image-map"></div>
<!--Footer-->
<div class="footerHolder">
  <p>
      Unless explicitly stated otherwise, all material is copyright © The University of Edinburgh

      <script type="text/javascript">
      var currentTime = new Date()
      var year = currentTime.getFullYear()
      document.write(+ year)
      </script>
              
    </p>
</div>
</div>
<script>
  var map = L.map('image-map', {
    minZoom: 0.2,
    maxZoom: 4,
    center: [0, 0],
    zoom: 1,
    attributionControl: false,
    crs: L.CRS.Simple
  });

  // dimensions of the image
  var w = 6000,
      h = 4000,
      url = '/assets/' + '<%= @library %>' + '_' + '<%= @floor %>' + '.svg';

  // calculate the edges of the image, in coordinate space
  var southWest = map.unproject([0, h], map.getMaxZoom()-1);
  var northEast = map.unproject([w, 0], map.getMaxZoom()-1);
  var bounds = new L.LatLngBounds(southWest, northEast);

  // add the image overlay,
  // so that it covers the entire map
  L.imageOverlay(url, bounds).addTo(map);

  // tell leaflet that the map is exactly as big as the image
  map.setMaxBounds(bounds);

  var _br = fromLatLngToVectorPoint(55.942517,-3.188288);
  var _bl = fromLatLngToVectorPoint(55.942326,-3.189546);
  var _tr = fromLatLngToVectorPoint(55.942999,-3.188516);
  var _tl = fromLatLngToVectorPoint(55.942811,-3.189775);

  var br = reflectYaxis(_bl.subtract(_br));
  var bl = reflectYaxis(_bl.subtract(_bl));
  var tr = reflectYaxis(_bl.subtract(_tr));
  var tl = reflectYaxis(_bl.subtract(_tl));

  var marker;
  function addPin(lat, lng, accuracy) {
    console.log(accuracy / (80/6000));
    var _newPoint = fromLatLngToVectorPoint(lat, lng);
    var newPoint = reflectYaxis(_bl.subtract(_newPoint));

    var m = {
      x: project(newPoint, br).modulus() * 6473394.1008608695,
      y: 4000 - project(newPoint, tl).modulus() * 6279304.20368495
    }

    console.log(m);
    if(marker){
      marker.setLatLng(map.unproject([m.x, m.y], map.getMaxZoom()-1))
    }else{
      marker = L.marker(map.unproject([m.x, m.y], map.getMaxZoom()-1));
      marker.addTo(map);
    }
  }

  function project(b, a) {
    return a.multiply(a.dot(b) / (a.modulus() * a.modulus()))
  }

  function reflectYaxis(v) {
    return Vector.create([v.e(1)*-1, v.e(2)]);
  }

  function fromLatLngToVectorPoint(lat, long) {
    var x = (long + 180) / 360 * 256;
    var y = ((1 - Math.log(Math.tan(lat * Math.PI / 180) + 1 / Math.cos(lat * Math.PI / 180)) / Math.PI) / 2 * Math.pow(2, 0)) * 256;
    return Vector.create([x, y]);
  }



  function successCallback(position) {
    console.log(position.coords.latitude, position.coords.longitude, position.coords.altitude)
    addPin(position.coords.latitude, position.coords.longitude, position.coords.accuracy);
  }

  function errorCallback(error){
    console.log("- It didn't work.\n");
    switch(error.code){
      case error.PERMISSION_DENIED:
        console.log("- Permission denied.\n");
        break;
      case error.POSITION_UNAVAILABLE:
        console.log("- Position unavailable.\n");
        break;
      case error.TIMEOUT:
        console.log("- Timeout.\n");
        break;
      case error.UNKNOW_ERROR:
        console.log("- Unknown error.\n");
        break;
    }
  }

  if (navigator.geolocation) {
    $('#console').append("- Retrieving position.\n");
    var options = {
      enableHighAccuracy : true,
      timeout : 10000, // 10s
      maximumAge : 0
    };

    navigator.geolocation.watchPosition(successCallback, errorCallback, options);

  } else {
    $('#console').append("- Geo Location is not supported.\n");
  }

  function showTip(){
    $('#tip-div').removeClass('hidden').animate(500);
    $('#tipbtn').addClass('hidden');
  };
{'fraction_non_alphanumeric': 0.18523765672593326, 'fraction_numerical': 0.025430332223560247, 'mean_word_length': 3.180633698549008, 'pattern_counts': {'":': 0, '<': 211, '<?xml version=': 0, '>': 211, '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': '2867577', 'n_tokens_mistral': 5203, 'n_tokens_neox': 4810, 'n_words': 1091}