Skip to content

Commit

Permalink
Fix preview flickering on iOS devices (#542)
Browse files Browse the repository at this point in the history
* v3.6.2 Keep one <img /> per tile, transition from preview, to full by settings "src" attr
  • Loading branch information
itanka9 authored Dec 28, 2020
1 parent 5100be1 commit dcfdfc2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "2gis-maps",
"version": "3.6.1",
"version": "3.6.2",
"description": "Interactive 2GIS maps API, based on Leaflet",
"license": "SEE LICENSE IN FILE",
"keywords": [
Expand Down
34 changes: 16 additions & 18 deletions src/DGCustomization/src/DGMobileImprove.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(this._tileReady, this, coords), url);
var tile = this.createTile(wrapCoords, L.bind(needPreview ? this._previewReady : this._tileReady, this, coords), url);

this._initTile(tile);

Expand All @@ -391,6 +391,21 @@ 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
*/
Expand All @@ -412,23 +427,6 @@ 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();
Expand Down

0 comments on commit dcfdfc2

Please sign in to comment.