@@ -39,13 +39,76 @@ export default class Instructions {
3939 if ( directions . length && shouldRender ) {
4040 const direction = this . directions = directions [ routeIndex ] ;
4141
42- if ( compile ) {
43- direction . legs . forEach ( function ( leg ) {
44- leg . steps . forEach ( function ( step ) {
42+ direction . legs . forEach ( function ( leg ) {
43+ leg . steps . forEach ( function ( step ) {
44+ step . lanes = stepToLanes ( step ) ;
45+ if ( compile ) {
4546 step . maneuver . instruction = compile ( 'en' , step ) ;
46- } ) ;
47+ }
4748 } ) ;
48- }
49+ } ) ;
50+
51+ function stepToLanes ( step ) {
52+ var lanes = step . intersections [ 0 ] . lanes ;
53+
54+ if ( ! lanes ) return [ ] ;
55+
56+ var maneuver = step . maneuver . modifier || '' ;
57+
58+ return lanes . map ( function ( lane , index ) {
59+ var classes = [ ] ;
60+ if ( ! lane . valid ) classes . push ( [ 'invalid' ] ) ;
61+
62+ // check maneuver direction matches this lane one(s)
63+ var maneuverIndication = lane . indications . indexOf ( maneuver ) ;
64+ if ( maneuverIndication === - 1 ) {
65+ // check non-indicated lane to allow straight, right turn from last lane and left turn for first lane
66+ if ( ( lane . indications [ 0 ] === 'none' || lane . indications [ 0 ] === '' ) && (
67+ maneuver === 'straight' ||
68+ ( index === 0 && maneuver . slice ( - 4 ) === 'left' ) ||
69+ ( index === ( lanes . length - 1 ) && maneuver . slice ( - 5 ) === 'right' ) ) ) {
70+ maneuverIndication = 0 ;
71+ } else if ( maneuver . slice ( 0 , 7 ) === 'slight ' ) {
72+ // try to exclude 'slight' modifier
73+ maneuverIndication = lane . indications . indexOf ( maneuver . slice ( 7 ) ) ;
74+ }
75+ }
76+ var indication = ( maneuverIndication === - 1 ) ? lane . indications [ 0 ] : maneuver ;
77+
78+ var icon ;
79+ switch ( indication ) {
80+ case 'right' :
81+ icon = 'right' ;
82+ break ;
83+ case 'sharp right' :
84+ icon = 'sharp-right' ;
85+ break ;
86+ case 'slight right' :
87+ icon = 'slight-right' ;
88+ break ;
89+ case 'left' :
90+ icon = 'left' ;
91+ break ;
92+ case 'sharp left' :
93+ icon = 'sharp-left' ;
94+ break ;
95+ case 'slight left' :
96+ icon = 'slight-left' ;
97+ break ;
98+ case 'uturn' :
99+ icon = 'u-turn' ;
100+ break ;
101+ //case 'straight':
102+ //case 'none':
103+ default :
104+ icon = 'straight' ;
105+ break ;
106+ }
107+ classes . push ( 'directions-icon-' + icon ) ;
108+
109+ return classes . join ( ' ' ) ;
110+ } ) ;
111+ }
49112
50113 this . container . innerHTML = instructionsTemplate ( {
51114 routeIndex,
0 commit comments