parent
2f6bd65efd
commit
0b4d2b0c44
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
<!-- /control -->
|
<!-- /control -->
|
||||||
<script type="text/javascript" src="suites/control/Control.LayersSpec.js"></script>
|
<script type="text/javascript" src="suites/control/Control.LayersSpec.js"></script>
|
||||||
|
<script type="text/javascript" src="suites/control/Control.ScaleSpec.js"></script>
|
||||||
|
|
||||||
<!-- /core -->
|
<!-- /core -->
|
||||||
<script type="text/javascript" src="suites/core/UtilSpec.js"></script>
|
<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("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 () {
|
describe("#getBounds", function () {
|
||||||
it("is safe to call from within a moveend callback during initial load (#1027)", function () {
|
it("is safe to call from within a moveend callback during initial load (#1027)", function () {
|
||||||
var c = document.createElement('div'),
|
var c = document.createElement('div'),
|
||||||
|
@ -17,7 +17,7 @@ L.Control.Scale = L.Control.extend({
|
|||||||
this._addScales(options, className, container);
|
this._addScales(options, className, container);
|
||||||
|
|
||||||
map.on(options.updateWhenIdle ? 'moveend' : 'move', this._update, this);
|
map.on(options.updateWhenIdle ? 'moveend' : 'move', this._update, this);
|
||||||
this._update();
|
map.whenReady(this._update, this);
|
||||||
|
|
||||||
return container;
|
return container;
|
||||||
},
|
},
|
||||||
|
@ -162,16 +162,10 @@ L.Map = L.Class.extend({
|
|||||||
layer.on('load', this._onTileLayerLoad, this);
|
layer.on('load', this._onTileLayerLoad, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
var onMapLoad = function () {
|
this.whenReady(function () {
|
||||||
layer.onAdd(this);
|
layer.onAdd(this);
|
||||||
this.fire('layeradd', {layer: layer});
|
this.fire('layeradd', {layer: layer});
|
||||||
};
|
}, this);
|
||||||
|
|
||||||
if (this._loaded) {
|
|
||||||
onMapLoad.call(this);
|
|
||||||
} else {
|
|
||||||
this.on('load', onMapLoad, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 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
|
// private methods for getting map state
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user