forked from unicef-polymer/etools-leaflet-map
-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaflet-geolocation.html
271 lines (241 loc) · 6.81 KB
/
leaflet-geolocation.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<link rel="import" href="leaflet-core.html">
<!--
element which controls geo location (<a href="http://leafletjs.com/reference.html#map">Leaflet Reference</a>).
##### Example
<leaflet-geolocation watch enableHighAccuracy latitude="{{latitude}}" longitude="{{longitude}}"> </leaflet-geolocation>
@element leaflet-geolocation
@blurb element which controls geo location.
@demo https://leaflet-extras.github.io/leaflet-map/demo.html
@homepage https://leaflet-extras.github.io/leaflet-map/
-->
<dom-module id="leaflet-geolocation">
<style>
:host {
display: none;
}
</style>
<template>
</template>
<script>
'use strict';
class LeafletGeolocation extends Polymer.Element {
static get is() { return 'leaflet-geolocation'; }
static get properties() {
return {
/**
* Fired when geolocation (using the locate method) went successfully.
*
* @event locationfound
* @type LocationEvent
* @param {LatLng} latlng Detected geographical location of the user.
* @param {LatLngBounds} bounds Geographical bounds of the area user is located in (with respect to the accuracy of location).
* @param {Number} accuracy Accuracy of location in meters.
* @param {Number} altitude Height of the position above the WGS84 ellipsoid in meters.
* @param {Number} altitudeAccuracy Accuracy of altitude in meters.
* @param {Number} heading The direction of travel in degrees counting clockwise from true North.
* @param {Number} speed Current velocity in meters per second.
* @param {Number} timestamp The time when the position was acquired.
*/
/**
* Fired when geolocation (using the locate method) failed.
*
* @event locationerror
* @type ErrorEvent
* @param {string} message Error message.
* @param {number} code Error code (if applicable).
*/
/**
* The `watch` attribute sets wether location changes should be continous watching (instead of detecting it once) using W3C watchPosition method. You can later stop watching using map.stopLocate() method.
*
* @attribute watch
* @type bool
*/
watch: {
type: Boolean,
value: false
},
/**
* The `set-view` attribute sets whether the map view to the user location with respect to detection accuracy, or to world view if geolocation failed.
*
* @attribute set-view
* @type bool
*/
setView: {
type: Boolean,
value: false
},
/**
* The `max-zoom` attribute sets the maximum zoom for automatic view setting when using `setView` option.
*
* @attribute max-zoom
* @type number
*/
maxZoom: {
type: Number,
value: Infinity
},
/**
* The `timeout` attribute sets the number of milliseconds to wait for a response from geolocation before firing a locationerror event.
*
* @attribute timeout
* @type number
*/
timeout: {
type: Number,
value: 10000
},
/**
* The `maximum-age` attribute sets maximum age of detected location. If less than this amount of milliseconds passed since last geolocation response, locate will return a cached location.
*
* @attribute maximum-age
* @type number
*/
maximumAge: {
type: Number,
value: 0
},
/**
* The `enable-high-accuracy` attribute sets whether high accuracy is enabled, see description in the W3C spec.
*
* @attribute enable-high-accuracy
* @type bool
*/
enableHighAccuracy: {
type: Boolean,
value: false
},
/**
* The `latitude` attribute returns the detected geographical location of the user.
*
* @attribute latitude
* @type number
*/
latitude: {
type: Number,
value: null,
notify: true
},
/**
* The `longitude` attribute returns the detected geographical location of the user.
*
* @attribute longitude
* @type number
*/
longitude: {
type: Number,
value: null,
notify: true
},
/**
* The `bounds` attribute returns the geographical bounds of the area user is located in (with respect to the accuracy of location).
*
* @attribute bounds
* @type number
*/
bounds: {
type: Number,
value: null,
notify: true
},
/**
* The `accuracy` attribute returns the accuracy of location in meters.
*
* @attribute accuracy
* @type number
*/
accuracy: {
type: Number,
value: null,
notify: true
},
/**
* The `altitude` attribute returns the height of the position above the WGS84 ellipsoid in meters.
*
* @attribute altitude
* @type number
*/
altitude: {
type: Number,
value: null,
notify: true
},
/**
* The `altitude-accuracy` attribute returns the accuracy of altitude in meters.
*
* @attribute altitude-accuracy
* @type number
*/
altitudeAccuracy: {
type: Number,
value: null,
notify: true
},
/**
* The `heading` attribute returns the direction of travel in degrees counting clockwise from true North.
*
* @attribute heading
* @type number
*/
heading: {
type: Number,
value: null,
notify: true
},
/**
* The `speed` attribute returns the current velocity in meters per second.
*
* @attribute speed
* @type number
*/
speed: {
type: Number,
value: null,
notify: true
},
/**
* The `timestamp` attribute returns the time when the position was acquired.
*
* @attribute timestamp
* @type number
*/
timestamp: {
type: Number,
value: null,
notify: true
},
container: {
type: Object,
observer: '_containerChanged'
}
};
}
_containerChanged() {
if (this.container) {
this.container.on('locationfound locationerror', function(e) {
this.dispatchEvent(new CustomEvent(e.type, e));
}, this);
this.container.on('locationfound', function(e) {
this.latitude = e.latlng.lat;
this.longitude = e.latlng.lng;
this.bounds = e.bounds;
this.accuracy = e.accuracy;
this.altitude = e.altitude;
this.altitudeAccuracy = e.altitudeAccuracy;
this.heading = e.heading;
this.speed = e.speed;
this.timestamp = e.timestamp;
}, this);
this.container.locate({
watch: this.watch,
setView: this.setView,
maxZoom: this.maxZoom,
timeout: this.timeout,
maximumAge: this.maximumAge,
enableHighAccuracy: this.enableHighAccuracy
});
}
}
}
window.customElements.define(LeafletGeolocation.is, LeafletGeolocation);
</script>
</dom-module>