fix rounding error when changing zoom, close #426

This commit is contained in:
Vladimir Agafonkin 2013-02-20 20:11:47 +02:00
parent 97454596c6
commit cf00a0113d

View File

@ -249,6 +249,11 @@ L.Map = L.Class.extend({
// public methods for getting map state
getCenter: function () { // (Boolean) -> LatLng
this._checkIfLoaded();
if (!this._moved()) {
return this._initialCenter;s
}
return this.layerPointToLatLng(this._getCenterLayerPoint());
},
@ -336,9 +341,7 @@ L.Map = L.Class.extend({
},
getPixelOrigin: function () {
if (!this._loaded) {
throw new Error('Set map center and zoom first.');
}
this._checkIfLoaded();
return this._initialTopLeftPoint;
},
@ -508,6 +511,7 @@ L.Map = L.Class.extend({
}
this._zoom = zoom;
this._initialCenter = center;
this._initialTopLeftPoint = this._getNewTopLeftPoint(center);
@ -575,6 +579,12 @@ L.Map = L.Class.extend({
}
},
_checkIfLoaded: function () {
if (!this._loaded) {
throw new Error('Set map center and zoom first.');
}
},
// map events
_initEvents: function (onOff) {
@ -658,6 +668,11 @@ L.Map = L.Class.extend({
return L.DomUtil.getPosition(this._mapPane);
},
_moved: function () {
var pos = this._getMapPanePos();
return pos && !pos.equals(new L.Point(0, 0));
},
_getTopLeftPoint: function () {
return this.getPixelOrigin().subtract(this._getMapPanePos());
},