-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathlocate.mjs
53 lines (42 loc) · 1.19 KB
/
locate.mjs
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
export default function (params) {
this._locate = this._locate || Object.assign({
icon: {
svg: `${this.host}/icons/locator.svg`,
scale: 0.05
},
feature: new ol.Feature({
geometry: new ol.geom.Point([0, 0])
}),
}, params || {})
this._locate.active = !this._locate.active
// Create the geolocation marker if it doesn't exist yet.
if (!this._locate.L) {
this._locate.L = new ol.layer.Vector({
source: new ol.source.Vector({
features: [this._locate.feature]
}),
zIndex: 999,
style: mapp.utils.style({
icon: this._locate.icon
})
})
}
// Remove the geolocation marker if locate is not active.
if (!this._locate.active) {
this.Map.removeLayer(this._locate.L)
return;
}
this.Map.addLayer(this._locate.L)
mapp.utils.getCurrentPosition((pos) => {
const coords = ol.proj.fromLonLat([
parseFloat(pos.coords.longitude),
parseFloat(pos.coords.latitude)
])
this._locate.feature.getGeometry().setCoordinates(coords)
// Fly to pos_ll and set flyTo to false to prevent map tracking.
this.Map.getView().animate({
center: coords,
zoom: this.locale.maxZoom
})
})
}