-
Notifications
You must be signed in to change notification settings - Fork 0
/
yandex.js
62 lines (51 loc) · 1.59 KB
/
yandex.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
const yandexApi = {
type: 'yandex',
map: undefined,
container: undefined,
init(elementId) {
if (!window.ymaps || !window.ymaps.Map) {
return;
}
if (this.map && this.container) {
this.update();
return;
}
this.container = document.createElement('div');
this.container.classList.add('map-container');
const wrapper = document.getElementById(elementId);
wrapper.appendChild(this.container);
this.map = new ymaps.Map(this.container, {
center: [state.lat, state.lng],
zoom: state.zoom,
controls: ['zoomControl', 'typeSelector'],
});
const typeSelector = this.map.controls.get('typeSelector');
typeSelector.options.set('position', { top: 10, left: 10 });
this.map.events.add('boundschange', () => {
const center = this.map.getCenter();
window.updateAnotherMap(this, {
lng: center[1],
lat: center[0],
zoom: this.map.getZoom(),
rotation: 0,
pitch: 0,
});
});
},
update() {
if (!this.map) {
return;
}
const { lng, lat, zoom } = state;
this.map.setCenter([lat, lng]);
this.map.setZoom(zoom);
},
hide() {
if (this.container && this.map) {
this.map.destroy();
this.container.parentElement.removeChild(this.container);
this.map = undefined;
this.container = undefined;
}
},
};