Skip to content

Commit

Permalink
L.Yandex: minor refactoring: all events set only after ymaps api init…
Browse files Browse the repository at this point in the history
…ialized
  • Loading branch information
johndoe committed Jun 30, 2019
1 parent acc326e commit 67c9abb
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions layer/tile/Yandex.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ L.Yandex = L.Layer.extend({
}
mapPane.appendChild(this._container);
if (!this._yandex) { return; }
this._setEvents(map);
this._update();
},

Expand All @@ -63,10 +64,6 @@ L.Yandex = L.Layer.extend({
},

onRemove: function (map) {
// do not remove container until api is initialized (ymaps API expects DOM element)
if (this._yandex) {
this._container.remove();
}
map._removeZoomLimit(this);
},

Expand All @@ -80,18 +77,21 @@ L.Yandex = L.Layer.extend({
}
},

getEvents: function () {
_setEvents: function (map) {
var events = {
move: this._update
};
if (this._zoomAnimated) {
events.zoomanim = this._animateZoom;
}
return events;
map.on(events, this);
this.once('remove', function () {
map.off(events, this);
this._container.remove(); // we do not call this until api is initialized (ymaps API expects DOM element)
}, this);
},

_update: function () {
if (!this._yandex) { return; }
var map = this._map;
var center = map.getCenter();
this._yandex.setCenter([center.lat, center.lng], map.getZoom());
Expand All @@ -106,7 +106,6 @@ L.Yandex = L.Layer.extend({
},

_animateZoom: function (e) {
if (!this._yandex) { return; }
var map = this._map;
var viewHalf = map.getSize()._divideBy(2);
var topLeft = map.project(e.center, e.zoom)._subtract(viewHalf)._round();
Expand Down Expand Up @@ -141,7 +140,7 @@ L.Yandex = L.Layer.extend({
if (this._isOverlay) {
ymap.container.getElement().style.background = 'transparent';
}
this._container.remove(); // see onRemove comments
this._container.remove();
this._yandex = ymap;
if (this._map) { this.onAdd(this._map); }

Expand Down

0 comments on commit 67c9abb

Please sign in to comment.