From 579c2e5e629898b23d48edfecd31ac3c0189d459 Mon Sep 17 00:00:00 2001 From: itanka9 Date: Thu, 11 Mar 2021 08:30:55 +0300 Subject: [PATCH] Revert "Fix preview flickering on iOS devices (#542)" (#545) This reverts commit dcfdfc27f2ab88fda5a504db84857ab589ea8eff. --- src/DGCustomization/src/DGMobileImprove.js | 34 ++++++++++++---------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/DGCustomization/src/DGMobileImprove.js b/src/DGCustomization/src/DGMobileImprove.js index 01cc7a605..c83cac601 100644 --- a/src/DGCustomization/src/DGMobileImprove.js +++ b/src/DGCustomization/src/DGMobileImprove.js @@ -368,7 +368,7 @@ L.MobileTileLayer = L.TileLayer.extend({ var needPreview = this._needPreviewTile(wrapCoords); var url = needPreview ? this._previewUrl : this._url; - var tile = this.createTile(wrapCoords, L.bind(needPreview ? this._previewReady : this._tileReady, this, coords), url); + var tile = this.createTile(wrapCoords, L.bind(this._tileReady, this, coords), url); this._initTile(tile); @@ -391,21 +391,6 @@ L.MobileTileLayer = L.TileLayer.extend({ }); }, - _previewReady: function(coords, err, tile) { - if (!this._map) { return; } - - var key = this._tileCoordsToKey(coords); - - tile = this._tiles[key]; - if (!tile) { return; } - - - tile.el.onload = L.bind(this._tileReady, this, coords, err, tile); - tile.el.onerror = L.bind(this._tileReady, this, coords, err, tile); - tile.el.src = this.getTileUrl(coords, this._url); - }, - - /** * Убран fadeAnimated и класс leaflet-tile-loaded */ @@ -427,6 +412,23 @@ L.MobileTileLayer = L.TileLayer.extend({ tile = this._tiles[key]; if (!tile) { return; } + // Если у тайла уже есть оригинальная (не пожатая) картинка, + // то заменим превью на нее + if (tile.originalEl && tile.el.parentNode) { + tile.el.parentNode.replaceChild(tile.originalEl, tile.el); + tile.el = tile.originalEl; + + tile.originalEl = null; + tile.preview = false; + + // Если у тайла есть только превью, то добавим его на карту + // И начнем грузить оригинальный + } else if (tile.preview) { + tile.originalEl = this.createTile(this._wrapCoords(coords), L.bind(this._tileReady, this, coords), this._url); + this._initTile(tile.originalEl); + L.DomUtil.setPosition(tile.originalEl, this._getTilePos(coords)); + } + tile.loaded = +new Date(); tile.active = true; this._pruneTiles();