maps: sync leaflet-gps with combo (#26375)
This commit is contained in:
parent
382af780b6
commit
31cb013a55
|
@ -34,7 +34,8 @@ L.Control.Gps = L.Control.extend({
|
|||
fillColor: '#f23',
|
||||
fillOpacity: 1
|
||||
},
|
||||
position: 'topleft'
|
||||
position: 'topleft',
|
||||
tooltipTitle: 'Display my position'
|
||||
},
|
||||
|
||||
initialize: function(options) {
|
||||
|
@ -49,13 +50,13 @@ L.Control.Gps = L.Control.extend({
|
|||
onAdd: function (map) {
|
||||
this._map = map;
|
||||
|
||||
var container = L.DomUtil.create('div', 'leaflet-control-gps leaflet-bar');
|
||||
this._container = L.DomUtil.create('div', 'leaflet-control-gps leaflet-bar');
|
||||
|
||||
this._button = L.DomUtil.create('a', 'gps-button', container);
|
||||
this._button = L.DomUtil.create('a', 'gps-button', this._container);
|
||||
this._button.href = '#';
|
||||
this._button.text = '\uf192';
|
||||
this._button.title = this.options.tooltipTitle;
|
||||
this._button.style.fontFamily = 'FontAwesome';
|
||||
this._button.style.borderRadius = '4px';
|
||||
L.DomEvent
|
||||
.on(this._button, 'click', L.DomEvent.stop, this)
|
||||
.on(this._button, 'click', this._askGps, this);
|
||||
|
@ -67,7 +68,7 @@ L.Control.Gps = L.Control.extend({
|
|||
.on('locationfound', this._drawGps, this)
|
||||
.on('locationerror', this._errorGps, this);
|
||||
|
||||
return container;
|
||||
return this._container;
|
||||
},
|
||||
|
||||
onRemove: function(map) {
|
||||
|
@ -75,6 +76,8 @@ L.Control.Gps = L.Control.extend({
|
|||
},
|
||||
|
||||
_askGps: function() {
|
||||
this._firstMoved = false;
|
||||
this._container.classList.add('pending');
|
||||
this.activate();
|
||||
},
|
||||
|
||||
|
@ -98,6 +101,7 @@ L.Control.Gps = L.Control.extend({
|
|||
},
|
||||
|
||||
deactivate: function() {
|
||||
this._container.classList.remove('pending');
|
||||
this._isActive = false;
|
||||
this._firstMoved = false;
|
||||
this._map.stopLocate();
|
||||
|
@ -106,12 +110,15 @@ L.Control.Gps = L.Control.extend({
|
|||
},
|
||||
|
||||
_drawGps: function(e) {
|
||||
this._container.classList.remove('pending');
|
||||
this._currentLocation = e.latlng;
|
||||
|
||||
this._gpsMarker.setLatLng(this._currentLocation);
|
||||
|
||||
if(this._isActive && !this._firstMoved)
|
||||
if(this._isActive && !this._firstMoved) {
|
||||
this._moveTo(this._currentLocation);
|
||||
this._map.stopLocate();
|
||||
}
|
||||
|
||||
if (this._isActive) {
|
||||
this.fire('gps:located', {latlng: this._currentLocation, marker: this._gpsMarker});
|
||||
|
|
Loading…
Reference in New Issue