Have NavigationHistory control deal with reprojection, r=ahocevar (closes #1997)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10261 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
bartvde
2010-04-30 14:52:38 +00:00
parent 0bb5ab8191
commit dc4d5036e4
2 changed files with 61 additions and 3 deletions

View File

@@ -294,7 +294,10 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
getState: function() {
return {
center: this.map.getCenter(),
resolution: this.map.getResolution()
resolution: this.map.getResolution(),
projection: this.map.getProjectionObject(),
units: this.map.getProjectionObject().getUnits() ||
this.map.units || this.map.baseLayer.units
};
},
@@ -306,8 +309,21 @@ OpenLayers.Control.NavigationHistory = OpenLayers.Class(OpenLayers.Control, {
* state - {Object} An object representing the state to restore.
*/
restore: function(state) {
var zoom = this.map.getZoomForResolution(state.resolution);
this.map.setCenter(state.center, zoom);
var center, zoom;
if (this.map.getProjectionObject() == state.projection) {
zoom = this.map.getZoomForResolution(state.resolution);
center = state.center;
} else {
center = state.center.clone();
center.transform(state.projection, this.map.getProjectionObject());
var sourceUnits = state.units;
var targetUnits = this.map.getProjectionObject().getUnits() ||
this.map.units || this.map.baseLayer.units;
var resolutionFactor = sourceUnits && targetUnits ?
OpenLayers.INCHES_PER_UNIT[sourceUnits] / OpenLayers.INCHES_PER_UNIT[targetUnits] : 1;
zoom = this.map.getZoomForResolution(resolutionFactor*state.resolution);
}
this.map.setCenter(center, zoom);
},
/**