Skip to content

Commit

Permalink
Merge f6f4b65 into 7f97fa0
Browse files Browse the repository at this point in the history
  • Loading branch information
Trufi committed Mar 4, 2015
2 parents 7f97fa0 + f6f4b65 commit c905e25
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var deps = {
'DGCustomization/src/DGCustomization.js',
'DGCustomization/src/DGMap.js',
'DGCustomization/src/DGMap.BaseLayer.js',
'DGCustomization/src/DGMap.TilesCheck.js',
'DGCustomization/src/DGPopup.js',
'DGCustomization/src/DGZoom.js',
'DGCustomization/lang/DGZoom/ru.js',
Expand Down
58 changes: 58 additions & 0 deletions src/DGCustomization/src/DGMap.TilesCheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
DG.Map.mergeOptions({
tilesCheck: true
});

DG.Map.TilesCheck = DG.Handler.extend({
initialize: function (map) {
this._map = map;
this._layer = map.baseLayer;

this._tileLoadArray = [];
},

addHooks: function () {
this._map.on(this._mapEvents, this);
this._layer.on(this._layerEvents, this);
},

removeHooks: function () {
this._map.off(this._mapEvents, this);
this._layer.off(this._layerEvents, this);
},

_mapEvents: {
layeradd: function (e) {
if (e.layer == this._layer) {
this.enable();
}
},
layerremove: function (e) {
if (e.layer == this._layer) {
this.disable();
}
}
},

_layerEvents: {
loading: function () {
this._tileLoadArray = [];
},
tileload: function (obj) {
this._tileLoadArray.push(obj.tile);
},
load: function () {
if (this._map._tileLayersNumber !== 0) { return; }

var errorUrl = this._layer.options.errorTileUrl;
var isSuccess = this._tileLoadArray.some(function (tile) {
return tile.src !== errorUrl;
});

if (!isSuccess) {
this._map.zoomOut();
}
}
}
});

DG.Map.addInitHook('addHandler', 'tilesCheck', DG.Map.TilesCheck);

0 comments on commit c905e25

Please sign in to comment.