stefanocudini / leaflet-search

Search stuff in a Leaflet map
https://opengeo.tech/maps/leaflet-search/
MIT License
780 stars 335 forks source link

How to disable further client-side filtering of ajax results? #310

Closed answerquest closed 1 year ago

answerquest commented 1 year ago

Hi, thank you for making this great plugin.

I have all searching functionalities well taken care of in my backend api that is being called. I'd like the results list as-is to be displayed. But instead I'm seeing that this plugin is doing one more level of filtering on those results, and this is messing up the functionality. Is there a way we can prevent this additional filtering that's happening?

answerquest commented 1 year ago

Got it! Have to give a function for filterData option param and just return the allRecords array.

function mapSearchFunc(textSearch, allRecords) {
    // console.log('textSearch:',textSearch, 'allRecords:',allRecords);
    return allRecords;
}

// ref: https://github.com/stefanocudini/leaflet-search
map.addControl( new L.Control.Search({ 
        sourceData: searchByAjax, 
        text:'Searh a stop...', 
        markerLocation: true,
        minLength: 3,
        filterData: mapSearchFunc
    })
);