A geocoder component using Mapbox Geocoding API
Parameters
options
Objectoptions.accessToken
String Required.options.zoom
Number On geocoded result what zoom level should the map animate to when abbox
isn't found in the response. If abbox
is found the map will fit to thebbox
. (optional, default16
)options.flyTo
Boolean If false, animating the map to a selected result is disabled. (optional, defaulttrue
)options.placeholder
String Override the default placeholder attribute value. (optional, default"Search"
)options.proximity
Object? a proximity argument: this is a geographical point given as an object with latitude and longitude properties. Search results closer to this point will be given higher priority.options.trackProximity
Boolean If true, the geocoder proximity will automatically update based on the map view. (optional, defaultfalse
)options.bbox
Array? a bounding box argument: this is a bounding box given as an array in the format [minX, minY, maxX, maxY]. Search results will be limited to the bounding box.options.types
string? a comma seperated list of types that filter results to match those specified. See https://www.mapbox.com/developers/api/geocoding/#filter-type for available types.options.country
string? a comma separated list of country codes to limit results to specified country or countries.options.minLength
Number Minimum number of characters to enter before results are shown. (optional, default2
)options.limit
Number Maximum number of results to show. (optional, default5
)options.language
string? Specify 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.options.filter
Function? A function which accepts a Feature in the Carmen GeoJSON format to filter out results from the Geocoding API response before they are included in the suggestions list. Returntrue
to keep the item,false
otherwise.options.localGeocoder
Function? A function accepting the query string which performs local geocoding to supplement results from the Mapbox Geocoding API. Expected to return an Array of GeoJSON Features in the Carmen GeoJSON format.
Examples
var geocoder = new MapboxGeocoder({ accessToken: mapboxgl.accessToken });
map.addControl(geocoder);
Returns MapboxGeocoder this
Set & query the input
Parameters
searchInput
string location name or other search input
Returns MapboxGeocoder this
Set input
Parameters
searchInput
string location name or other search input
Returns MapboxGeocoder this
Set proximity
Parameters
proximity
Object The new options.proximity value. This is a geographical point given as an object with latitude and longitude properties.
Returns MapboxGeocoder this
Get proximity
Returns Object The geocoder proximity
Subscribe to events that happen within the plugin.
Parameters
type
String name of event. Available events and the data passed into their respective event objects are:- clearEmitted when the input is cleared
- loading
{ query } Emitted when the geocoder is looking up a query
- results
{ results } Fired when the geocoder returns a response
- result
{ result } Fired when input is set
- error
{ error } Error as string
- loading
fn
Function function that's called when the event is emitted.
Returns MapboxGeocoder this;
Remove an event
Parameters
Returns MapboxGeocoder this