diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js index 4826920fa..1789b2154 100644 --- a/spec/suites/map/MapSpec.js +++ b/spec/suites/map/MapSpec.js @@ -6,6 +6,14 @@ describe("Map", function () { spy = jasmine.createSpy(); }); + describe('#getCenter', function () { + it ('should throw if not set before', function () { + expect(function () { + map.getCenter(); + }).toThrow(); + }); + }); + describe("#whenReady", function () { describe("when the map has not yet been loaded", function () { it("calls the callback when the map is loaded", function () { diff --git a/src/map/Map.js b/src/map/Map.js index b88cee0e7..f1f41647b 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -330,6 +330,9 @@ L.Map = L.Class.extend({ }, getPixelOrigin: function () { + if (!this._loaded) { + throw new Error('Set map center and zoom first.'); + } return this._initialTopLeftPoint; }, @@ -367,13 +370,13 @@ L.Map = L.Class.extend({ }, layerPointToLatLng: function (point) { // (Point) - var projectedPoint = L.point(point).add(this._initialTopLeftPoint); + var projectedPoint = L.point(point).add(this.getPixelOrigin()); return this.unproject(projectedPoint); }, latLngToLayerPoint: function (latlng) { // (LatLng) var projectedPoint = this.project(L.latLng(latlng))._round(); - return projectedPoint._subtract(this._initialTopLeftPoint); + return projectedPoint._subtract(this.getPixelOrigin()); }, containerPointToLayerPoint: function (point) { // (Point) @@ -651,11 +654,7 @@ L.Map = L.Class.extend({ }, _getTopLeftPoint: function () { - if (!this._loaded) { - throw new Error('Set map center and zoom first.'); - } - - return this._initialTopLeftPoint.subtract(this._getMapPanePos()); + return this.getPixelOrigin().subtract(this._getMapPanePos()); }, _getNewTopLeftPoint: function (center, zoom) {