Skip to content

Latest commit

 

History

History
112 lines (75 loc) · 6.68 KB

API.md

File metadata and controls

112 lines (75 loc) · 6.68 KB

Table of Contents

MapboxGeocoder

A geocoder component using Mapbox Geocoding API

Parameters

  • options Object
    • options.accessToken String Required.
    • options.zoom Number On geocoded result what zoom level should the map animate to when a bbox isn't found in the response. If a bbox is found the map will fit to the bbox. (optional, default 16)
    • options.flyTo Boolean If false, animating the map to a selected result is disabled. (optional, default true)
    • 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, default false)
    • 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, default 2)
    • options.limit Number Maximum number of results to show. (optional, default 5)
    • 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. Return true 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

query

Set & query the input

Parameters

  • searchInput string location name or other search input

Returns MapboxGeocoder this

setInput

Set input

Parameters

  • searchInput string location name or other search input

Returns MapboxGeocoder this

setProximity

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

getProximity

Get proximity

Returns Object The geocoder proximity

on

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:- clear Emitted 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
  • fn Function function that's called when the event is emitted.

Returns MapboxGeocoder this;

off

Remove an event

Parameters

  • type String Event name.
  • fn Function Function that should unsubscribe to the event emitted.

Returns MapboxGeocoder this