-
Notifications
You must be signed in to change notification settings - Fork 0
/
google.js
75 lines (64 loc) · 1.92 KB
/
google.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
const googleApi = {
type: 'google',
map: undefined,
container: undefined,
init(elementId) {
if (!window.google) {
return;
}
if (this.map && this.container) {
this.container.style.display = 'block';
this.update();
return;
}
this.container = document.createElement('div');
this.container.classList.add('map-container');
const wrapper = document.getElementById(elementId);
wrapper.appendChild(this.container);
const styledMapType = new google.maps.StyledMapType([
{
featureType: 'poi',
stylers: [
{
visibility: 'off',
},
],
},
]);
this.map = new google.maps.Map(this.container, {
center: { lng: state.lng, lat: state.lat },
zoom: state.zoom,
mapTypeControl: false,
streetViewControl: false,
fullscreenControl: false,
clickableIcons: false,
});
this.map.mapTypes.set('styled_map', styledMapType);
this.map.setMapTypeId('styled_map');
const onMove = () => {
const center = this.map.getCenter();
window.updateAnotherMap(this, {
lng: center.lng(),
lat: center.lat(),
zoom: this.map.getZoom(),
rotation: 0,
pitch: 0,
});
};
this.map.addListener('center_changed', onMove);
this.map.addListener('zoom_changed', onMove);
},
update() {
if (!this.map) {
return;
}
const { lng, lat, zoom } = state;
this.map.setCenter({ lng, lat });
this.map.setZoom(zoom);
},
hide() {
if (this.container) {
this.container.style.display = 'none';
}
},
};