throw meaningful exception on getCenter before setView, close #1395

This commit is contained in:
Vladimir Agafonkin 2013-02-19 16:54:29 +02:00
parent 879b9f987b
commit d98b4ea035
2 changed files with 14 additions and 7 deletions

View File

@ -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 () {

View File

@ -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) {