throw meaningful exception on getCenter before setView, close #1395
This commit is contained in:
parent
879b9f987b
commit
d98b4ea035
@ -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 () {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user