Leaflet Search
Leaflet Search is an easy-to-configure search plugin for leaflet.
Demo: click here
Requirements:
- Leaflet
- FontAwesome
Installation:
via npm:
npm install leaflet-search-control --save
old fashioned way:
download the repository and add the files inside src folder to your project.
Use:
var search = L.control.search({
placeholder : 'Search', //search input placeholder
minNumberOfCharacters : 0, //min number of characters user has to type before search callback is called
searchOnEnter : true, //search when user type enter
noResults : 'No Records Found', //custom text when no result is found
search: function(control, value) {
control.setResults([
{title: 'Item 1'},
{title: 'Item 2', icon: 'fa fa-search'},
{title: 'Item 3', imgIcon: 'img/icon.png'},
{title: 'Item with Super Long Text', icon: 'fa fa-search', imgIcon: 'img/icon.png'}
]);
},
selected: function(item) {
console.log(item);
}
});
search.addTo(map);