Skip to content

Commit 485e013

Browse files
committed
Add support for custom profiles.
1 parent 0fe2d32 commit 485e013

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

src/actions/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function fetchDirections() {
6363
options.push('overview=full');
6464
options.push('access_token=' + accessToken);
6565
request.abort();
66-
request.open('GET', `${api}mapbox/${profile}/${query}.json?${options.join('&')}`, true);
66+
request.open('GET', `${api}${profile}/${query}.json?${options.join('&')}`, true);
6767

6868
request.onload = () => {
6969
if (request.status >= 200 && request.status < 400) {

src/controls/inputs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default class Inputs {
8383

8484
var destinationEl = this.destinationInput.onAdd();
8585
this.container.querySelector('#mapbox-directions-destination-input').appendChild(destinationEl);
86-
86+
8787

8888
this.originInput.on('result', (e) => {
8989
const coords = e.result.center;
@@ -105,7 +105,7 @@ export default class Inputs {
105105
const profiles = this.container.querySelectorAll('input[type="radio"]');
106106
Array.prototype.forEach.call(profiles, (el) => {
107107
el.addEventListener('change', () => {
108-
setProfile(el.id.replace('mapbox-directions-profile-', ''));
108+
setProfile(el.value);
109109
});
110110
});
111111

src/directions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import Instructions from './controls/instructions';
2323
* @param {Array} [options.styles] 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/).
2424
* @param {String} [options.accessToken=null] Required unless `mapboxgl.accessToken` is set globally
2525
* @param {Boolean} [options.interactive=true] Enable/Disable mouse or touch interactivity from the plugin
26-
* @param {String} [options.profile="driving-traffic"] Routing profile to use. Options: `driving-traffic`, `driving`, `walking`, `cycling`
26+
* @param {String} [options.profile="mapbox/driving-traffic"] Routing profile to use. Options: `mapbox/driving-traffic`, `mapbox/driving`, `mapbox/walking`, `mapbox/cycling`
2727
* @param {Boolean} [options.alternatives=true] Whether to enable alternatives.
2828
* @param {String} [options.unit="imperial"] Measurement system to be used in navigation instructions. Options: `imperial`, `metric`
2929
* @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).
@@ -35,7 +35,7 @@ import Instructions from './controls/instructions';
3535
* var directions = new MapboxDirections({
3636
* accessToken: 'YOUR-MAPBOX-ACCESS-TOKEN',
3737
* unit: 'metric',
38-
* profile: 'cycling'
38+
* profile: 'mapbox/cycling'
3939
* });
4040
* // add to your mapboxgl map
4141
* map.addControl(directions);

src/reducers/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import deepAssign from 'deep-assign';
44
const initialState = {
55
// Options set on initialization
66
api: 'https://api.mapbox.com/directions/v5/',
7-
profile: 'driving-traffic',
7+
profile: 'mapbox/driving-traffic',
88
alternatives: false,
99
unit: 'imperial',
1010
proximity: false,

src/templates/inputs.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,32 @@
2424
id='mapbox-directions-profile-driving-traffic'
2525
type='radio'
2626
name='profile'
27-
<% if (profile === 'driving-traffic') { %>checked<% } %>
27+
value='mapbox/driving-traffic'
28+
<% if (profile === 'mapbox/driving-traffic') { %>checked<% } %>
2829
/>
2930
<label for='mapbox-directions-profile-driving-traffic'>Traffic</label>
3031
<input
3132
id='mapbox-directions-profile-driving'
3233
type='radio'
3334
name='profile'
34-
<% if (profile === 'driving') { %>checked<% } %>
35+
value='mapbox/driving'
36+
<% if (profile === 'mapbox/driving') { %>checked<% } %>
3537
/>
3638
<label for='mapbox-directions-profile-driving'>Driving</label>
3739
<input
3840
id='mapbox-directions-profile-walking'
3941
type='radio'
4042
name='profile'
41-
<% if (profile === 'walking') { %>checked<% } %>
43+
value='mapbox/walking'
44+
<% if (profile === 'mapbox/walking') { %>checked<% } %>
4245
/>
4346
<label for='mapbox-directions-profile-walking'>Walking</label>
4447
<input
4548
id='mapbox-directions-profile-cycling'
4649
type='radio'
4750
name='profile'
48-
<% if (profile === 'cycling') { %>checked<% } %>
51+
value='mapbox/cycling'
52+
<% if (profile === 'mapbox/cycling') { %>checked<% } %>
4953
/>
5054
<label for='mapbox-directions-profile-cycling'>Cycling</label>
5155
</div>

0 commit comments

Comments
 (0)