Maps SDK for Web

tt.plugins.SearchBox

This plugin provides a search box functionality to your map.

As the user starts typing, search results appear in the list below the input field. Results list combines autocomplete and fuzzy search results.

User’s keystrokes result in requests to Fuzzy Search and Autocomplete services. A number of calls made to the service can be optimized thanks to the options: idleTimePress and minNumberOfCharacters.

For more details on how to use the configuration options, please refer to the documentation below.

Constructor

tt.plugins.SearchBox(services, [options])

Example
{
   idleTimePress: 100,
   minNumberOfCharacters: 0,
   searchOptions: {
       key: '<your-tomtom-search-key>'
       language: 'en-GB'
   },
   autocompleteOptions: {
       key: '<your-tomtom-search-key>'
       language: 'en-GB'
   },
   noResultsMessage: 'No results found.'
}
Parameters
Name Description
services
Services
default:None
The services object, which you need to import beforehand.
options
Object
default:None
The Options object.
options.placeholder
String
default:None
Specifies text that appears within the search box when it's empty.
options.idleTimePress
Number
default:200
The Search service call delay (in ms) after the last typed character.
options.minNumberOfCharacters
Number
default:3
The minimum number of characters to trigger the search call. Search results will show the distance from the center of the map; this sets which units should be used.
options.searchOptions
Object
default:None
Options for the fuzzy search service. For full list of options please refer to fuzzySearch service documentation.
options.autocompleteOptions
Object
default:None
Options for the autocomplete service. For full list of options please refer to autocomplete service documentation. If you pass this option, results list will be extended by the results returned by autocomplete service. They are used as filters for the fuzzy search.
options.filterSearchResults
Function
default:None
Only those fuzzy search results that pass the test implemented in this method will be shown on the results list.
options.noResultsMessage
String
default:'No results found.'
The message shown when a given query search service returned no results or they were filtered out.
options.showSearchButton
Boolean
default:true
If set to false, search icon in the input will be hidden.
options.cssStyleCheck
Boolean
default:true
If true, the plugin will check if required css styles are added.

Methods

getOptions( ): Object

Returns the options object.

Returns

this.options

onAdd(map): HTMLElement

Binds map with plugin instance.

Parameters
Name Description
map
Maps.Map
default:None
Returns

container

onRemove( ): Void

Removes plugin from the map.

Returns

query( ): Void

Triggers search and fills the results list

Returns

removeFilter( ): Void

Remove the existing filter

Returns

setFilter(filterOptions): Void

Set a filter as brandSet or categorySet for the search options

Parameters
Name Description
filterOptions
Object
default:None
object consists of [type] and [value] properties
filterOptions.type
String
default:None
available types: 'category', 'brand'
filterOptions.value
Object
default:None
data needed for preparing a service call and for the correct display the filter inside the input
Returns

Sample filterOptions object notation: <pre><code class="language-javascript">{ type: 'category', value: { name: 'Shop', id: '9361' } } </code></pre>

updateOptions(options): Void

Updates options

Parameters
Name Description
options
Object
default:None
Returns

Events

All the class events are keys of the Events static member.

To learn more about how to listen events please refer to the Evented class.

tomtom.searchbox.resultfocused

Fired when result is focused.

tomtom.searchbox.resultscleared

Fired when search results are cleared.

tomtom.searchbox.resultselected

Fired when result is selected.

tomtom.searchbox.resultsfound

Fired when search results are found.