ÿþ/ /   i n d e x . j s  
 / *  
 C o p y r i g h t   2 0 0 8   G o o g l e   I n c .  
  
 L i c e n s e d   u n d e r   t h e   A p a c h e   L i c e n s e ,   V e r s i o n   2 . 0   ( t h e   " L i c e n s e " ) ;  
 y o u   m a y   n o t   u s e   t h i s   f i l e   e x c e p t   i n   c o m p l i a n c e   w i t h   t h e   L i c e n s e .  
 Y o u   m a y   o b t a i n   a   c o p y   o f   t h e   L i c e n s e   a t  
  
           h t t p : / / w w w . a p a c h e . o r g / l i c e n s e s / L I C E N S E - 2 . 0  
  
 U n l e s s   r e q u i r e d   b y   a p p l i c a b l e   l a w   o r   a g r e e d   t o   i n   w r i t i n g ,   s o f t w a r e  
 d i s t r i b u t e d   u n d e r   t h e   L i c e n s e   i s   d i s t r i b u t e d   o n   a n   " A S   I S "   B A S I S ,  
 W I T H O U T   W A R R A N T I E S   O R   C O N D I T I O N S   O F   A N Y   K I N D ,   e i t h e r   e x p r e s s   o r   i m p l i e d .  
 S e e   t h e   L i c e n s e   f o r   t h e   s p e c i f i c   l a n g u a g e   g o v e r n i n g   p e r m i s s i o n s   a n d  
 l i m i t a t i o n s   u n d e r   t h e   L i c e n s e .  
 * /  
  
 f u n c t i o n   s t a r t 1 ( )   {  
  
 D S _ c o n t r o l S i m u l a t o r ( ' s t a r t ' ) ;  
  
 D S _ c o n t r o l S i m u l a t o r ( ' p a u s e ' ) ;  
 D S _ c o n t r o l S i m u l a t o r ( ' s t a r t ' ) ;  
 }  
  
 / * *  
   *   @ f i l e o v e r v i e w   T h i s   i s   t h e   m a i n   J a v a S c r i p t   f i l e   f o r   t h e   D r i v i n g   S i m u l a t o r  
   *   @ a u t h o r   R o m a n   N u r i k  
   *   @ s u p p o r t e d   T e s t e d   i n   I E 6 +   a n d   F F 2 +  
   * /  
  
 / * *  
   *   T h e   g l o b a l   D i r e c t i o n s   o b j e c t   f o r   t h e   c u r r e n t l y   l o a d e d   d i r e c t i o n s  
   *   @ t y p e   { g o o g l e . m a p s . D i r e c t i o n s }  
   * /  
 v a r   D S _ d i r e c t i o n s   =   n u l l ;  
  
 / * *  
   *   T h e   l i s t   o f   d r i v i n g   s t e p s   l o a d e d   f r o m   g o o g l e . m a p s . D i r e c t i o n s  
   *   @ t y p e   { A r r a y . < O b j e c t > }  
   * /  
 v a r   D S _ s t e p s   =   [ ] ;  
  
 / * *  
   *   T h e   l i s t   o f   p a t h   v e r t i c e s   a n d   t h e i r   m e t a d a t a   f o r   t h e   d r i v i n g   d i r e c t i o n s  
   *   @ t y p e   { A r r a y . < O b j e c t > }  
   * /  
 v a r   D S _ p a t h   =   [ ] ;   / /   e n t i r e   d r i v i n g   p a t h  
  
 / * *  
   *   T h e   g l o b a l   s i m u l a t o r   i n s t a n c e   t h a t   c o n d u c t s   t h e   d r i v i n g   s i m u l a t i o n  
   *   @ t y p e   { D D S i m u l a t o r }  
   * /  
 v a r   D S _ s i m u l a t o r ;   / /   i n s t a n c e   o f   t h e   D D S i m u l a t o r   c l a s s  
  
 / * *  
   *   T h e   c a r   m a r k e r   t h a t   a p p e a r s   o n   t h e   r e f e r e n c e   m a p   t o   t h e   r i g h t   o f   t h e   m a i n  
   *   s i m u l a t i o n   s c r e e n  
   *   @ t y p e   { g o o g l e . m a p s . M a r k e r }  
   * /  
 v a r   D S _ m a p M a r k e r   =   n u l l ;   / /   c a r   m a r k e r   o n   t h e   M a p  
  
 / * *  
   *   I n s t e a d   o f   u s i n g   t h e   p l u g i n ' s   b u i l t - i n   I D   s y s t e m ,   w h i c h   d o e s n ' t   l i k e   w h e n  
   *   I D s   a r e   r e u s e d ,   w e   w i l l   u s e   a   s e p a r a t e   d i c t i o n a r y   m a p p i n g   I D   t o   p l a c e m a r k  
   *   o b j e c t  
   *   @ t y p e   { O b j e c t }  
   * /  
 v a r   D S _ p l a c e m a r k s   =   { } ;  
  
 / * *  
   *   T h e   c a l l b a c k   f o r   w h e n   t h e   ' G o ! '   b u t t o n   i s   p r e s s e d .   T h i s   u s e s   t h e   M a p s   A P I ' s  
   *   D i r e c t i o n s   c l a s s   t o   g e t   t h e   r o u t e   a n d   p u l l   o u t   t h e   i n d i v i d u a l   r o u t e   s t e p s  
   *   i n t o   a   p a t h ,   w h i c h   i s   r e n d e r e d   a s   a   p o l y l i n e .  
   * /  
 f u n c t i o n   D S _ g o D i r e c t i o n s ( )   {  
     $ ( ' # r o u t e - d e t a i l s ' ) . e m p t y ( ) ;  
     $ ( ' # r o u t e - d e t a i l s ' ) . h t m l (  
             ' < s p a n   c l a s s = " l o a d i n g " > L o a d i n g   d i r e c t i o n s . . . < / s p a n > ' ) ;  
      
     i f   ( D S _ d i r e c t i o n s )  
         D S _ d i r e c t i o n s . c l e a r ( ) ;  
  
     D S _ d i r e c t i o n s   =   n e w   g o o g l e . m a p s . D i r e c t i o n s ( D S _ m a p ,   n u l l ) ;  
      
     g o o g l e . m a p s . E v e n t . a d d L i s t e n e r ( D S _ d i r e c t i o n s ,   ' l o a d ' ,   D S _ d i r e c t i o n s L o a d e d ) ;  
      
     g o o g l e . m a p s . E v e n t . a d d L i s t e n e r ( D S _ d i r e c t i o n s ,   ' e r r o r ' ,   f u n c t i o n ( )   {  
         $ ( ' # r o u t e - d e t a i l s ' ) . e m p t y ( ) ;  
         $ ( ' # r o u t e - d e t a i l s ' ) . h t m l (  
                 ' < s p a n   c l a s s = " e r r o r " > N o   d i r e c t i o n s   f o u n d . < / s p a n > ' ) ;  
     } ) ;  
      
     D S _ d i r e c t i o n s . l o a d ( ' f r o m :   '   +   $ ( ' # f r o m ' ) . v a l ( )   +   '   t o :   '   +   $ ( ' # t o ' ) . v a l ( ) ,  
             { g e t S t e p s :   t r u e ,   g e t P o l y l i n e :   t r u e } ) ;  
  
 }  
  
 / * *  
   *   I n i t i a l i z a t i o n   a f t e r   d i r e c t i o n s   a r e   l o a d e d  
   * /  
 f u n c t i o n   D S _ d i r e c t i o n s L o a d e d ( )   {  
     / /   D i r e c t i o n s   d a t a   h a s   l o a d e d  
     $ ( ' # r o u t e - d e t a i l s ' ) . e m p t y ( ) ;  
     v a r   r o u t e   =   D S _ d i r e c t i o n s . g e t R o u t e ( 0 ) ;  
     v a r   s t a r t   =   r o u t e . g e t S t a r t G e o c o d e ( ) ;  
     v a r   e n d   =   r o u t e . g e t E n d G e o c o d e ( ) ;  
      
     / /   b u i l d   t h e   p a t h   a n d   s t e p   a r r a y s   f r o m   t h e   g o o g l e . m a p s . D i r e c t i o n s   r o u t e  
     D S _ b u i l d P a t h S t e p A r r a y s ( ) ;  
      
     D S _ g e H e l p e r s . c l e a r F e a t u r e s ( ) ;  
     D S _ p l a c e m a r k s   =   { } ;  
  
    
  
      
     / /   c r e a t e   t h e   s t a r t i n g   p o i n t   p l a c e m a r k  
     D S _ p l a c e m a r k s [ ' s t a r t ' ]   =   D S _ g e H e l p e r s . c r e a t e P o i n t P l a c e m a r k (  
             n e w   g o o g l e . m a p s . L a t L n g ( s t a r t . P o i n t . c o o r d i n a t e s [ 1 ] ,  
                                                           s t a r t . P o i n t . c o o r d i n a t e s [ 0 ] ) ,  
             { d e s c r i p t i o n :   s t a r t . a d d r e s s ,   s t a n d a r d I c o n :   ' g r n - d i a m o n d ' } ) ;  
      
     / /   c r e a t e   t h e   p o i n t   p l a c e m a r k s   f o r   e a c h   s t e p   i n   t h e   d r i v i n g   d i r e c t i o n s  
     f o r   ( v a r   i   =   0 ;   i   <   D S _ s t e p s . l e n g t h ;   i + + )   {  
         v a r   s t e p   =   D S _ s t e p s [ i ] ;  
          
         v a r   p l a c e m a r k   =   D S _ g e H e l p e r s . c r e a t e P o i n t P l a c e m a r k (  
                 s t e p . l o c ,   { d e s c r i p t i o n :   s t e p . d e s c ,   s t a n d a r d I c o n :   ' r e d - c i r c l e ' } ) ;  
          
         D S _ p l a c e m a r k s [ ' s t e p - '   +   i ]   =   p l a c e m a r k ;    
          
         g o o g l e . e a r t h . a d d E v e n t L i s t e n e r ( p l a c e m a r k ,   ' c l i c k ' ,   f u n c t i o n ( e v e n t )   {  
             / /   m a t c h   u p   t h e   p l a c e m a r k   t o   i t s   i d   i n   t h e   d i c t i o n a r y   t o   f i n d   o u t  
             / /   w h i c h   s t e p   n u m b e r   i t   i s  
             v a r   i d   =   ' ' ;  
             f o r   ( k   i n   D S _ p l a c e m a r k s )  
                 i f   ( D S _ p l a c e m a r k s [ k ] . e q u a l s ( e v e n t . g e t T a r g e t ( ) ) )  
                     i d   =   k ;  
              
             v a r   s t e p N u m   =   p a r s e I n t ( i d . m a t c h ( / s t e p - ( \ d + ) / ) [ 1 ] ) ;  
              
             D S _ f l y T o S t e p ( s t e p N u m ) ;  
         } ) ;  
     }  
      
     / /   c r e a t e   t h e   e n d i n g   p o i n t   p l a c e m a r k  
     D S _ p l a c e m a r k s [ ' e n d ' ]   =   D S _ g e H e l p e r s . c r e a t e P o i n t P l a c e m a r k (  
             n e w   g o o g l e . m a p s . L a t L n g ( e n d . P o i n t . c o o r d i n a t e s [ 1 ] ,  
                                                           e n d . P o i n t . c o o r d i n a t e s [ 0 ] ) ,  
             { d e s c r i p t i o n :   e n d . a d d r e s s ,   s t a n d a r d I c o n :   ' g r n - d i a m o n d ' } ) ;  
      
     / /   b u i l d   t h e   r o u t e   L i n e S t r i n g ;   i n s t e a d   o f   c r e a t i n g   a   L i n e S t r i n g   u s i n g  
     / /   p u s h L a t L n g A l t ,   w h i c h   h a s   s o m e   p e r f o r m a n c e   i s s u e s ,   w e   w i l l   c o n s t r u c t   a  
     / /   K M L   b l o b   a n d   u s e   p a r s e K m l ( )    
     v a r   l i n e S t r i n g K m l   =   ' < L i n e S t r i n g > < c o o r d i n a t e s > \ n ' ;  
      
     f o r   ( v a r   i   =   0 ;   i   <   D S _ p a t h . l e n g t h ;   i + + )  
         l i n e S t r i n g K m l   + =  
                 D S _ p a t h [ i ] . l o c . l n g ( ) . t o S t r i n g ( )   +   ' , '   +  
                 D S _ p a t h [ i ] . l o c . l a t ( ) . t o S t r i n g ( )   +  
                 ' , 1 0 \ n ' ;  
      
     l i n e S t r i n g K m l   + =   ' < / c o o r d i n a t e s > < / L i n e S t r i n g > ' ;  
      
     / /   c r e a t e   t h e   r o u t e   p l a c e m a r k   f r o m   t h e   L i n e S t r i n g   K M L   b l o b  
     v a r   r o u t e L i n e S t r i n g   =   D S _ g e . p a r s e K m l ( l i n e S t r i n g K m l ) ;  
     r o u t e L i n e S t r i n g . s e t T e s s e l l a t e ( t r u e ) ;  
      
     v a r   r o u t e P l a c e m a r k   =   D S _ g e . c r e a t e P l a c e m a r k ( ' ' ) ;  
     r o u t e P l a c e m a r k . s e t G e o m e t r y ( r o u t e L i n e S t r i n g ) ;  
     D S _ p l a c e m a r k s [ ' r o u t e ' ]   =   r o u t e P l a c e m a r k ;  
      
     r o u t e P l a c e m a r k . s e t S t y l e S e l e c t o r (  
             D S _ g e H e l p e r s . c r e a t e L i n e S t y l e ( { w i d t h :   1 ,   c o l o r :   ' 0 0 0 0 0 0 0 0 ' } ) ) ;  
      
     D S _ g e . g e t F e a t u r e s ( ) . a p p e n d C h i l d ( r o u t e P l a c e m a r k ) ;  
  
     / /   b u i l d   t h e   l e f t   d i r e c t i o n s   l i s t  
     D S _ b u i l d D i r e c t i o n s L i s t ( ) ;  
      
     / /   f l y   t o   t h e   s t a r t   o f   t h e   r o u t e  
     D S _ f l y T o L a t L n g ( n e w   g o o g l e . m a p s . L a t L n g (  
                                   s t a r t . P o i n t . c o o r d i n a t e s [ 1 ] ,   s t a r t . P o i n t . c o o r d i n a t e s [ 0 ] ) ) ;  
  
      
     / /   e n a b l e   t h e   s i m u l a t o r   c o n t r o l s  
     $ ( ' # s i m u l a t o r - f o r m   i n p u t ' ) . r e m o v e A t t r ( ' d i s a b l e d ' ) ;  
      
     / /   d e s t r o y   t h e   s i m u l a t o r   i f   e x i s t s  
     i f   ( D S _ s i m u l a t o r )   {  
         D S _ s i m u l a t o r . d e s t r o y ( ) ;  
         D S _ s i m u l a t o r   =   n u l l ;  
     }  
 }  
  
 / * *  
   *   G e n e r a t e s   t h e   D S _ p a t h   a n d   D S _ s t e p   a r r a y s   f r o m   t h e   g l o b a l   D S _ d i r e c t i o n s  
   *   i n s t a n c e  
   *    
   *   N O T E :   o n l y   t h e   f i r s t   r o u t e   i s   u s e d  
   * /  
 f u n c t i o n   D S _ b u i l d P a t h S t e p A r r a y s ( )   {  
     / /   b e g i n   p r o c e s s i n g   t h e   d i r e c t i o n s '   s t e p s   a n d   p a t h  
     D S _ s t e p s   =   [ ] ;  
     D S _ p a t h   =   [ ] ;  
      
     v a r   p o l y l i n e   =   D S _ d i r e c t i o n s . g e t P o l y l i n e ( ) ;  
     v a r   r o u t e   =   D S _ d i r e c t i o n s . g e t R o u t e ( 0 ) ;  
     v a r   n u m P o l y l i n e V e r t i c e s   =   p o l y l i n e . g e t V e r t e x C o u n t ( ) ;  
     v a r   n u m S t e p s   =   r o u t e . g e t N u m S t e p s ( ) ;  
      
     f o r   ( v a r   i   =   0 ;   i   <   n u m S t e p s ;   i + + )   {  
         v a r   s t e p   =   r o u t e . g e t S t e p ( i ) ;  
          
         v a r   f i r s t P o l y l i n e I n d e x   =   s t e p . g e t P o l y l i n e I n d e x ( ) ;  
          
         v a r   l a s t P o l y l i n e I n d e x   =   - 1 ;  
         i f   ( i   = =   n u m S t e p s   -   1 )  
             l a s t P o l y l i n e I n d e x   =   n u m P o l y l i n e V e r t i c e s   -   1 ;  
         e l s e   {  
             / /   s u b t r a c t   2   b e c a u s e   t h e   l a s t   v e r t e x   o f   a   s t e p   i s   d u p l i c a t e d  
             / /   a s   t h e   f i r s t   v e r t e x   o f   t h e   n e x t   s t e p   i n   g o o g l e . m a p s . D i r e c t i o n s   r e s u l t s  
             l a s t P o l y l i n e I n d e x   =   r o u t e . g e t S t e p ( i   +   1 ) . g e t P o l y l i n e I n d e x ( )   -   2 ;  
         }  
          
         D S _ s t e p s . p u s h ( {  
             l o c :   s t e p . g e t L a t L n g ( ) ,  
             d e s c :   s t e p . g e t D e s c r i p t i o n H t m l ( ) ,  
             d i s t a n c e H t m l :   s t e p . g e t D i s t a n c e ( ) . h t m l ,  
             p a t h I n d e x :   D S _ p a t h . l e n g t h  
         } ) ;  
          
         v a r   s t e p D i s t a n c e   =   s t e p . g e t D i s t a n c e ( ) . m e t e r s ;  
         f o r   ( v a r   j   =   f i r s t P o l y l i n e I n d e x ;   j   < =   l a s t P o l y l i n e I n d e x ;   j + + )   {  
             v a r   l o c   =   p o l y l i n e . g e t V e r t e x ( j ) ;  
             v a r   d i s t a n c e   =   ( j   = =   n u m P o l y l i n e V e r t i c e s   -   1 )   ?  
                                           0   :   D S _ g e H e l p e r s . d i s t a n c e ( l o c ,   p o l y l i n e . g e t V e r t e x ( j   +   1 ) ) ;  
              
             D S _ p a t h . p u s h ( {  
                 l o c :   l o c ,  
                 s t e p :   i ,  
                 d i s t a n c e :   d i s t a n c e ,  
                  
                 / /   t h i s   s e g m e n t ' s   t i m e   d u r a t i o n   i s   p r o p o r t i o n a l   t o   i t s   l e n g t h   i n  
                 / /   r e l a t i o n   t o   t h e   l e n g t h   o f   t h e   s t e p  
                 d u r a t i o n :   s t e p . g e t D u r a t i o n ( ) . s e c o n d s   *   d i s t a n c e   /   s t e p D i s t a n c e  
             } ) ;  
         }  
     }  
 }  
  
 / * *  
   *   G e n e r a t e s   t h e   H T M L   e l e m e n t s   f o r   t h e   l e f t   d i r e c t i o n s   l i s t  
   *    
   *   N O T E :   o n l y   t h e   f i r s t   r o u t e   i s   u s e d  
   * /  
 f u n c t i o n   D S _ b u i l d D i r e c t i o n s L i s t ( )   {  
     v a r   s t a r t   =   D S _ d i r e c t i o n s . g e t R o u t e ( 0 ) . g e t S t a r t G e o c o d e ( ) ;  
     v a r   e n d   =   D S _ d i r e c t i o n s . g e t R o u t e ( 0 ) . g e t E n d G e o c o d e ( ) ;  
      
     $ ( ' # r o u t e - d e t a i l s ' ) . a p p e n d ( $ (  
             ' < d i v   i d = " d i r - s t a r t " > '   +   s t a r t . a d d r e s s   +   ' < / d i v > ' ) ) ;  
      
     $ ( ' # r o u t e - d e t a i l s ' ) . a p p e n d ( ' < o l > ' ) ;  
     f o r   ( v a r   i   =   0 ;   i   <   D S _ s t e p s . l e n g t h ;   i + + )   {  
         $ ( ' # r o u t e - d e t a i l s   o l ' ) . a p p e n d ( $ (  
                 ' < l i   c l a s s = " d i r - s t e p "   i d = " d i r - s t e p - '   +   i   +   ' " > '   +  
                 D S _ s t e p s [ i ] . d e s c   +  
                 ' < d i v   c l a s s = " n o t e " > '   +   D S _ s t e p s [ i ] . d i s t a n c e H t m l   +   ' < / d i v > '   +    
                 ' < / l i > ' ) ) ;  
     }  
      
     $ ( ' # r o u t e - d e t a i l s ' ) . a p p e n d ( $ (  
             ' < d i v   i d = " d i r - e n d " > '   +   e n d . a d d r e s s   +   ' < / d i v > ' ) ) ;  
      
     / /   h a n d l e   e v e n t s   o n   t h e   d i r e c t i o n s   l i s t  
     $ ( ' # d i r - s t a r t ' ) . c l i c k ( f u n c t i o n ( )   {  
         D S _ f l y T o L a t L n g ( n e w   g o o g l e . m a p s . L a t L n g (  
                                       s t a r t . P o i n t . c o o r d i n a t e s [ 1 ] ,   s t a r t . P o i n t . c o o r d i n a t e s [ 0 ] ) ) ;  
     } ) ;  
      
     $ ( ' # d i r - e n d ' ) . c l i c k ( f u n c t i o n ( )   {  
         D S _ f l y T o L a t L n g ( n e w   g o o g l e . m a p s . L a t L n g (  
                                       e n d . P o i n t . c o o r d i n a t e s [ 1 ] ,   e n d . P o i n t . c o o r d i n a t e s [ 0 ] ) ) ;  
     } ) ;  
      
     $ ( ' # r o u t e - d e t a i l s   l i ' ) . c l i c k ( f u n c t i o n ( )   {  
         v a r   i d   =   $ ( t h i s ) . a t t r ( ' i d ' ) ;  
         i f   ( i d   = =   ' d i r - s t a r t '   | |   i d   = =   ' d i r - e n d ' )  
             r e t u r n ;  
          
         v a r   s t e p N u m   =   p a r s e I n t ( i d . m a t c h ( / d i r - s t e p - ( \ d + ) / ) [ 1 ] ) ;  
         D S _ f l y T o S t e p ( s t e p N u m ) ;  
     } ) ;  
 }  
  
 / * *  
   *   F l y   t h e   c a m e r a   t o   t h e   g i v e n   s t e p   i n d e x   i n   t h e   r o u t e ,   a n d   h i g h l i g h t   i t   i n  
   *   t h e   d i r e c t i o n s   l i s t .   A l s o   s h o w   t h e   p l a c e m a r k   d e s c r i p t i o n   b a l l o o n .  
   *   @ p a r a m   { n u m b e r }   s t e p N u m   T h e   0 - b a s e d   s t e p   i n d e x   t o   f l y   t o  
   * /  
 f u n c t i o n   D S _ f l y T o S t e p ( s t e p N u m )   {  
     v a r   s t e p   =   D S _ s t e p s [ s t e p N u m ] ;  
      
     v a r   l a   =   D S _ g e . c r e a t e L o o k A t ( ' ' ) ;  
     l a . s e t ( s t e p . l o c . l a t ( ) ,   s t e p . l o c . l n g ( ) ,  
             0 ,   / /   a l t i t u d e  
             D S _ g e . A L T I T U D E _ R E L A T I V E _ T O _ G R O U N D ,  
             D S _ g e H e l p e r s . g e t H e a d i n g ( s t e p . l o c ,   D S _ p a t h [ s t e p . p a t h I n d e x   +   1 ] . l o c ) ,  
             6 0 ,   / /   t i l t  
             5 0   / /   r a n g e   ( i n v e r s e   o f   z o o m )  
             ) ;  
     D S _ g e . g e t V i e w ( ) . s e t A b s t r a c t V i e w ( l a ) ;  
  
  
     / /   s h o w   t h e   d e s c r i p t i o n   b a l l o o n .  
     v a r   b a l l o o n   =   D S _ g e . c r e a t e F e a t u r e B a l l o o n ( ' ' ) ;  
     b a l l o o n . s e t F e a t u r e ( D S _ p l a c e m a r k s [ ' s t e p - '   +   s t e p N u m ] ) ;  
     D S _ g e . s e t B a l l o o n ( b a l l o o n ) ;    
  
     D S _ h i g h l i g h t S t e p ( s t e p N u m ) ;  
 }  
  
 / * *  
   *   H i g h l i g h t s   t h e   g i v e n   s t e p   i n   t h e   l e f t   d i r e c t i o n s   l i s t  
   *   @ p a r a m   { n u m b e r }   s t e p N u m   T h e   0 - b a s e d   s t e p   i n d e x   t o   h i g h l i g h t   i n   t h e  
   *           d i r e c t i o n s   l i s t  
   * /  
 f u n c t i o n   D S _ h i g h l i g h t S t e p ( s t e p N u m )   {  
     $ ( ' # r o u t e - d e t a i l s   l i ' ) . r e m o v e C l a s s ( ' s e l ' ) ;  
     $ ( ' # r o u t e - d e t a i l s   # d i r - s t e p - '   +   s t e p N u m ) . a d d C l a s s ( ' s e l ' ) ;  
 }  
  
 / * *  
   *   M o v e   t h e   c a m e r a   t o   t h e   g i v e n   l o c a t i o n ,   s t a r i n g   s t r a i g h t   d o w n ,   a n d   u n h i g h l i g h t  
   *   a l l   i t e m s   i n   t h e   l e f t   d i r e c t i o n s   l i s t  
   *   @ p a r a m   { g o o g l e . m a p s . L a t L n g }   l o c   T h e   l o c a t i o n   t o   f l y   t h e   c a m e r a   t o  
   * /  
 f u n c t i o n   D S _ f l y T o L a t L n g ( l o c )   {  
     v a r   l a   =   D S _ g e . c r e a t e L o o k A t ( ' ' ) ;  
     l a . s e t ( l o c . l a t ( ) ,   l o c . l n g ( ) ,  
             1 0 ,   / /   a l t i t u d e  
             D S _ g e . A L T I T U D E _ R E L A T I V E _ T O _ G R O U N D ,  
             9 0 ,   / /   h e a d i n g  
             0 ,   / /   t i l t  
             2 0 0   / /   r a n g e   ( i n v e r s e   o f   z o o m )  
             ) ;  
     D S _ g e . g e t V i e w ( ) . s e t A b s t r a c t V i e w ( l a ) ;  
  
      
     $ ( ' # r o u t e - d e t a i l s   l i ' ) . r e m o v e C l a s s ( ' s e l ' ) ;  
 }  
  
 / * *  
   *   F o r m a t s   a   t i m e   g i v e n   i n   s e c o n d s   t o   a   h u m a n   r e a d a b l e   f o r m a t  
   *   @ p a r a m   { n u m b e r }   s   T i m e   i n   s e c o n d s  
   *   @ r e t u r n   { s t r i n g }   A   s t r i n g   f o r m a t t e d   i n   h h : m m   f o r m   r e p r e s e n t i n g   t h e   g i v e n  
   *           n u m b e r   o f   s e c o n d s  
   * /  
 f u n c t i o n   D S _ f o r m a t T i m e ( s )   {  
     v a r   m   =   M a t h . f l o o r ( s   /   6 0 ) ;  
     s   % =   6 0 ;  
     v a r   h   =   M a t h . f l o o r ( m   /   6 0 ) ;  
     m   % =   6 0 ;  
     s   =   M a t h . r o u n d ( s ) ;  
     r e t u r n   ( ( h   <   1 0 )   ?   ( ' 0 '   +   h )   :   h )   +   ' : '   +   ( ( m   <   1 0 )   ?   ( ' 0 '   +   m )   :   m ) ;  
 }  
  
 / * *  
   *   S i m u l a t o r   c o n t r o l s  
   *   @ p a r a m   { s t r i n g }   c o m m a n d   T h e   c o n t r o l   c o m m a n d   t o   r u n  
   *   @ p a r a m   { F u n c t i o n ? }   o p t _ c b   O p t i o n a l   c a l l b a c k   t o   r u n   w h e n   t h e   c o m m a n d  
   *           c o m p l e t e s   i t s   t a s k  
   * /  
 f u n c t i o n   D S _ c o n t r o l S i m u l a t o r ( c o m m a n d ,   o p t _ c b )   {  
     s w i t c h   ( c o m m a n d )   {  
         c a s e   ' r e s e t ' :  
             i f   ( D S _ s i m u l a t o r )  
                 D S _ s i m u l a t o r . d e s t r o y ( ) ;  
              
             / /   c r e a t e   a   D D S i m u l a t o r   o b j e c t   f o r   t h e   c u r r e n t   D S _ p a t h   a r r a y  
             / /   o n   t h e   D S _ g e   E a r t h   i n s t a n c e  
             D S _ s i m u l a t o r   =   n e w   D D S i m u l a t o r ( D S _ g e ,   D S _ p a t h ,   {  
                 / /   a s   t h e   s i m u l a t o r   r u n s ,   r e p o s i t i o n   t h e   m a p   o n   t h e   r i g h t   a n d   t h e  
                 / /   c a r   m a r k e r   o n   t h e   m a p ,   a n d   u p d a t e   t h e   s t a t u s   b o x   o n   t h e   b o t t o m  
                 o n _ t i c k :   f u n c t i o n ( )   {  
                     D S _ m a p . p a n T o ( D S _ s i m u l a t o r . c u r r e n t L o c ) ;  
                     D S _ m a p M a r k e r . s e t L a t L n g ( D S _ s i m u l a t o r . c u r r e n t L o c ) ;  
                      
                     i f   ( D S _ s i m u l a t o r )   {  
                         $ ( ' # s t a t u s ' ) . h t m l (  
                                 ' < s t r o n g > T i d : < / s t r o n g >   '   +  
                                     D S _ f o r m a t T i m e ( D S _ s i m u l a t o r . t o t a l T i m e )   +   ' < b r / > '   +  
                                 ' < s t r o n g > D i s t a n s : < / s t r o n g >   '   +  
                                     ( M a t h . r o u n d (  
                                             D S _ s i m u l a t o r . t o t a l D i s t a n c e   /   1 0 0 0   *   1 0 )   /   1 0 )   +  
                                     '   k m '   +   ' < b r / > '   +  
                                 ' < s t r o n g > H a s t i g h e t : < / s t r o n g >   '   +  
                                     M a t h . r o u n d ( D S _ s i m u l a t o r . c u r r e n t S p e e d / 0 . 1 9 )   +   ' K p h '   +  
                                     ' < b r / > '   +  
                                 ' < s t r o n g > P o s i t i o n : < / s t r o n g >   '   +  
                                     D S _ s i m u l a t o r . c u r r e n t L o c   +   ' l a t   l o n g ' )   +  
                                     ' < b r / > ' ;  
  
                     }  
                 } ,  
                  
                 / /   w h e n   t h e   s i m u l a t o r   m o v e s   t o   a   n e w   s t e p   ( s p e c i f i e d   a s   a n   i n t e g e r  
                 / /   i n d e x   i n   D S _ p a t h   i t e m s ) ,   h i g h l i g h t   t h a t   s t e p   i n   t h e   d i r e c t i o n s  
                 / /   l i s t  
                 o n _ c h a n g e S t e p :   f u n c t i o n ( s t e p N u m )   {  
                     D S _ h i g h l i g h t S t e p ( s t e p N u m ) ;  
                 }  
             } ) ;  
              
             i f   ( ! D S _ m a p M a r k e r )   {  
                 / /   c r e a t e   v e h i c l e   l o c a t i o n   i n d i c a t o r   o n   m a p  
                 v a r   i c o n   =   n e w   g o o g l e . m a p s . I c o n ( ) ;  
                 i c o n . i c o n S i z e   =   n e w   g o o g l e . m a p s . S i z e ( 4 2 ,   4 2 ) ;  
                 i c o n . i c o n A n c h o r   =   n e w   g o o g l e . m a p s . P o i n t ( 2 1 ,   2 1 ) ;  
                 i c o n . i m a g e   =   ' s m a r t _ m a r k e r . p n g ' ;  
                 D S _ m a p M a r k e r   =   n e w   g o o g l e . m a p s . M a r k e r (  
                                               D S _ s i m u l a t o r . c u r r e n t L o c ,   { i c o n :   i c o n } ) ;  
                 D S _ m a p . a d d O v e r l a y ( D S _ m a p M a r k e r ) ;  
             }  
              
             D S _ m a p . s e t Z o o m ( 1 3 ) ;  
             D S _ m a p M a r k e r . s e t L a t L n g ( D S _ s i m u l a t o r . c u r r e n t L o c ) ;  
              
             D S _ u p d a t e S p e e d I n d i c a t o r ( ) ;  
             D S _ s i m u l a t o r . i n i t U I ( o p t _ c b ) ;  
             b r e a k ;  
          
         c a s e   ' s t a r t ' :  
             i f   ( ! D S _ s i m u l a t o r )  
                 D S _ c o n t r o l S i m u l a t o r ( ' r e s e t ' ,   f u n c t i o n ( )   {  
                     D S _ s i m u l a t o r . s t a r t ( ) ;  
                     i f   ( o p t _ c b )   o p t _ c b ( ) ;  
                 } ) ;  
             e l s e   {  
                 D S _ s i m u l a t o r . s t a r t ( ) ;  
                 i f   ( o p t _ c b )   o p t _ c b ( ) ;  
             }  
             b r e a k ;  
          
         c a s e   ' p a u s e ' :  
             i f   ( D S _ s i m u l a t o r )  
                 D S _ s i m u l a t o r . s t o p ( ) ;  
              
             i f   ( o p t _ c b )   o p t _ c b ( ) ;  
             b r e a k ;  
          
         c a s e   ' r e s u m e ' :  
             i f   ( D S _ s i m u l a t o r )  
                 D S _ s i m u l a t o r . s t a r t ( ) ;  
              
             i f   ( o p t _ c b )   o p t _ c b ( ) ;  
             b r e a k ;  
          
         c a s e   ' s l o w e r ' :  
             i f   ( D S _ s i m u l a t o r   & &   D S _ s i m u l a t o r . o p t i o n s . s p e e d   >   0 . 1 2 5 )   {  
                 D S _ s i m u l a t o r . o p t i o n s . s p e e d   / =   2 . 0 ;  
                 D S _ u p d a t e S p e e d I n d i c a t o r ( ) ;  
             }  
             b r e a k ;  
          
         c a s e   ' f a s t e r ' :  
             i f   ( D S _ s i m u l a t o r   & &   D S _ s i m u l a t o r . o p t i o n s . s p e e d   <   3 2 . 0 )   {  
                 D S _ s i m u l a t o r . o p t i o n s . s p e e d   * =   2 . 0 ;  
                 D S _ u p d a t e S p e e d I n d i c a t o r ( ) ;  
             }  
             b r e a k ;  
     }  
 }  
  
 / * *  
   *   U p d a t e   t h e   s p e e d   i n d i c a t o r   i n   t h e   s i m u l a t i o n   c o n t r o l s   b o x   t o   r e f l e c t  
   *   t h e   c u r r e n t   s i m u l a t i o n   s p e e d   m u l t i p l i e r  
   * /  
 f u n c t i o n   D S _ u p d a t e S p e e d I n d i c a t o r ( )   {  
     i f   ( D S _ s i m u l a t o r . o p t i o n s . s p e e d   <   1 )  
         $ ( ' # s p e e d - i n d i c a t o r ' ) . t e x t ( ' 1 / '   +  
                 M a t h . f l o o r ( 1   /   D S _ s i m u l a t o r . o p t i o n s . s p e e d )   +   ' x ' ) ;  
     e l s e  
         $ ( ' # s p e e d - i n d i c a t o r ' ) . t e x t ( M a t h . f l o o r ( D S _ s i m u l a t o r . o p t i o n s . s p e e d )   +   ' x ' ) ;  
 }  
 
