Class: Search

ol.control. Search

Search Control. This is the base class for search controls. You can use it for simple custom search or as base to new class.


Parameters:
Name Type Argument Description
options Object <optional>
Properties
Name Type Description
className string

control class name

target Element | string | undefined

Specify a target if you want the control to be rendered outside of the map's viewport.

title string | undefined

Title to use for the search button tooltip, default "Search"

reverseTitle string | undefined

Title to use for the reverse geocoding button tooltip, default "Click on the map..."

placeholder string | undefined

placeholder, default "Search..."

reverse boolean | undefined

enable reverse geocoding, default false

inputLabel string | undefined

label for the input, default none

collapsed string | undefined

search is collapsed on start, default true

noCollapse string | undefined

prevent collapsing on input blur, default false

typing number | undefined

a delay on each typing to start searching (ms) use -1 to prevent autocompletion, default 300.

minLength integer | undefined

minimum length to start searching, default 1

maxItems integer | undefined

maximum number of items to display in the autocomplete list, default 10

maxHistory integer | undefined

maximum number of items to display in history. Set -1 if you don't want history, default maxItems

getTitle function

a function that takes a feature and return the name to display in the index.

autocomplete function

a function that take a search string and callback function to send an array

onselect function

a function called when a search is selected

centerOnSelect boolean

center map on search, default false

zoomOnSelect number | boolean

center map on search and zoom to value if zoom < value, default false

See:
Fires:
  • event:select
  • change:input

Extends

Members


_history

Current history

Methods


_getTitleTxt(f)

Returns title as text

Parameters:
Name Type Description
f any

feature to be displayed

Returns:
Type
string

autocomplete(s, cback)

Autocomplete function

Parameters:
Name Type Description
s string

search string

cback function

a callback function that takes an array to display in the autocomplete field (for asynchronous search)

Returns:

an array of search solutions or false if the array is send with the cback argument (asnchronous)

Type
Array | false

clearHistory()

Remove previous history


collapse( [b])

Collapse the search

Parameters:
Name Type Argument Default Description
b boolean <optional>
true

equalFeatures(f1, f2)

Test if 2 features are equal

Parameters:
Name Type Description
f1 any
f2 any
Returns:
Type
boolean

getHistory()

Get history table


getInputField()

Get the input field

Returns:
Type
Element

getTitle(f)

Returns the text to be displayed in the menu

Parameters:
Name Type Description
f any

feature to be displayed

Returns:

the text to be displayed in the index, default f.name

Type
string

restoreHistory()

Restore history (from the localstorage)


reverseGeocode(coord, cback)

Reverse geocode

Parameters:
Name Type Description
coord ol.coordinate
cback function | undefined

a callback function, default trigger a select event


saveHistory()

Save history (in the localstorage)


Force search to refresh


select(f, reverse, coord, options)

A line has been clicked in the menu > dispatch event

Parameters:
Name Type Description
f any

the feature, as passed in the autocomplete

reverse boolean

true if reverse geocode

coord ol.coordinate
options *

options passed to the event


setInput(value, search)

Set the input value in the form (for initialisation purpose)

Parameters:
Name Type Description
value string
search boolean

to start a search


setMap(map)

Remove the control from its current map and attach it to the new map. Subclasses may set up event handlers to get notified about changes to the map here.

Parameters:
Name Type Description
map ol.Map

Map.