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