Skip to content

Commit

Permalink
A little bit reworked source
Browse files Browse the repository at this point in the history
  • Loading branch information
underoot committed Jan 15, 2024
1 parent af5d590 commit 7e8c78a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/constants/action_types.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const DESTINATION = 'DESTINATION';
export const DESTINATION_CLEAR = 'DESTINATION_CLEAR';
export const DESTINATION_QUERY = 'DESTINATION_QUERY';
export const DESTINATION_QUERY_START = 'DESTINATION_QUERY_START';
export const DESTINATION_FROM_COORDINATES = 'DESTINATION_FROM_COORDINATES';
export const DIRECTIONS = 'DIRECTIONS';
export const DIRECTIONS_PROFILE = 'DIRECTIONS_PROFILE';
Expand Down
9 changes: 1 addition & 8 deletions src/controls/instructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,7 @@ export default class Instructions {

if (directions.length && shouldRender) {
const direction = this.directions = directions[routeIndex];
const allSteps = direction.legs.reduce((steps, leg, idx) => {
if (idx > 0) {
steps[steps.length - 1].maneuver.type = 'waypoint';
leg.steps[0].maneuver.type = '';
}

return steps.concat(leg.steps)
}, []);
const allSteps = utils.getAllSteps(direction);

if (compile) {
direction.legs.forEach(function(leg) {
Expand Down
9 changes: 1 addition & 8 deletions src/directions.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,7 @@ export default class MapboxDirections {
return c.reverse();
});

const allSteps = feature.legs.reduce((steps, leg, idx) => {
if (idx > 0) {
steps[steps.length - 1].maneuver.type = 'waypoint';
leg.steps[0].maneuver.type = '';
}

return steps.concat(leg.steps)
}, []);
const allSteps = utils.getAllSteps(feature);

decoded.forEach(function(c, i) {
var previous = features[features.length - 1];
Expand Down
13 changes: 12 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ function createPoint(coordinates, properties) {
};
}

function getAllSteps(feature) {
return feature.legs.reduce((steps, leg, idx) => {
if (idx > 0) {
steps[steps.length - 1].maneuver.type = 'waypoint';
leg.steps[0].maneuver.type = '';
}

return steps.concat(leg.steps)
}, []);
}

const format = {
duration(s) {
var m = Math.floor(s / 60),
Expand Down Expand Up @@ -62,4 +73,4 @@ const format = {
}
};

export default { format, coordinateMatch, createPoint, validCoords, wrap, roundWithOriginalPrecision };
export default { format, coordinateMatch, createPoint, validCoords, wrap, roundWithOriginalPrecision, getAllSteps };
2 changes: 1 addition & 1 deletion test/test.instructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('Directions#instructionControl', tt => {
directions.setDestination([-77.3, 41]);
directions.on('route', once((e) => {
t.ok(e.route, 'route is emitted');
t.ok(container.querySelector('.directions-control-directions').textContent, 'instructions are shown');
t.ok(container.querySelector('.directions-icon-arrive'), 'instructions are shown');
}));
});

Expand Down

0 comments on commit 7e8c78a

Please sign in to comment.