<commit_before>var map, pointArray, heatmap;
var heatmapData = [
  <% @coordinates.each do |venue| %>
    new google.maps.LatLng(<%= venue[0] %>, <%= venue[1] %>),
  <% end %>
  ];

function initialize() {
  $('span#hide-pins-btn').addClass('hidden');
  $('span#show-pins-btn').removeClass('hidden');
  $('span#show-pins-btn').on("click", "button", changeShowClass)
  $('span#hide-pins-btn').on("click", "button", changeHideClass)
  var cuisine = "<%= @search.cuisine%>";
  restaurantCount(cuisine);
  var mapOptions = {
    zoom: 11,
    center: new google.maps.LatLng(40.7, -73.9),
    mapTypeId: google.maps.MapTypeId.MAP
  };

  map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);

  var pointArray = new google.maps.MVCArray(heatmapData);
  
  heatmap = new google.maps.visualization.HeatmapLayer({
    data: pointArray
    
  });
  
  heatmap.setMap(map);
  allMarkers = []
  <% @restaurants.each do |restaurant| %>

    marker = new google.maps.Marker({
    position: new google.maps.LatLng(<%=restaurant.latitude%>, <%= restaurant.longitude -%>),
    title: "<%= restaurant.name %>"
    });
    var contentString = '<h5><%= restaurant.name %></h5>'+'<a href="<%= restaurant.foursquare_url %>" target="_blank">Foursquare Page</a><br>'
    <% if restaurant.phone_number %>
    +'<p><%= restaurant.phone_number[0..2] %>.<%= restaurant.phone_number[3..5]%>.<%= restaurant.phone_number[6..-1] %></p>'
    <% end %>
    <% restaurant.cuisines.each do |cuisine| %>
                +'<li><%= cuisine.name %></li><br>'
                <% end %>;

    var infoWindow = new google.maps.InfoWindow();
    bindInfoWindow(marker, contentString, infoWindow);
    allMarkers.push(marker)
  <% end %>
}

function restaurantCount(cuisine){
  var count = "<%= @coordinates.count %>";
  $("span.count").text(cuisine + ": " + count)
}

function toggleHeatmap() {
  heatmap.setMap(heatmap.getMap() ? null : map);
}

function changeGradient() {
  var gradient = [
    'rgba(0, 255, 255, 0)',
    'rgba(0, 255, 255, 1)',
    'rgba(0, 191, 255, 1)',
    'rgba(0, 127, 255, 1)',
    'rgba(0, 63, 255, 1)',
    'rgba(0, 0, 255, 1)',
    'rgba(0, 0, 223, 1)',
    'rgba(0, 0, 191, 1)',
    'rgba(0, 0, 159, 1)',
    'rgba(0, 0, 127, 1)',
    'rgba(63, 0, 91, 1)',
    'rgba(127, 0, 63, 1)',
    'rgba(191, 0, 31, 1)',
    'rgba(255, 0, 0, 1)'
  ]
  heatmap.set('gradient', heatmap.get('gradient') ? null : gradient);
}

function changeRadius() {
  heatmap.set('radius', heatmap.get('radius') ? null : 20);
}

function changeOpacity() {
  heatmap.set('opacity', heatmap.get('opacity') ? null : 0.2);
}

function dropPin(){
  marker.setMap(map);
}

function changeShowClass(){
  dropPins();
  $('span#show-pins-btn').addClass("hidden")
  $('span#hide-pins-btn').removeClass('hidden')
} 

function changeHideClass(){
  hidePins();
  $('span#hide-pins-btn').addClass('hidden')
  $('span#show-pins-btn').removeClass('hidden')
} 

function bindInfoWindow(marker, contentString, infowindow){
  previousWindow = null;
  google.maps.event.addListener(marker, 'click', function(){
    if (previousWindow !== null){
      previousWindow.close();
    }
    infowindow.setContent(contentString);
    infowindow.open(map, marker);
    previousWindow = infowindow;
  });
}

function dropPins(){
  allMarkers.forEach(function(venue){
    venue.setMap(map);
  })
}

function hidePins(){
   allMarkers.forEach(function(venue){
    venue.setMap(null);
  })
}

initialize();<commit_msg>working multiple pin drops with autoclose<commit_after>var map, pointArray, heatmap;
var heatmapData = [
  <% @coordinates.each do |venue| %>
    new google.maps.LatLng(<%= venue[0] %>, <%= venue[1] %>),
  <% end %>
  ];

function initialize() {
  $('span#hide-pins-btn').addClass('hidden');
  $('span#show-pins-btn').removeClass('hidden');
  $('span#show-pins-btn').on("click", "button", changeShowClass)
  $('span#hide-pins-btn').on("click", "button", changeHideClass)
  var cuisine = "<%= @search.cuisine%>";
  restaurantCount(cuisine);
  var mapOptions = {
    zoom: 11,
    center: new google.maps.LatLng(40.7, -73.9),
    mapTypeId: google.maps.MapTypeId.MAP
  };

  map = new google.maps.Map(document.getElementById('map-canvas'),
      mapOptions);

  var pointArray = new google.maps.MVCArray(heatmapData);
  
  heatmap = new google.maps.visualization.HeatmapLayer({
    data: pointArray
    
  });
  
  heatmap.setMap(map);
  allMarkers = []
  <% @restaurants.each do |restaurant| %>

    marker = new google.maps.Marker({
    position: new google.maps.LatLng(<%=restaurant.latitude%>, <%= restaurant.longitude -%>),
    title: "<%= restaurant.name %>",
    id: "<%= restaurant.foursquare_id %>"
    });
    var contentString = '<h5><%= restaurant.name %></h5>'+'<a href="<%= restaurant.foursquare_url %>" target="_blank">Foursquare Page</a><br>'
    // +'<div class="rating">Rating: </div>'
    <% if restaurant.phone_number %>
    +'<p><%= restaurant.phone_number[0..2] %>.<%= restaurant.phone_number[3..5]%>.<%= restaurant.phone_number[6..-1] %></p>'
    <% end %>
    <% restaurant.cuisines.each do |cuisine| %>
                +'<li><%= cuisine.name %></li><br>'
                <% end %>;

    var infoWindow = new google.maps.InfoWindow();
    bindInfoWindow(marker, contentString, infoWindow);
    allMarkers.push(marker)
  <% end %>
}

function restaurantCount(cuisine){
  var count = "<%= @coordinates.count %>";
  $("span.count").text(cuisine + ": " + count)
}

function toggleHeatmap() {
  heatmap.setMap(heatmap.getMap() ? null : map);
}

function changeGradient() {
  var gradient = [
    'rgba(0, 255, 255, 0)',
    'rgba(0, 255, 255, 1)',
    'rgba(0, 191, 255, 1)',
    'rgba(0, 127, 255, 1)',
    'rgba(0, 63, 255, 1)',
    'rgba(0, 0, 255, 1)',
    'rgba(0, 0, 223, 1)',
    'rgba(0, 0, 191, 1)',
    'rgba(0, 0, 159, 1)',
    'rgba(0, 0, 127, 1)',
    'rgba(63, 0, 91, 1)',
    'rgba(127, 0, 63, 1)',
    'rgba(191, 0, 31, 1)',
    'rgba(255, 0, 0, 1)'
  ]
  heatmap.set('gradient', heatmap.get('gradient') ? null : gradient);
}

function changeRadius() {
  heatmap.set('radius', heatmap.get('radius') ? null : 20);
}

function changeOpacity() {
  heatmap.set('opacity', heatmap.get('opacity') ? null : 0.2);
}

function dropPin(){
  marker.setMap(map);
}

function changeShowClass(){
  dropPins();
  $('span#show-pins-btn').addClass("hidden")
  $('span#hide-pins-btn').removeClass('hidden')
} 

function changeHideClass(){
  hidePins();
  $('span#hide-pins-btn').addClass('hidden')
  $('span#show-pins-btn').removeClass('hidden')
} 

function bindInfoWindow(marker, contentString, infowindow){
  previousWindow = null;
  google.maps.event.addListener(marker, 'click', function(){
    if (previousWindow !== null){
      previousWindow.close();
    }
    infowindow.setContent(contentString);
    infowindow.open(map, marker);
    previousWindow = infowindow;
  });
}

function dropPins(){
  allMarkers.forEach(function(venue){
    venue.setMap(map);
  })
}

function hidePins(){
   allMarkers.forEach(function(venue){
    venue.setMap(null);
  })
}

initialize();


// $('.gm-style-iw').children('div').children('div').children('div').append("8.4")
{'fraction_non_alphanumeric': 0.20832751152717618, 'fraction_numerical': 0.03297471007405337, 'mean_word_length': 3.8234501347708894, 'pattern_counts': {'":': 2, '<': 68, '<?xml version=': 0, '>': 68, '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': '2345837', 'n_tokens_mistral': 2847, 'n_tokens_neox': 2552, 'n_words': 462}