maps: add classes for geolocation status (#30911)

This commit is contained in:
Frédéric Péters 2019-02-26 15:39:08 +01:00
parent 2fbbe647d3
commit 77c4131be4
2 changed files with 13 additions and 0 deletions

View File

@ -154,14 +154,20 @@ $(function() {
map.setView(latlng, map_options.zoom);
if (init_state == 'device-location') {
$map_widget.addClass('waiting-for-geolocation');
map.locate({timeout: 10000, maximumAge: 300000, enableHighAccuracy: false});
map.on('locationfound', function(e) {
$map_widget.removeClass('waiting-for-geolocation');
if (map_options.maxBounds && ! map_options.maxBounds.contains(e.latlng)) {
/* ouf of bounds, keep map centered on default position */
return;
}
map.setView(e.latlng, map_options.zoom);
});
map.on('locationerror', function(e) {
$map_widget.removeClass('waiting-for-geolocation');
$map_widget.addClass('geolocation-error');
});
}
L.tileLayer(map_tile_url,

View File

@ -78,6 +78,8 @@ L.Control.Gps = L.Control.extend({
_askGps: function() {
this._firstMoved = false;
this._container.classList.add('pending');
this._map._container.classList.remove('geolocation-error');
this._map._container.classList.add('waiting-for-geolocation');
this.activate();
},
@ -102,6 +104,8 @@ L.Control.Gps = L.Control.extend({
deactivate: function() {
this._container.classList.remove('pending');
this._map._container.classList.remove('geolocation-error');
this._map._container.classList.remove('waiting-for-geolocation');
this._isActive = false;
this._firstMoved = false;
this._map.stopLocate();
@ -111,6 +115,8 @@ L.Control.Gps = L.Control.extend({
_drawGps: function(e) {
this._container.classList.remove('pending');
this._map._container.classList.remove('geolocation-error');
this._map._container.classList.remove('waiting-for-geolocation');
this._currentLocation = e.latlng;
this._gpsMarker.setLatLng(this._currentLocation);
@ -132,6 +138,7 @@ L.Control.Gps = L.Control.extend({
_errorGps: function(e) {
this.deactivate();
this._map._container.classList.add('geolocation-error');
},
});