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
This commit is contained in:
@@ -523,9 +523,13 @@ OpenLayers.Map.prototype = {
|
|||||||
var center = this.getCenter();
|
var center = this.getCenter();
|
||||||
if (center != null) {
|
if (center != null) {
|
||||||
if (oldExtent == null) {
|
if (oldExtent == null) {
|
||||||
this.setCenter(center);
|
// simply set center but force zoom change
|
||||||
|
this.setCenter(center, this.getZoom(), false, true);
|
||||||
} else {
|
} 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 {int} zoom
|
||||||
* @param {Boolean} dragging Specifies whether or not to
|
* @param {Boolean} dragging Specifies whether or not to
|
||||||
* trigger movestart/end events
|
* 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)) {
|
if (!this.center && !this.isValidLonLat(lonlat)) {
|
||||||
lonlat = this.maxExtent.getCenterLonLat();
|
lonlat = this.maxExtent.getCenterLonLat();
|
||||||
}
|
}
|
||||||
|
|
||||||
var zoomChanged = (this.isValidZoomLevel(zoom)) &&
|
var zoomChanged = forceZoomChange || (
|
||||||
(zoom != this.getZoom());
|
(this.isValidZoomLevel(zoom)) &&
|
||||||
|
(zoom != this.getZoom()) );
|
||||||
|
|
||||||
var centerChanged = (this.isValidLonLat(lonlat)) &&
|
var centerChanged = (this.isValidLonLat(lonlat)) &&
|
||||||
(!lonlat.equals(this.center));
|
(!lonlat.equals(this.center));
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
<script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>
|
||||||
<script src="../lib/OpenLayers.js"></script>
|
<script src="../lib/OpenLayers.js"></script>
|
||||||
<script type="text/javascript"><!--
|
<script type="text/javascript"><!--
|
||||||
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
|
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
|
||||||
@@ -261,7 +262,22 @@
|
|||||||
|
|
||||||
map.setBaseLayer(wmslayer2);
|
map.setBaseLayer(wmslayer2);
|
||||||
t.ok(map.baseLayer == wmslayer2, "setbaselayer correctly sets 'baseLayer' property");
|
t.ok(map.baseLayer == wmslayer2, "setbaselayer correctly sets 'baseLayer' property");
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_01_Map_setBaseLayer_after_pan (t) {
|
||||||
|
t.plan(1);
|
||||||
|
map = new OpenLayers.Map('map');
|
||||||
|
var wmsLayer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
|
||||||
|
"http://labs.metacarta.com/wms/vmap0", {layers: 'basic'} );
|
||||||
|
var google = new OpenLayers.Layer.Google("GOOG");
|
||||||
|
map.addLayers([wmsLayer,google]);
|
||||||
|
map.setBaseLayer(wmsLayer);
|
||||||
|
map.zoomToMaxExtent();
|
||||||
|
map.setBaseLayer(google);
|
||||||
|
map.zoomIn();
|
||||||
|
map.pan(0, -200);
|
||||||
|
map.setBaseLayer(wmsLayer);
|
||||||
|
t.eq(map.layerContainerDiv.style.top, "0px", "layerContainer is recentered after setBaseLayer");
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_12_Map_moveLayer (t) {
|
function test_12_Map_moveLayer (t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user