Skip to content

Latest commit

 

History

History
187 lines (123 loc) · 11.1 KB

API.md

File metadata and controls

187 lines (123 loc) · 11.1 KB

Table of Contents

MapboxDirections

The Directions control

Parameters

  • options Object
    • options.styles Array? Override default layer properties of the directions source. Documentation for each property are specified in the Mapbox GL Style Reference.
    • options.accessToken String Required unless mapboxgl.accessToken is set globally (optional, default null)
    • options.api String Override default routing endpoint url (optional, default "https://api.mapbox.com/directions/v5/")
    • options.interactive Boolean Enable/Disable mouse or touch interactivity from the plugin (optional, default true)
    • options.profile String Routing profile to use. Options: mapbox/driving-traffic, mapbox/driving, mapbox/walking, mapbox/cycling (optional, default "mapbox/driving-traffic")
    • options.alternatives Boolean Whether to enable alternatives. (optional, default false)
    • options.congestion Boolean Whether to enable congestion along the route line. (optional, default false)
    • options.unit String Measurement system to be used in navigation instructions. Options: imperial, metric (optional, default "imperial")
    • options.compile Function Provide a custom function for generating instruction, compatible with osrm-text-instructions. (optional, default null)
    • options.geocoder Object? Accepts an object containing the query parameters as documented here.
    • options.controls Object?
      • options.controls.inputs Boolean Hide or display the inputs control. (optional, default true)
      • options.controls.instructions Boolean Hide or display the instructions control. (optional, default true)
      • options.controls.profileSwitcher Boolean Hide or display the default profile switch with options for traffic, driving, walking and cycling. (optional, default true)
    • options.zoom Number If no bbox exists from the geocoder result, the zoom you set here will be used in the flyTo. (optional, default 16)
    • options.language String The language of returned turn-by-turn text instructions. See supported languages : https://docs.mapbox.com/api/navigation/#instructions-languages (optional, default "en")
    • options.placeholderOrigin String If set, this text will appear as the placeholder attribute for the origin input element. (optional, default "Choose a starting place")
    • options.placeholderDestination String If set, this text will appear as the placeholder attribute for the destination input element. (optional, default "Choose destination")
    • options.flyTo Boolean If false, animating the map to a selected result is disabled. (optional, default true)
    • options.exclude String Exclude certain road types from routing. The default is to not exclude anything. Search for exclude in optional parameters: https://docs.mapbox.com/api/navigation/#retrieve-directions (optional, default null)
    • options.routePadding (number | PaddingOptions) Specify padding surrounding route. A single number of pixels or a PaddingOptions object. (optional, default 80)

Examples

var MapboxDirections = require('../src/index');
var directions = new MapboxDirections({
  accessToken: 'YOUR-MAPBOX-ACCESS-TOKEN',
  unit: 'metric',
  profile: 'mapbox/cycling'
});
// add to your mapboxgl map
map.addControl(directions);

Returns MapboxDirections this

onRemove

Removes the control from the map it has been added to. This is called by map.removeControl, which is the recommended method to remove controls.

Parameters

  • map

Returns Control this

interactive

Turn on or off interactivity

Parameters

  • state Boolean sets interactivity based on a state of true or false.

Returns MapboxDirections this

getOrigin

Returns the origin of the current route.

Returns Object origin

setOrigin

Sets origin. Note: calling this method requires the map load event to have run.

Parameters

  • query (Array<number> | String) An array of coordinates [lng, lat] or location name as a string.

Returns MapboxDirections this

getDestination

Returns the destination of the current route.

Returns Object destination

setDestination

Sets destination. Note: calling this method requires the map load event to have run.

Parameters

  • query (Array<number> | String) An array of coordinates [lng, lat] or location name as a string.

Returns MapboxDirections this

reverse

Swap the origin and destination.

Returns MapboxDirections this

addWaypoint

Add a waypoint to the route. Note: calling this method requires the map load event to have run.

Parameters

  • index Number position waypoint should be placed in the waypoint array
  • waypoint (Array<number> | Point) can be a GeoJSON Point Feature or [lng, lat] coordinates.

Returns MapboxDirections this;

setWaypoint

Change the waypoint at a given index in the route. Note: calling this method requires the map load event to have run.

Parameters

  • index Number indexed position of the waypoint to update
  • waypoint (Array<number> | Point) can be a GeoJSON Point Feature or [lng, lat] coordinates.

Returns MapboxDirections this;

removeWaypoint

Remove a waypoint from the route.

Parameters

  • index Number position in the waypoints array.

Returns MapboxDirections this;

getWaypoints

Fetch all current waypoints in a route.

Returns Array waypoints

removeRoutes

Removes all routes and waypoints from the map.

Returns MapboxDirections this;

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 { type: } Type is one of 'origin' or 'destination'
    • loading { type: } Type is one of 'origin' or 'destination'
    • profile { profile } Profile is one of 'driving', 'walking', or 'cycling'
    • origin { feature } Fired when origin is set
    • destination { feature } Fired when destination is set
    • route { route } Fired when a route is updated
    • error { error } Error as string
  • fn Function function that's called when the event is emitted.

Returns MapboxDirections this;