34 |
34 |
fillColor: '#f23',
|
35 |
35 |
fillOpacity: 1
|
36 |
36 |
},
|
37 |
|
position: 'topleft'
|
|
37 |
position: 'topleft',
|
|
38 |
tooltipTitle: 'Display my position'
|
38 |
39 |
},
|
39 |
40 |
|
40 |
41 |
initialize: function(options) {
|
... | ... | |
49 |
50 |
onAdd: function (map) {
|
50 |
51 |
this._map = map;
|
51 |
52 |
|
52 |
|
var container = L.DomUtil.create('div', 'leaflet-control-gps leaflet-bar');
|
|
53 |
this._container = L.DomUtil.create('div', 'leaflet-control-gps leaflet-bar');
|
53 |
54 |
|
54 |
|
this._button = L.DomUtil.create('a', 'gps-button', container);
|
|
55 |
this._button = L.DomUtil.create('a', 'gps-button', this._container);
|
55 |
56 |
this._button.href = '#';
|
56 |
57 |
this._button.text = '\uf192';
|
|
58 |
this._button.title = this.options.tooltipTitle;
|
57 |
59 |
this._button.style.fontFamily = 'FontAwesome';
|
58 |
|
this._button.style.borderRadius = '4px';
|
59 |
60 |
L.DomEvent
|
60 |
61 |
.on(this._button, 'click', L.DomEvent.stop, this)
|
61 |
62 |
.on(this._button, 'click', this._askGps, this);
|
... | ... | |
67 |
68 |
.on('locationfound', this._drawGps, this)
|
68 |
69 |
.on('locationerror', this._errorGps, this);
|
69 |
70 |
|
70 |
|
return container;
|
|
71 |
return this._container;
|
71 |
72 |
},
|
72 |
73 |
|
73 |
74 |
onRemove: function(map) {
|
... | ... | |
75 |
76 |
},
|
76 |
77 |
|
77 |
78 |
_askGps: function() {
|
|
79 |
this._firstMoved = false;
|
|
80 |
this._container.classList.add('pending');
|
78 |
81 |
this.activate();
|
79 |
82 |
},
|
80 |
83 |
|
... | ... | |
98 |
101 |
},
|
99 |
102 |
|
100 |
103 |
deactivate: function() {
|
|
104 |
this._container.classList.remove('pending');
|
101 |
105 |
this._isActive = false;
|
102 |
106 |
this._firstMoved = false;
|
103 |
107 |
this._map.stopLocate();
|
... | ... | |
106 |
110 |
},
|
107 |
111 |
|
108 |
112 |
_drawGps: function(e) {
|
|
113 |
this._container.classList.remove('pending');
|
109 |
114 |
this._currentLocation = e.latlng;
|
110 |
115 |
|
111 |
116 |
this._gpsMarker.setLatLng(this._currentLocation);
|
112 |
117 |
|
113 |
|
if(this._isActive && !this._firstMoved)
|
|
118 |
if(this._isActive && !this._firstMoved) {
|
114 |
119 |
this._moveTo(this._currentLocation);
|
|
120 |
this._map.stopLocate();
|
|
121 |
}
|
115 |
122 |
|
116 |
123 |
if (this._isActive) {
|
117 |
124 |
this.fire('gps:located', {latlng: this._currentLocation, marker: this._gpsMarker});
|
118 |
|
-
|