A geocoder component using Mapbox Geocoding API
Parameters
optionsObjectoptions.accessTokenString Required.options.zoomNumber On geocoded result what zoom level should the map animate to when abboxisn't found in the response. If abboxis found the map will fit to thebbox. (optional, default16)options.flyToBoolean If false, animating the map to a selected result is disabled. (optional, defaulttrue)options.placeholderString Override the default placeholder attribute value. (optional, default"Search")options.proximityObject? 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.trackProximityBoolean If true, the geocoder proximity will automatically update based on the map view. (optional, defaultfalse)options.bboxArray? 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.typesstring? 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.countrystring? a comma separated list of country codes to limit results to specified country or countries.options.minLengthNumber Minimum number of characters to enter before results are shown. (optional, default2)options.limitNumber Maximum number of results to show. (optional, default5)options.languagestring? 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.filterFunction? 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. Returntrueto keep the item,falseotherwise.options.localGeocoderFunction? 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
searchInputstring location name or other search input
Returns MapboxGeocoder this
Set input
Parameters
searchInputstring location name or other search input
Returns MapboxGeocoder this
Set proximity
Parameters
proximityObject 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
typeString 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
fnFunction function that's called when the event is emitted.
Returns MapboxGeocoder this;
Remove an event
Parameters
Returns MapboxGeocoder this