Click here to Skip to main content
15,917,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I developed the store locator using open street map and leaflet. The problem is when I want to type in searchbox it will become lagging to finish the word. That store locator read from the CSV file that has 300++ data. Below is the code for the searchbox:

var locationLat = [];
var locationLng = [];
var locMarker;
var infoDiv = document.getElementById('storeinfo');
var infoDivInner = document.getElementById('infoDivInner');
var toggleSearch = document.getElementById('searchIcon');
var hasCircle = 0;
var circle = [];
//close store infor when x is clicked
var userLocation;
$("#infoClose").click(function() {
  $("#storeinfo").hide();
  if (map.hasLayer(circle)) {
    map.removeLayer(circle);
  }
});
var listings = document.getElementById('listingDiv');
var stores = L.geoJson().addTo(map);
var storesData = omnivore.csv('assets/data/table_1.csv
function setActive(el) {
  var siblings = listings.getElementsByTagName('div');
  for (var i = 0; i < siblings.length; i++) {
    siblings[i].className = siblings[i].className
      .replace(/active/, '').replace(/\s\s*$/, '');
  }
  el.className += ' active';
}

function sortGeojson(a,b,prop) {
  return (a.properties.name.toUpperCase() < b.properties.name.toUpperCase()) ? -1 : ((a.properties.name.toUpperCase() > b.properties.name.toUpperCase()) ? 1 : 0);
}

storesData.on('readyunction() {

  var storesSorted = storesData.toGeoJSON();
  //console.log(storesSorted);
  var sorted = (storesSorted.features).sort(sortGeojson)
  //console.log(sorted);
  storesSorted.features = sorted;
  //console.log(storesSorted)
  stores.addData(storesSorted);

  map.fitBounds(stores.getBounds());
  toggleSearch.onclick = function() {
    //var s = document.getElementById('searchbox');
    //if (s.style.display != 'none') {
      //s.style.display = 'yes';
      //toggleSearch.innerHTML = '';
      //$("#search-input").val("");

      //search.collapse();
      //document.getElementById('storeinfo').style.display = 'none';
      //$('.item').show();
    //} else {
      //toggleSearch.innerHTML = '^__i class="fa fa-times">';
      //s.style.display = 'block';

      //attempt to autofocus search input field when opened
      //$('#search-input').focus();
    //}
  };
  stores.eachLayer(function(layer) {

    //New jquery search
    $('#searchbox').on('change paste keyup', function() {
      var txt = $('#search-input').val();
      $('.item').each(function() {
        if ($(this).text().toUpperCase().indexOf(txt.toUpperCase()) != -1) {
          $(this).show();
        } else {
          $(this).hide();
        }
      });
    });


Is there any way to solve this problem? I've been searching solution to solve this but still cannot find the solution. Thank you

What I have tried:

I tried learn to use bootstrap search table but i did know how to apply in this store locator.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900