Add the geocoder to a container. The container can be either a Map
, an HTMLElement
or a CSS selector string.
If the container is a Map
, this function will behave identically to Map.addControl(geocoder)
.
If the container is an instance of HTMLElement
, then the geocoder will be appended as a child of that HTMLElement
.
If the container is a CSS selector string, the geocoder will be appended to the element returned from the query.
This function will throw an error if the container is none of the above.
It will also throw an error if the referenced HTML element cannot be found in the document.body
.
For example, if the HTML body contains the element <div id='geocoder-container'></div>
, the following script will append the geocoder to #geocoder-container
:
A reference to the container to which to add the geocoder
Get the filter function used by the plugin
the filter function
Get the geocoding endpoint the plugin is currently set to
the geocoding API
Get the function used to render the results dropdown
the render function
Subscribe to events that happen within the plugin.
name of event. Available events and the data passed into their respective event objects are:
Emitted when the input is cleared
{ query } Emitted when the geocoder is looking up a query
{ results } Fired when the geocoder returns a response
{ result } Fired when input is set
{ error } Error as string
function that's called when the event is emitted.
Subscribe to events that happen within the plugin only once.
Event name. Available events and the data passed into their respective event objects are:
Emitted when the input is cleared
{ query } Emitted when the geocoder is looking up a query
{ results } Fired when the geocoder returns a response
{ result } Fired when input is set
{ error } Error as string
a Promise that resolves when the event is emitted.
Set the filter function used by the plugin.
A function which accepts a CarmenGeojsonFeature to filter out results from the Geocoding API response before they are included in the suggestions list. Return true
to keep the item, false
otherwise.
Set the geocoding api used by the plugin.
Get the language to use in UI elements and when making search requests
Look first at the explicitly set options otherwise use the browser's language settings
Optional
language: stringSpecify the language to use for response text and query result weighting. Options are IETF language tags comprised of a mandatory ISO 639-1 language code and optionally one or more IETF subtags for country or script. More than one value can also be specified, separated by commas.
Set the render function used in the results dropdown
The function to use as a render function. This function accepts a single CarmenGeojsonFeature object as input and returns a string.
A geocoder component that works with maplibre