parent
2f6bd65efd
commit
0b4d2b0c44
@ -23,6 +23,7 @@
|
||||
|
||||
<!-- /control -->
|
||||
<script type="text/javascript" src="suites/control/Control.LayersSpec.js"></script>
|
||||
<script type="text/javascript" src="suites/control/Control.ScaleSpec.js"></script>
|
||||
|
||||
<!-- /core -->
|
||||
<script type="text/javascript" src="suites/core/UtilSpec.js"></script>
|
||||
|
6
spec/suites/control/Control.ScaleSpec.js
Normal file
6
spec/suites/control/Control.ScaleSpec.js
Normal file
@ -0,0 +1,6 @@
|
||||
describe("Control.Scale", function () {
|
||||
it("can be added to an unloaded map", function () {
|
||||
var map = L.map(document.createElement('div'));
|
||||
new L.Control.Scale().addTo(map);
|
||||
})
|
||||
});
|
@ -1,4 +1,31 @@
|
||||
describe("Map", function () {
|
||||
describe("#whenReady", function () {
|
||||
describe("when the map has not yet been loaded", function () {
|
||||
it("calls the callback when the map is loaded", function () {
|
||||
var map = L.map(document.createElement('div')),
|
||||
spy = jasmine.createSpy();
|
||||
|
||||
map.whenReady(spy);
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
|
||||
map.setView([0, 0], 1);
|
||||
expect(spy).toHaveBeenCalled();
|
||||
})
|
||||
});
|
||||
|
||||
describe("when the map has already been loaded", function () {
|
||||
it("calls the callback immediately", function () {
|
||||
var map = L.map(document.createElement('div')),
|
||||
spy = jasmine.createSpy();
|
||||
|
||||
map.setView([0, 0], 1);
|
||||
map.whenReady(spy);
|
||||
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#getBounds", function () {
|
||||
it("is safe to call from within a moveend callback during initial load (#1027)", function () {
|
||||
var c = document.createElement('div'),
|
||||
|
@ -17,7 +17,7 @@ L.Control.Scale = L.Control.extend({
|
||||
this._addScales(options, className, container);
|
||||
|
||||
map.on(options.updateWhenIdle ? 'moveend' : 'move', this._update, this);
|
||||
this._update();
|
||||
map.whenReady(this._update, this);
|
||||
|
||||
return container;
|
||||
},
|
||||
|
@ -162,16 +162,10 @@ L.Map = L.Class.extend({
|
||||
layer.on('load', this._onTileLayerLoad, this);
|
||||
}
|
||||
|
||||
var onMapLoad = function () {
|
||||
this.whenReady(function () {
|
||||
layer.onAdd(this);
|
||||
this.fire('layeradd', {layer: layer});
|
||||
};
|
||||
|
||||
if (this._loaded) {
|
||||
onMapLoad.call(this);
|
||||
} else {
|
||||
this.on('load', onMapLoad, this);
|
||||
}
|
||||
}, this);
|
||||
|
||||
return this;
|
||||
},
|
||||
@ -606,6 +600,15 @@ L.Map = L.Class.extend({
|
||||
}
|
||||
},
|
||||
|
||||
whenReady: function (callback, context) {
|
||||
if (this._loaded) {
|
||||
callback.call(context || this, this);
|
||||
} else {
|
||||
this.on('load', callback, context);
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
// private methods for getting map state
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user