From 4968e0e59c4803d378985dc0a37546b87b3935f2 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Tue, 10 Apr 2007 10:30:49 +0000 Subject: [PATCH] Commit Fix for #654: Layer should not redraw on setVisibility(false). For some layers, this is a significant performance enhancement. Includes regression tests. git-svn-id: http://svn.openlayers.org/trunk/openlayers@3041 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer.js | 2 +- tests/test_Layer.html | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Layer.js b/lib/OpenLayers/Layer.js index a4dc37263e..fe82f36318 100644 --- a/lib/OpenLayers/Layer.js +++ b/lib/OpenLayers/Layer.js @@ -347,7 +347,7 @@ OpenLayers.Layer.prototype = { if (visibility != this.visibility) { this.visibility = visibility; this.display(visibility); - if (this.map != null) { + if (visibility && this.map != null) { var extent = this.map.getExtent(); if (extent != null) { this.moveTo(extent, true); diff --git a/tests/test_Layer.html b/tests/test_Layer.html index 7767e80945..920f4706bb 100644 --- a/tests/test_Layer.html +++ b/tests/test_Layer.html @@ -118,7 +118,7 @@ function test_05_Layer_visibility(t) { - t.plan(3) + t.plan(5) var layer = new OpenLayers.Layer('Test Layer'); @@ -129,6 +129,22 @@ layer.setVisibility(true); t.eq(layer.getVisibility(), true, "setVisibility true works"); + + // Need a map in order to have moveTo called. + // Tests added for #654. + var layer = new OpenLayers.Layer.WMS('Test Layer','http://example.com'); + var m = new OpenLayers.Map('map'); + m.addLayer(layer); + m.zoomToMaxExtent(); + + layermoved = false; + layer.moveTo = function() { layermoved = true; } + + layer.setVisibility(false); + t.eq(layermoved, false, "Layer didn't move when calling setvis false"); + + layer.setVisibility(true); + t.eq(layermoved, true, "Layer moved when calling setvis true."); }