@@ -17,8 +17,10 @@ var session = require('session');
1717var View = module . exports = view ( require ( './template.html' ) , function ( view , plan ) {
1818 view . on ( 'rendered' , function ( ) {
1919 var self = this ;
20+
2021 window . setTimeout ( function ( ) {
2122 self . resetIcons ( ) ;
23+ // TODO: check for user location here
2224 } , 200 ) ;
2325
2426 closest ( view . el , 'form' ) . onsubmit = function ( e ) {
@@ -478,15 +480,25 @@ View.prototype.locateMe = function(e) {
478480 loading_btn . classList . remove ( 'hidden' )
479481 location_me_btn . classList . add ( 'hidden' )
480482
481- navigator . geolocation . getCurrentPosition ( function ( position ) {
483+ var geolocationSuccess = function ( position ) {
484+ console . log ( 'user allowed access to geolocation' )
485+ self . user_geolocation = true ;
482486 var plan = session . plan ( ) ;
483487 var target = input . id . indexOf ( 'from' ) !== - 1 ? 'from' : 'to' ;
484-
485488 plan . setAddress ( target , position . coords . longitude + ',' + position . coords . latitude , function ( err , rees ) {
486489 plan . updateRoutes ( ) ;
487490 self . resetIcons ( ) ;
488491 } ) ;
489- } , null , {
492+ }
493+
494+ var geolocationError = function ( position ) {
495+ console . warn ( 'user denied access to geolocation' )
496+ // hide the geolocation button
497+ self . user_geolocation = false ;
498+ self . resetIcons ( ) ;
499+ }
500+
501+ navigator . geolocation . getCurrentPosition ( geolocationSuccess , geolocationError , {
490502 enableHighAccuracy : true ,
491503 maximumAge : 10000 ,
492504 timeout : 30000
@@ -497,25 +509,34 @@ View.prototype.locateMe = function(e) {
497509}
498510
499511View . prototype . resetIcons = function ( e ) {
500- showClearOrCurrentLocation ( this , 'from' )
501- showClearOrCurrentLocation ( this , 'to' )
502-
512+
503513 function showClearOrCurrentLocation ( view , name ) {
504514 var selector = '.' + name
505515 var value = view . find ( selector + ' input' ) . value
506516 var clear_btn = view . find ( selector + ' .fa-times' )
507517 var loading_btn = view . find ( selector + ' .fa-spin' )
508518 var location_me_btn = view . find ( selector + ' .fa-location-arrow' )
509519 if ( ! value || ! value . trim || value . trim ( ) . length === 0 ) {
510- clear_btn . classList . add ( 'hidden' )
520+
511521 loading_btn . classList . add ( 'hidden' )
512- location_me_btn . classList . remove ( 'hidden' )
522+ if ( show_geo_btn ) {
523+ clear_btn . classList . add ( 'hidden' )
524+ location_me_btn . classList . remove ( 'hidden' )
525+ } else {
526+ console . log ( 'refusing to show location arrow' )
527+ clear_btn . classList . remove ( 'hidden' )
528+ location_me_btn . classList . add ( 'hidden' )
529+ }
513530 } else {
514531 clear_btn . classList . remove ( 'hidden' )
515532 loading_btn . classList . add ( 'hidden' )
516533 location_me_btn . classList . add ( 'hidden' )
517534 }
518535 }
536+
537+ var show_geo_btn = ( this . user_geolocation === undefined || this . user_geolocation === true ) ? true : false ;
538+ showClearOrCurrentLocation ( this , 'from' )
539+ showClearOrCurrentLocation ( this , 'to' )
519540}
520541
521542/**
0 commit comments