Invalidate _initialCenter along with size (fixes #1919)

This commit is contained in:
John Firebaugh 2013-08-05 13:58:54 -07:00
parent 16db077b2a
commit a0c6363bb6
2 changed files with 16 additions and 2 deletions

View File

@ -72,11 +72,24 @@ describe("Map", function () {
});
describe('#getCenter', function () {
it ('throws if not set before', function () {
it('throws if not set before', function () {
expect(function () {
map.getCenter();
}).to.throwError();
});
it('returns a precise center when zoomed in after being set (#426)', function () {
var center = L.latLng(10, 10);
map.setView(center, 1);
map.setZoom(19);
expect(map.getCenter()).to.eql(center);
});
it('returns correct center after invalidateSize (#1919)', function () {
map.setView(L.latLng(10, 10), 1);
map.invalidateSize();
expect(map.getCenter()).not.to.eql(L.latLng(10, 10));
});
});
describe("#whenReady", function () {

View File

@ -253,6 +253,7 @@ L.Map = L.Class.extend({
var oldSize = this.getSize();
this._sizeChanged = true;
this._initialCenter = null;
if (this.options.maxBounds) {
this.setMaxBounds(this.options.maxBounds);
@ -326,7 +327,7 @@ L.Map = L.Class.extend({
getCenter: function () { // (Boolean) -> LatLng
this._checkIfLoaded();
if (!this._moved()) {
if (this._initialCenter && !this._moved()) {
return this._initialCenter;
}
return this.layerPointToLatLng(this._getCenterLayerPoint());