2015-09-01 16:59:03 +02:00
|
|
|
function onDocumentReady(){
|
|
|
|
if (typeof L != 'undefined') {
|
|
|
|
L.SpinMapMixin = {
|
|
|
|
spin: function (state, options) {
|
|
|
|
if (!!state) {
|
|
|
|
// start spinning !
|
|
|
|
if (!this._spinner) {
|
|
|
|
this._spinner = new Spinner(options).spin(this._container);
|
|
|
|
this._spinning = 0;
|
|
|
|
}
|
|
|
|
this._spinning++;
|
2015-08-24 11:41:50 +02:00
|
|
|
}
|
2015-09-01 16:59:03 +02:00
|
|
|
else {
|
|
|
|
this._spinning--;
|
|
|
|
if (this._spinning <= 0) {
|
|
|
|
// end spinning !
|
|
|
|
if (this._spinner) {
|
|
|
|
this._spinner.stop();
|
|
|
|
this._spinner = null;
|
|
|
|
}
|
2015-08-24 11:41:50 +02:00
|
|
|
}
|
2015-08-10 11:05:06 +02:00
|
|
|
}
|
|
|
|
}
|
2015-09-01 16:59:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
L.Map.include(L.SpinMapMixin);
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2015-09-01 16:59:03 +02:00
|
|
|
L.Map.addInitHook(function () {
|
|
|
|
this.on('layeradd', function (e) {
|
|
|
|
// If added layer is currently loading, spin !
|
|
|
|
if (e.layer.loading) this.spin(true);
|
|
|
|
if (typeof e.layer.on != 'function') return;
|
|
|
|
e.layer.on('data:loading', function () { this.spin(true); }, this);
|
|
|
|
e.layer.on('data:loaded', function () { this.spin(false); }, this);
|
|
|
|
}, this);
|
|
|
|
this.on('layerremove', function (e) {
|
|
|
|
// Clean-up
|
|
|
|
if (e.layer.loading) this.spin(false);
|
|
|
|
if (typeof e.layer.on != 'function') return;
|
|
|
|
e.layer.off('data:loaded');
|
|
|
|
e.layer.off('data:loading');
|
|
|
|
}, this);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2015-09-01 16:59:03 +02:00
|
|
|
$(document).ready(onDocumentReady);
|
|
|
|
$(document).on('page:load', onDocumentReady);
|