diff options
Diffstat (limited to 'www/js')
-rw-r--r-- | www/js/app.js | 2 | ||||
-rw-r--r-- | www/js/locate.js | 8 | ||||
-rw-r--r-- | www/js/views/around.js | 62 | ||||
-rw-r--r-- | www/js/views/locator.js | 64 |
4 files changed, 79 insertions, 57 deletions
diff --git a/www/js/app.js b/www/js/app.js index a62ec73..4fa0ff8 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -53,6 +53,8 @@ var tpl = { reportToView: null, + locationAccuracy: 100, + online: function() { FMS.isOffline = 0; }, diff --git a/www/js/locate.js b/www/js/locate.js index efc8e82..beb40e7 100644 --- a/www/js/locate.js +++ b/www/js/locate.js @@ -36,7 +36,7 @@ } ); }, - geolocate: function( minAccuracy ) { + geolocate: function( minAccuracy, skipLocationCheck ) { this.locating = 1; $('#ajaxOverlay').show(); @@ -52,7 +52,11 @@ navigator.geolocation.clearWatch( that.watch_id ); delete that.watch_id; - that.check_location(location.coords); + if ( skipLocationCheck ) { + that.trigger('gps_located', { coordinates: location.coords } ); + } else { + that.check_location(location.coords); + } } }, function() { diff --git a/www/js/views/around.js b/www/js/views/around.js index 3664d64..162d69d 100644 --- a/www/js/views/around.js +++ b/www/js/views/around.js @@ -1,6 +1,6 @@ (function (FMS, Backbone, _, $) { _.extend( FMS, { - AroundView: FMS.FMSView.extend({ + AroundView: FMS.LocatorView.extend({ template: 'around', id: 'around-page', @@ -18,68 +18,23 @@ if ( FMS.currentLocation ) { var info = { coordinates: FMS.currentLocation }; FMS.currentLocation = null; - this.showMap(info); + this.gotLocation(info); } else if ( this.model && this.model.get('lat') ) { var modelInfo = { coordinates: { latitude: this.model.get('lat'), longitude: this.model.get('lon') } }; - this.showMap(modelInfo); + this.gotLocation(modelInfo); } else { this.locate(); } }, - locate: function() { - $('#locating').show(); - this.listenTo(FMS.locator, 'gps_located', this.showMap); - this.listenTo(FMS.locator, 'gps_failed', this.noMap ); - this.listenTo(FMS.locator, 'gps_locating', this.locationUpdate); - - FMS.locator.geolocate(100); - this.startLocateProgress(); - }, - - locationUpdate: function( accuracy ) { - if ( accuracy && accuracy < 500 ) { - $('#progress-bar').css( 'background-color', 'orange' ); - } else if ( accuracy && accuracy < 250 ) { - $('#progress-bar').css( 'background-color', 'yellow' ); - } else { - $('#progress-bar').css( 'background-color', 'grey' ); - } - - $('#accuracy').text(parseInt(accuracy, 10) + 'm'); - }, - - startLocateProgress: function() { - this.located = false; - this.locateCount = 1; - var that = this; - window.setTimeout( function() {that.showLocateProgress();}, 1000); - }, - - showLocateProgress: function() { - if ( !this.located && this.locateCount > 20 ) { - FMS.searchMessage = FMS.strings.geolocation_failed; - this.navigate('search'); - return; - } - var percent = ( ( 20 - this.locateCount ) / 20 ) * 100; - $('#progress-bar').css( 'width', percent + '%' ); - this.locateCount++; - var that = this; - window.setTimeout( function() {that.showLocateProgress();}, 1000); - }, - - showMap: function( info ) { - this.stopListening(FMS.locator, 'gps_locating'); - this.stopListening(FMS.locator, 'gps_located'); - this.stopListening(FMS.locator, 'gps_failed'); + gotLocation: function( info ) { + this.finishedLocating(); this.listenTo(FMS.locator, 'gps_current_position', this.positionUpdate); this.located = true; this.locateCount = 21; $('#ajaxOverlay').hide(); - $('#locating').hide(); var coords = info.coordinates; fixmystreet.latitude = coords.latitude; @@ -131,12 +86,9 @@ } }, - noMap: function( details ) { - this.stopListening(FMS.locator, 'gps_locating'); - this.stopListening(FMS.locator, 'gps_located'); - this.stopListening(FMS.locator, 'gps_failed'); + failedLocation: function( details ) { + this.finishedLocating(); this.locateCount = 21; - $('#locating').hide(); $('#ajaxOverlay').hide(); if ( details.msg ) { FMS.searchMessage = details.msg; diff --git a/www/js/views/locator.js b/www/js/views/locator.js new file mode 100644 index 0000000..2475da8 --- /dev/null +++ b/www/js/views/locator.js @@ -0,0 +1,64 @@ +(function (FMS, Backbone, _, $) { + _.extend( FMS, { + LocatorView: FMS.FMSView.extend({ + skipLocationCheck: false, + + locate: function() { + $('#locating').show(); + this.listenTo(FMS.locator, 'gps_located', this.gotLocation); + this.listenTo(FMS.locator, 'gps_failed', this.failedLocation); + this.listenTo(FMS.locator, 'gps_locating', this.locationUpdate); + + FMS.locator.geolocate(FMS.locationAccuracy, this.skipLocationCheck); + this.startLocateProgress(); + }, + + startLocateProgress: function() { + this.located = false; + this.locateCount = 1; + var that = this; + window.setTimeout( function() {that.showLocateProgress();}, 1000); + }, + + locationUpdate: function( accuracy ) { + if ( accuracy && accuracy < 500 ) { + $('#progress-bar').css( 'background-color', 'orange' ); + } else if ( accuracy && accuracy < 250 ) { + $('#progress-bar').css( 'background-color', 'yellow' ); + } else { + $('#progress-bar').css( 'background-color', 'grey' ); + } + + $('#accuracy').text(parseInt(accuracy, 10) + 'm'); + }, + + showLocateProgress: function() { + if ( !this.located && this.locateCount > 20 ) { + FMS.searchMessage = FMS.strings.geolocation_failed; + $('#locating').hide(); + return; + } + var percent = ( ( 20 - this.locateCount ) / 20 ) * 100; + $('#progress-bar').css( 'width', percent + '%' ); + this.locateCount++; + var that = this; + window.setTimeout( function() {that.showLocateProgress();}, 1000); + }, + + finishedLocating: function() { + this.stopListening(FMS.locator, 'gps_locating'); + this.stopListening(FMS.locator, 'gps_located'); + this.stopListening(FMS.locator, 'gps_failed'); + $('#locating').hide(); + }, + + failedLocation: function(details) { + this.finishedLocating(); + }, + + gotLocation: function(info) { + this.finishedLocating(); + } + }) + }); +})(FMS, Backbone, _, $); |