make updateSize not call setCenter if map has no center, and remove unused code, r=tschaub (closes #2105) (closes #2114)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9587 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2009-07-24 12:49:13 +00:00
parent 1faae2a2a2
commit f7a2efe2bf
2 changed files with 37 additions and 5 deletions

View File

@@ -1343,12 +1343,12 @@ OpenLayers.Map = OpenLayers.Class({
this.layers[i].onMapResize();
}
if (this.baseLayer != null) {
var center = new OpenLayers.Pixel(newSize.w /2, newSize.h / 2);
var centerLL = this.getLonLatFromViewPortPx(center);
var center = this.getCenter();
if (this.baseLayer != null && center != null) {
var zoom = this.getZoom();
this.zoom = null;
this.setCenter(this.getCenter(), zoom);
this.setCenter(center, zoom);
}
}

View File

@@ -1313,7 +1313,39 @@
map.destroy();
t.ok(!map.panTween || !map.panTween.playing, "the map pan tween is not playing after destroy");
}
function test_updateSize(t) {
t.plan(2);
var map, moveToCnt, size;
map = new OpenLayers.Map({div: "map"});
map.addLayer(new OpenLayers.Layer("layer", {isBaseLayer: true}));
map.moveTo = function() {
moveToCnt++;
OpenLayers.Map.prototype.moveTo.apply(this, arguments);
};
map.getCurrentSize = function() {
return size;
};
// map has no center
// 1 test
moveToCnt = 0;
size = new OpenLayers.Size(650, 350);
map.updateSize();
t.eq(moveToCnt, 0, "updateSize doesn't move the map if it doesn't have a center");
// map has a center
// 1 test
map.zoomToMaxExtent();
moveToCnt = 0;
size = new OpenLayers.Size(600, 300);
map.updateSize();
t.eq(moveToCnt, 1, "updateSize move the map if it has a center");
}
</script>