forked from locationestimatr/locationestimatr.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StreetviewElement.js
88 lines (77 loc) · 2.84 KB
/
StreetviewElement.js
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
class StreetviewElement {
constructor(element, flagElement) {
this.flagElement = flagElement;
this.element = element;
}
resetRestrictions() {
this.allowMove();
this.allowPan();
this.allowZoom();
this.removeMoveLimit();
}
setMoveLimit(moves, remainingElement) {
console.log({moves});
if (moves === 0)
this.restrictMove();
remainingElement.style.display = "inline-block";
remainingElement.innerHTML = `Moves: <b>${moves}</b>`;
this.panorama.addListener("position_changed", () => {
remainingElement.innerHTML = `Moves: <b>${--moves}</b>`;
if (moves === 0)
this.restrictMove();
});
}
removeMoveLimit() {
google.maps.event.clearListeners(this.panorama, "position_changed");
}
restrictPan() {
this.element.querySelector(".gm-compass").style.display = "none";
this.element.querySelector(".widget-scene").style.pointerEvents = "none";
}
allowPan() {
this.element.querySelector(".gm-compass").style.display = "block";
this.element.querySelector(".widget-scene").style.pointerEvents = "all";
}
restrictZoom() {
this.element.querySelector("div.gmnoprint.gm-bundled-control.gm-bundled-control-on-bottom > div.gmnoprint > div").style.display = "none";
this.panorama.setOptions({scrollwheel: false});
}
allowZoom() {
this.element.querySelector("div.gmnoprint.gm-bundled-control.gm-bundled-control-on-bottom > div.gmnoprint > div").style.display = "block";
this.panorama.setOptions({scrollwheel: true});
}
restrictMove() {
this.panorama.setOptions({linksControl: false});
this.panorama.setOptions({clickToGo: false});
this.flagElement.style.display = "none";
}
allowMove() {
this.panorama.setOptions({linksControl: true});
this.panorama.setOptions({clickToGo: true});
this.flagElement.style.display = "block";
}
getLocation() {
let position = this.panorama.getPosition();
let lat = position.lat();
let lon = position.lng();
return [lat, lon];
}
setLocation(lat, lon) {
if (this.panorama !== undefined) {
this.panorama.setPosition({lat: lat, lng: lon});
} else {
this.panorama = new google.maps.StreetViewPanorama(
this.element, {
position: {lat: lat, lng: lon},
addressControl: false,
linksControl: true,
panControl: true,
enableCloseButton: false,
showRoadLabels: false,
motionTracking: false,
fullscreenControl: false,
motionTrackingControl: false
});
}
}
}