title: Calling multiple JSON data with Jquery Deferred
body: <p>I am trying to get multiple JSON data with deferred object. I have JSON files for individual days. In each individual day, I have data for points, lines and polygons. I have jQueryUI Sliders to visualise for individual days. For example, if the slider has value of 1, only the day1 data (points, lines and polygons)  need to be visualised, and for day2, all points, lines and polygons relating to day2 only should be visualised and so on. </p>
  
  <p>I don't know what is problem with my code but it is not serving the required data. Latest data/merged data is shown.
  Help me out here.</p>
  
  <pre><code>$(document).ready(function () {
  
  var map = L.map("map", {
      center: [27.6419412, 85.1224152],
      zoom: 13,
      doubleClickZoom: true
  });
  
  L.tileLayer('http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png', {
      attribution: '&amp;copy; &lt;a href="http://www.openstreetmap.org/copyright"&gt;OpenStreetMap&lt;/a&gt;'
  }).addTo(map);
  
  L.control.scale().addTo(map);
  
  var markerCluster = L.markerClusterGroup({
      showCoverageOnHover: false
  });
  
  function TableContent(jsonData) {
      var content = $('&lt;div&gt;&lt;/div&gt;').addClass('table-content');
      for (row in jsonData) {
          var tableRow = $('&lt;div&gt;&lt;/div&gt;').addClass('table-row').append(function () {
              var key = row;
              if (!(key === "@uid" || key === "@changeset" || key === "@version" || key === "@timestamp" || key === "@id")) {
                  return jsonData[row] ? $("&lt;div&gt;&lt;/div&gt;").text(key).append($("&lt;div&gt;&lt;/div&gt;").text(jsonData[row])) : "";
              }
          });
          tableRow.prependTo(content).addClass(row);
      }
      return $(content)[0];
  }
  
  function Table(json) {
      return $('&lt;div&gt;&lt;/div&gt;').append($('&lt;div class="title"&gt;&lt;/div&gt;').text(json.type)).addClass('table-container').append(new TableContent(json.data));
  }
  
  var pointBuild = L.geoJson(null, {
      pointToLayer: function (feature, latlng) {
          var deferred = $.Deferred();
          marker = L.marker(latlng, {
              icon: L.icon({
                  iconUrl: 'img/marker.png',
                  iconSize: [30, 30],
                  iconAnchor: [15, 15]
              }),
              riseOnHover: true,
              title: "This is a Point feature. Click to have a look at some of its attributes"
          });
          markerCluster.addLayer(marker);
          deferred.resolve();
          map.fire('cluster-hover');
          return marker;
      },
      onEachFeature: function (feature, layer) {
          var popup = L.popup();
          layer.on('click', function (e) {
              var deferred = $.Deferred();
              popup.setLatLng(e.latlng);
              popup.setContent(new TableContent(feature.properties));
              popup.openOn(map);
              deferred.resolve();
          });
      }
  });
  
  var myStyle = {
      weight: 2,
      opacity: 1,
      color: '#FF0000',
      dashArray: '3',
      fillOpacity: 0.3,
      fillColor: '#FA8072'
  };
  
  var wayBuild = L.geoJson(null, {
      style: myStyle,
      onEachFeature: function (feature, layer) {
          var popup = L.popup();
          layer.on('click', function (e) {
              var deferred = $.Deferred();
              popup.setLatLng(e.latlng);
              popup.setContent(new TableContent(feature.properties));
              popup.openOn(map);
              deferred.resolve();
          });
      }
  });
  
  function pointLinePolygon(receivedPoints, receivedLines, receivedPolygon, day) {
  
      var points_, lines_, polygon_;
      var deferredPoint = $.Deferred();
      var deferredLine = $.Deferred();
      var deferredPolygon = $.Deferred();
  
      $.getJSON(receivedPoints, function (data) {
  
          setTimeout(function () {
              pointBuild.addData(data);
              points_ = markerCluster;
              deferredPoint.resolve();
          }, 0);
      });
  
      $.getJSON(receivedLines, function (data) {
          setTimeout(function () {
              lines_ = wayBuild.addData(data);
              deferredLine.resolve();
          }, 0);
      });
  
      $.getJSON(receivedPolygon, function (data) {
          setTimeout(function () {
              polygon_ = wayBuild.addData(data);
              deferredPolygon.resolve();
          }, 0);
      });
  
      $.when(deferredPoint, deferredLine, deferredPolygon).done(function () {
  
          var featureGroup = L.layerGroup([points_, lines_, polygon_]);
          featureGroup.addTo(map);
          $.map(wayBuild._layers, function (layer, index) {
              $(layer._container).find("path").attr("title", "This is a way feature. Click to have a look at some of its attributes.");
          });
      });
  
  }
  
  map.on('cluster-hover', function () {
      setTimeout(function () {
          $("#map").find("div.marker-cluster").attrByFunction(function () {
              return {
                  title: "This is a Cluster of " + $(this).find("span").text() + " Point features. Click to zoom in and see the Point features and sub-clusters it contains."
              }
          });
      }, 0);
  });
  
  var tooltip = $('&lt;div id="toolTipSlider" /&gt;').hide();
  
  $('#slider').slider({
      min: 1,
      max: 4,
      slide: function (event, ui) {
          if (ui.value === 1) {
              tooltip.text("Day " + ui.value);
              $.ajax({
                  type: 'post',
                  success: function () {
                      pointLinePolygon("data/day1/points.geojson", "data/day1/lines.geojson", "data/day1/polygon.geojson", "Day 1");
                  }
              });
          }
          else if (ui.value === 2) {
              tooltip.text("Day " + ui.value);
              $.ajax({
                  type: 'post',
                  success: function () {
                      pointLinePolygon("data/day2/points.geojson", "data/day2/lines.geojson", "data/day2/polygon.geojson", "Day 2");
                  }
              });
          }
  
          else if (ui.value === 3) {
              tooltip.text("Day " + ui.value);
              $.ajax({
                  type: 'post',
                  success: function () {
                      pointLinePolygon("data/day3/points.geojson", "data/day3/lines.geojson", "data/day3/polygon.geojson", "Day 3");
                  }
              });
          }
  
          else if (ui.value === 4) {
              tooltip.text("Day " + ui.value);
              $.ajax({
                  type: 'post',
                  success: function () {
                      pointLinePolygon("data/day4/points.geojson", "data/day4/lines.geojson", "data/day4/polygon.geojson", "Day 4");
                  }
              });
          }
      }
  }).find(".ui-slider-handle").append(tooltip).hover(function () {
      tooltip.show();
  });
  </code></pre>
  
  <p>});</p>
  
  <pre><code>$.fn.attrByFunction = function (a) {
  return $(this).each(function () {
      $(this).attr(a.call(this));
  });
  };
  </code></pre>