From a0c6363bb6f0bffe443ffbe8bd4c24da22e2fba4 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 5 Aug 2013 13:58:54 -0700 Subject: [PATCH] Invalidate _initialCenter along with size (fixes #1919) --- spec/suites/map/MapSpec.js | 15 ++++++++++++++- src/map/Map.js | 3 ++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js index 1c9069961..11e056196 100644 --- a/spec/suites/map/MapSpec.js +++ b/spec/suites/map/MapSpec.js @@ -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 () { diff --git a/src/map/Map.js b/src/map/Map.js index 62f16efbe..80757be97 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -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());