From 77c4131be48a0edc555ec102bebb59c42061f2a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 26 Feb 2019 15:39:08 +0100 Subject: [PATCH] maps: add classes for geolocation status (#30911) --- combo/apps/maps/static/js/combo.map.js | 6 ++++++ combo/apps/maps/static/js/leaflet-gps.js | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/combo/apps/maps/static/js/combo.map.js b/combo/apps/maps/static/js/combo.map.js index 4ba8816e..90a2f076 100644 --- a/combo/apps/maps/static/js/combo.map.js +++ b/combo/apps/maps/static/js/combo.map.js @@ -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, diff --git a/combo/apps/maps/static/js/leaflet-gps.js b/combo/apps/maps/static/js/leaflet-gps.js index 1414239d..a531f5d9 100644 --- a/combo/apps/maps/static/js/leaflet-gps.js +++ b/combo/apps/maps/static/js/leaflet-gps.js @@ -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'); }, });