Skip to content

Commit

Permalink
Merge pull request #135 from mapbox/alternatives
Browse files Browse the repository at this point in the history
Disable alternatives by default.
  • Loading branch information
willwhite authored Jul 29, 2017
2 parents 46cd036 + c32a772 commit 99b1bc9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 26 deletions.
66 changes: 43 additions & 23 deletions API.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
# MapboxDirections
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

- [MapboxDirections](#mapboxdirections)
- [onRemove](#onremove)
- [interactive](#interactive)
- [getOrigin](#getorigin)
- [setOrigin](#setorigin)
- [getDestination](#getdestination)
- [setDestination](#setdestination)
- [reverse](#reverse)
- [addWaypoint](#addwaypoint)
- [setWaypoint](#setwaypoint)
- [removeWaypoint](#removewaypoint)
- [getWaypoints](#getwaypoints)
- [removeRoutes](#removeroutes)
- [on](#on)

## MapboxDirections

The Directions control

**Parameters**

- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `options.styles` **\[[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)]** Override default layer properties of the [directions source](https://github.com/mapbox/mapbox-gl-directions/blob/master/src/directions_style.js). Documentation for each property are specified in the [Mapbox GL Style Reference](https://www.mapbox.com/mapbox-gl-style-spec/).
- `options.accessToken` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** Required unless `mapboxgl.accessToken` is set globally (optional, default `null`)
- `options.interactive` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** Enable/Disable mouse or touch interactivity from the plugin (optional, default `true`)
- `options.profile` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** Routing profile to use. Options: `driving-traffic`, `driving`, `walking`, `cycling` (optional, default `"driving-traffic"`)
- `options.unit` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** Measurement system to be used in navigation instructions. Options: `imperial`, `metric` (optional, default `"imperial"`)
- `options.geocoder` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)]** Pass options available to mapbox-gl-geocoder as [documented here](https://github.com/mapbox/mapbox-gl-geocoder/blob/master/API.md#mapboxglgeocoder).
- `options.controls` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)]**
- `options.controls.inputs` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** Hide or display the inputs control. (optional, default `true`)
- `options.controls.instructions` **\[[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** Hide or display the instructions control. (optional, default `true`)
- `options.styles` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)?** Override default layer properties of the [directions source](https://github.com/mapbox/mapbox-gl-directions/blob/master/src/directions_style.js). Documentation for each property are specified in the [Mapbox GL Style Reference](https://www.mapbox.com/mapbox-gl-style-spec/).
- `options.accessToken` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Required unless `mapboxgl.accessToken` is set globally (optional, default `null`)
- `options.interactive` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Enable/Disable mouse or touch interactivity from the plugin (optional, default `true`)
- `options.profile` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Routing profile to use. Options: `driving-traffic`, `driving`, `walking`, `cycling` (optional, default `"driving-traffic"`)
- `options.alternatives` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether to enable alternatives. (optional, default `true`)
- `options.unit` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Measurement system to be used in navigation instructions. Options: `imperial`, `metric` (optional, default `"imperial"`)
- `options.geocoder` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Pass options available to mapbox-gl-geocoder as [documented here](https://github.com/mapbox/mapbox-gl-geocoder/blob/master/API.md#mapboxglgeocoder).
- `options.controls` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)?**
- `options.controls.inputs` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Hide or display the inputs control. (optional, default `true`)
- `options.controls.instructions` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Hide or display the instructions control. (optional, default `true`)

**Examples**

Expand All @@ -30,7 +50,7 @@ map.addControl(directions);

Returns **[MapboxDirections](#mapboxdirections)** `this`

## onRemove
### 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.
Expand All @@ -41,7 +61,7 @@ which is the recommended method to remove controls.

Returns **Control** `this`

## interactive
### interactive

Turn on or off interactivity

Expand All @@ -51,13 +71,13 @@ Turn on or off interactivity

Returns **[MapboxDirections](#mapboxdirections)** this

## getOrigin
### getOrigin

Returns the origin of the current route.

Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** origin

## setOrigin
### setOrigin

Sets origin. _Note:_ calling this method requires the [map load event](https://www.mapbox.com/mapbox-gl-js/api/#Map.load)
to have run.
Expand All @@ -68,13 +88,13 @@ to have run.

Returns **[MapboxDirections](#mapboxdirections)** this

## getDestination
### getDestination

Returns the destination of the current route.

Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** destination

## setDestination
### setDestination

Sets destination. _Note:_ calling this method requires the [map load event](https://www.mapbox.com/mapbox-gl-js/api/#Map.load)
to have run.
Expand All @@ -85,13 +105,13 @@ to have run.

Returns **[MapboxDirections](#mapboxdirections)** this

## reverse
### reverse

Swap the origin and destination.

Returns **[MapboxDirections](#mapboxdirections)** this

## addWaypoint
### addWaypoint

Add a waypoint to the route. _Note:_ calling this method requires the
[map load event](https://www.mapbox.com/mapbox-gl-js/api/#Map.load) to have run.
Expand All @@ -103,7 +123,7 @@ Add a waypoint to the route. _Note:_ calling this method requires the

Returns **[MapboxDirections](#mapboxdirections)** this;

## setWaypoint
### setWaypoint

Change the waypoint at a given index in the route. _Note:_ calling this
method requires the [map load event](https://www.mapbox.com/mapbox-gl-js/api/#Map.load)
Expand All @@ -116,7 +136,7 @@ to have run.

Returns **[MapboxDirections](#mapboxdirections)** this;

## removeWaypoint
### removeWaypoint

Remove a waypoint from the route.

Expand All @@ -126,19 +146,19 @@ Remove a waypoint from the route.

Returns **[MapboxDirections](#mapboxdirections)** this;

## getWaypoints
### getWaypoints

Fetch all current waypoints in a route.

Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** waypoints

## removeRoutes
### removeRoutes

Removes all routes and waypoints from the map.

Returns **[MapboxDirections](#mapboxdirections)** this;

## on
### on

Subscribe to events that happen within the plugin.

Expand Down
4 changes: 2 additions & 2 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ function setHoverMarker(feature) {

function fetchDirections() {
return (dispatch, getState) => {
const { api, accessToken, routeIndex, profile } = getState();
const { api, accessToken, routeIndex, profile, alternatives } = getState();
const query = buildDirectionsQuery(getState);

// Request params
var options = [];
options.push('geometries=polyline');
options.push('alternatives=true');
if (alternatives) options.push('alternatives=true');
options.push('steps=true');
options.push('overview=full');
options.push('access_token=' + accessToken);
Expand Down
3 changes: 2 additions & 1 deletion src/directions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Instructions from './controls/instructions';
* @param {String} [options.accessToken=null] Required unless `mapboxgl.accessToken` is set globally
* @param {Boolean} [options.interactive=true] Enable/Disable mouse or touch interactivity from the plugin
* @param {String} [options.profile="driving-traffic"] Routing profile to use. Options: `driving-traffic`, `driving`, `walking`, `cycling`
* @param {Boolean} [options.alternatives=true] Whether to enable alternatives.
* @param {String} [options.unit="imperial"] Measurement system to be used in navigation instructions. Options: `imperial`, `metric`
* @param {Object} [options.geocoder] Pass options available to mapbox-gl-geocoder as [documented here](https://github.com/mapbox/mapbox-gl-geocoder/blob/master/API.md#mapboxglgeocoder).
* @param {Object} [options.controls]
Expand Down Expand Up @@ -109,7 +110,7 @@ export default class MapboxDirections {
}

mapState() {
const { profile, styles, interactive } = store.getState();
const { profile, alternatives, styles, interactive } = store.getState();

// Emit any default or option set config
this.actions.eventEmit('profile', { profile });
Expand Down
1 change: 1 addition & 0 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const initialState = {
// Options set on initialization
api: 'https://api.mapbox.com/directions/v5/',
profile: 'driving-traffic',
alternatives: false,
unit: 'imperial',
proximity: false,
styles: [],
Expand Down

0 comments on commit 99b1bc9

Please sign in to comment.