From 75b81b23741608f79591decdeb291c9cb7c90f08 Mon Sep 17 00:00:00 2001 From: Schuyler Erle Date: Sun, 1 Apr 2007 20:47:52 +0000 Subject: [PATCH] Add 4th arg to map.setCenter() to force zoom change, and change map.setBaseLayer() to use it on every base layer change, regardless of whether the numeric zoom level itself actually changes. Includes test. Fixes #450. git-svn-id: http://svn.openlayers.org/trunk/openlayers@2952 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Map.js | 21 ++++++++++++++++----- tests/test_Map.html | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lib/OpenLayers/Map.js b/lib/OpenLayers/Map.js index 816ee5399b..c2bb9f0e28 100644 --- a/lib/OpenLayers/Map.js +++ b/lib/OpenLayers/Map.js @@ -523,9 +523,13 @@ OpenLayers.Map.prototype = { var center = this.getCenter(); if (center != null) { if (oldExtent == null) { - this.setCenter(center); + // simply set center but force zoom change + this.setCenter(center, this.getZoom(), false, true); } else { - this.zoomToExtent(oldExtent); + // zoom to oldExtent *and* force zoom change + this.setCenter(oldExtent.getCenterLonLat(), + this.getZoomForExtent(oldExtent), + false, true); } } @@ -770,15 +774,22 @@ OpenLayers.Map.prototype = { * @param {int} zoom * @param {Boolean} dragging Specifies whether or not to * trigger movestart/end events + * @param {Boolean} forceZoomChange + * Specifies whether or not to + * trigger zoom change events + * (needed on baseLayer change) + * + * TBD: reconsider forceZoomChange in 3.0 */ - setCenter: function (lonlat, zoom, dragging) { + setCenter: function (lonlat, zoom, dragging, forceZoomChange) { if (!this.center && !this.isValidLonLat(lonlat)) { lonlat = this.maxExtent.getCenterLonLat(); } - var zoomChanged = (this.isValidZoomLevel(zoom)) && - (zoom != this.getZoom()); + var zoomChanged = forceZoomChange || ( + (this.isValidZoomLevel(zoom)) && + (zoom != this.getZoom()) ); var centerChanged = (this.isValidLonLat(lonlat)) && (!lonlat.equals(this.center)); diff --git a/tests/test_Map.html b/tests/test_Map.html index af38301d80..690834a2d4 100644 --- a/tests/test_Map.html +++ b/tests/test_Map.html @@ -1,5 +1,6 @@ +