Skip to content

Commit

Permalink
Make route padding configurable (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mal Wood-Santoro authored Jun 30, 2020
1 parent 5cdd312 commit 0fb4dcc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/controls/inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,18 @@ export default class Inputs {
}

animateToCoordinates(mode, coords) {
const { origin, destination } = this.store.getState();

const { origin, destination, routePadding } = this.store.getState();
if (origin.geometry &&
destination.geometry &&
!isEqual(origin.geometry, destination.geometry)) {

// Animate map to fit bounds.
const bb = extent({
type: 'FeatureCollection',
features: [origin, destination]
});

this._map.fitBounds([[bb[0], bb[1]], [bb[2], bb[3]]], { padding: 80 });
this._map.fitBounds([[bb[0], bb[1]], [bb[2], bb[3]]], {padding: routePadding});
} else {
this._map.flyTo({ center: coords });
}
Expand Down
1 change: 1 addition & 0 deletions src/directions.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import Instructions from './controls/instructions';
* @param {String} [options.placeholderDestination="Choose destination"] If set, this text will appear as the placeholder attribute for the destination input element.
* @param {Boolean} [options.flyTo=true] If false, animating the map to a selected result is disabled.
* @param {String} [options.exclude=null] 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
* @param {number | PaddingOptions} [options.routePadding=80] Specify padding surrounding route. A single number of pixels or a [PaddingOptions](https://docs.mapbox.com/mapbox-gl-js/api/#paddingoptions) object.
* @example
* var MapboxDirections = require('../src/index');
* var directions = new MapboxDirections({
Expand Down
3 changes: 2 additions & 1 deletion src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ const initialState = {

// Directions data
directions: [],
routeIndex: 0
routeIndex: 0,
routePadding: 80
};

function data(state = initialState, action) {
Expand Down

0 comments on commit 0fb4dcc

Please sign in to comment.