
// add an array to store markers that added on map from shortList aaray
var mapMakers = [];
var bikeRackIcon = '../img/Icons/Bike.png'


var rackObj = {
  rackData: null,
  shortList: [],
  distance: 500,
  distanceEl: document.getElementById("distance"),
  sliderEl: document.getElementById("slider"),
  txtinEl: document.getElementById('txtin'),
  callData: $.getJSON('https://data.seattle.gov/resource/fxh3-tqdm.json?$limit=3000').done(function(){
    rackObj.rackData = rackObj.callData;
  }),
  //returns net distance between user and rack in feet.
  netDistance: function(userLat, userLong, rackLat, rackLong){
    var yDist;
    var xDist;
    yDist = rackLat - userLat;
    xDist = rackLong - userLong;
    //because the length of a latitudinal degree is different from the length of a longitudinal degree, we need to convert to a standard unit.  In this case, feet. I assume Seattle's lat of approx 47.6 degrees.
    yDist = Math.floor(yDist * 364771.26);
    xDist = Math.floor(xDist * 246819.84);
    return Math.sqrt(yDist * yDist + xDist * xDist);
  },
  //pushes nearby racks to the shortList array.
  closeRacksFinder: function(userLat, userLong, distance){
    this.shortList = [];
    for (var i =0; i < this.rackData.responseJSON.length; i++){
      var rack = this.rackData.responseJSON;
      if (this.netDistance(userLat, userLong, parseFloat(rack[i].latitude), parseFloat(rack[i].longitude)) < distance){
        this.shortList.push(rack[i]);
      }
    }
  },
  rackMarker: function(rack){
    var latLng = {lat: parseFloat(rack.latitude), lng: parseFloat(rack.longitude)};
    var marker = new google.maps.Marker({
      position: latLng,
      map: map,
      title: "Distance from you: " + rackObj.netDistance(uLat, uLong, latLng.lat, latLng.lng) + " feet.",
      icon:bikeRackIcon
    })
    mapMakers.push(marker);
  },
  racksMapper: function(){
    for (var i = 0; i < this.shortList.length ; i++){
      this.rackMarker(this.shortList[i]);
    }
  }
}

//remove all markers of nearest bike rack from map
document.getElementById('clearMap').addEventListener('click',function(){
  for (var i=0; i < mapMakers.length; i++) {
    mapMakers[i].setMap(null);
  }
  for (var i = 0; i < markers.length; i++) {
    markers[i].setMap(null);  }
});

@@ -1980,16 +1980,133 @@
 %0A  %7D%0A%7D%0A%0A
+function removeBikeRacksMarkers()%7B%0A  for (var i=0; i %3C mapMakers.length; i++) %7B%0A    mapMakers%5Bi%5D.setMap(null);%0A  %7D%0A%7D%0A
 //remove
@@ -2217,24 +2217,52 @@
 function()%7B%0A
+  removeBikeRacksMarkers();%0A
   for (var i
@@ -2253,33 +2253,35 @@
 ();%0A  for (var i
-=
+ = 
 0; i %3C mapMakers
@@ -2265,35 +2265,33 @@
 ar i = 0; i %3C ma
-pMa
+r
 kers.length; i++
@@ -2292,35 +2292,33 @@
 h; i++) %7B%0A    ma
-pMa
+r
 kers%5Bi%5D.setMap(n
@@ -2331,84 +2331,110 @@
   %7D%0A
-  for (var i = 0; i %3C markers.length; i++) %7B%0A    markers%5Bi%5D.setMap(null);  %7D
+%7D);%0Adocument.getElementById('slider').addEventListener('click',function()%7B%0A  removeBikeRacksMarkers();
 %0A%7D);

clear old bike racks by click on range