Permalink
Browse files

Don't geolocate to a place that is outside of the defined max bounds.

  • Loading branch information...
1 parent 2667553 commit 75034291e3a83d76d52ff5af98be0ec53c70bf8b @atogle atogle committed Sep 28, 2012
Showing with 16 additions and 2 deletions.
  1. +16 −2 src/sa_web/static/js/views/map-view.js
@@ -56,6 +56,8 @@ var Shareabouts = Shareabouts || {};
});
},
initGeolocation: function() {
+ var self = this;
+
var onLocationError = function(evt) {
var message;
switch (evt.code) {
@@ -79,15 +81,27 @@ var Shareabouts = Shareabouts || {};
alert(message);
};
+ var onLocationFound = function(evt) {
+ var msg;
+ if(!self.map.options.maxBounds ||self.map.options.maxBounds.contains(evt.latlng)) {
+ self.map.fitBounds(evt.bounds);
+ } else {
+ msg = 'It looks like you\'re not in a place where we\'re collecting ' +
+ 'data. I\'m going to leave the map where it is, okay?';
+ alert(msg);
+ }
+ };
+
// Add the geolocation control link
this.$('.leaflet-top.leaflet-right').append(
'<div class="leaflet-control">' +
'<a href="#" class="locate-me">&bull;<span> Locate Me</span></a>' +
'</div>'
);
- // Bind error handling event
+ // Bind event handling
this.map.on('locationerror', onLocationError);
+ this.map.on('locationfound', onLocationFound);
// Go to the current location if specified
if (this.options.mapConfig.geolocation_onload) {
@@ -99,7 +113,7 @@ var Shareabouts = Shareabouts || {};
evt.preventDefault();
}
- this.map.locate({setView: true});
+ this.map.locate();
},
addLayerView: function(model) {
this.layerViews[model.cid] = new S.LayerView({

0 comments on commit 7503429

Please sign in to comment.