Skip to content

Commit 4fb359e

Browse files
authored
TILES-6268 preview tiles for ios (#594)
* TILES-6268 preview tiles for ios
1 parent 9c78cfb commit 4fb359e

1 file changed

Lines changed: 52 additions & 16 deletions

File tree

src/DGCustomization/src/DGMobileImprove.js

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ if (DG.Browser.mobile) {
146146
L.MobileTileLayer = L.TileLayer.extend({
147147
initialize: function(url, options) {
148148
L.TileLayer.prototype.initialize.call(this, url, options);
149-
149+
this._appleDevice = this._isAppleDevice()
150150
this._previewUrl = options.previewUrl;
151151
},
152152

@@ -357,6 +357,26 @@ L.MobileTileLayer = L.TileLayer.extend({
357357
return true;
358358
},
359359

360+
_isAppleDevice: function() {
361+
var appleMobileRE = /ip(hone|od)/i;
362+
var appleTabletRE = /ipad/i;
363+
var touchMacRE = /Macintosh/i;
364+
365+
var ua = typeof navigator !== 'undefined' ? navigator.userAgent : '';
366+
367+
if (!ua) {
368+
return false;
369+
}
370+
371+
var isAppleMobile = appleMobileRE.test(ua);
372+
var isAppleTablet = appleTabletRE.test(ua);
373+
374+
var isTouchMac =
375+
navigator.maxTouchPoints > 1 && touchMacRE.test(ua) && ua.indexOf('Safari') !== -1;
376+
377+
return isAppleMobile || isAppleTablet || isTouchMac;
378+
},
379+
360380
/**
361381
* Добавлена логика с превью тайлами
362382
*/
@@ -368,7 +388,8 @@ L.MobileTileLayer = L.TileLayer.extend({
368388
var needPreview = this._needPreviewTile(wrapCoords);
369389

370390
var url = needPreview ? this._previewUrl : this._url;
371-
var tile = this.createTile(wrapCoords, L.bind(this._tileReady, this, coords), url);
391+
var showPreviewForIphone = this._appleDevice && needPreview;
392+
var tile = this.createTile(wrapCoords, L.bind(showPreviewForIphone ? this._previewReady : this._tileReady, this, coords), url);
372393

373394
this._initTile(tile);
374395

@@ -391,6 +412,20 @@ L.MobileTileLayer = L.TileLayer.extend({
391412
});
392413
},
393414

415+
_previewReady: function(coords, err, tile) {
416+
if (!this._map) { return; }
417+
418+
var key = this._tileCoordsToKey(coords);
419+
420+
tile = this._tiles[key];
421+
if (!tile) { return; }
422+
423+
424+
tile.el.onload = L.bind(this._tileReady, this, coords, err, tile);
425+
tile.el.onerror = L.bind(this._tileReady, this, coords, err, tile);
426+
tile.el.src = this.getTileUrl(coords, this._url);
427+
},
428+
394429
/**
395430
* Убран fadeAnimated и класс leaflet-tile-loaded
396431
*/
@@ -412,23 +447,24 @@ L.MobileTileLayer = L.TileLayer.extend({
412447
tile = this._tiles[key];
413448
if (!tile) { return; }
414449

450+
if (!this._appleDevice) {
415451
// Если у тайла уже есть оригинальная (не пожатая) картинка,
416452
// то заменим превью на нее
417-
if (tile.originalEl && tile.el.parentNode) {
418-
tile.el.parentNode.replaceChild(tile.originalEl, tile.el);
419-
tile.el = tile.originalEl;
420-
421-
tile.originalEl = null;
422-
tile.preview = false;
423-
424-
// Если у тайла есть только превью, то добавим его на карту
425-
// И начнем грузить оригинальный
426-
} else if (tile.preview) {
427-
tile.originalEl = this.createTile(this._wrapCoords(coords), L.bind(this._tileReady, this, coords), this._url);
428-
this._initTile(tile.originalEl);
429-
L.DomUtil.setPosition(tile.originalEl, this._getTilePos(coords));
453+
if (tile.originalEl && tile.el.parentNode) {
454+
tile.el.parentNode.replaceChild(tile.originalEl, tile.el);
455+
tile.el = tile.originalEl;
456+
457+
tile.originalEl = null;
458+
tile.preview = false;
459+
460+
// Если у тайла есть только превью, то добавим его на карту
461+
// И начнем грузить оригинальный
462+
} else if (tile.preview) {
463+
tile.originalEl = this.createTile(this._wrapCoords(coords), L.bind(this._tileReady, this, coords), this._url);
464+
this._initTile(tile.originalEl);
465+
L.DomUtil.setPosition(tile.originalEl, this._getTilePos(coords));
466+
}
430467
}
431-
432468
tile.loaded = +new Date();
433469
tile.active = true;
434470
this._pruneTiles();

0 commit comments

Comments
 (0)