From bca3e4594041034790b1ed2d22b0072809af6b02 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Tue, 15 May 2012 12:18:42 +0200 Subject: [PATCH 1/2] BBOX strategy should not request data if its layer is out of range when changing layer visibility --- lib/OpenLayers/Strategy/BBOX.js | 4 ++-- tests/Strategy/BBOX.html | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/OpenLayers/Strategy/BBOX.js b/lib/OpenLayers/Strategy/BBOX.js index 154a8ae6b2..a476b90cb8 100644 --- a/lib/OpenLayers/Strategy/BBOX.js +++ b/lib/OpenLayers/Strategy/BBOX.js @@ -87,7 +87,7 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, { "refresh": this.update, scope: this }); - if(this.layer.visibility === true && this.layer.inRange === true) { + if(this.layer.visibility === true) { this.update(); } else { this.layer.events.on({ @@ -134,7 +134,7 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, { update: function(options) { var mapBounds = this.getMapBounds(); if (mapBounds !== null && ((options && options.force) || - this.invalidBounds(mapBounds))) { + (this.layer.calculateInRange() && this.invalidBounds(mapBounds)))) { this.calculateBounds(mapBounds); this.resolution = this.layer.map.getResolution(); this.triggerRead(options); diff --git a/tests/Strategy/BBOX.html b/tests/Strategy/BBOX.html index 84c0ad02ee..4194b59175 100644 --- a/tests/Strategy/BBOX.html +++ b/tests/Strategy/BBOX.html @@ -305,7 +305,7 @@ // Test fix for Ticket #3142 function test_layerLoadedAfterBeingAdded(t) { - t.plan(2); + t.plan(3); var dummy = new OpenLayers.Layer(null, {isBaseLayer: true}); @@ -341,6 +341,11 @@ // test that the strategy bounds were set t.ok(map.getExtent().equals(strategy.bounds), "[set center] bounds set to map extent"); t.eq(layerOutOfRange.strategies[0].bounds, null, "Data not requested if layer is out of range"); + + layerOutOfRange.setVisibility(false); + layerOutOfRange.setVisibility(true); + t.eq(layerOutOfRange.strategies[0].bounds, null, "Data not requested if layer is out of range when switching visibility"); + map.destroy(); } From 44f9b8108545cc10585fc112c67b80dc8db3a559 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Tue, 15 May 2012 12:26:21 +0200 Subject: [PATCH 2/2] also check for visibility of the layer in the central place: the update function --- lib/OpenLayers/Strategy/BBOX.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/OpenLayers/Strategy/BBOX.js b/lib/OpenLayers/Strategy/BBOX.js index a476b90cb8..6df04b1a03 100644 --- a/lib/OpenLayers/Strategy/BBOX.js +++ b/lib/OpenLayers/Strategy/BBOX.js @@ -81,20 +81,11 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, { if(activated) { this.layer.events.on({ "moveend": this.update, - scope: this - }); - this.layer.events.on({ "refresh": this.update, + "visibilitychanged": this.update, scope: this }); - if(this.layer.visibility === true) { - this.update(); - } else { - this.layer.events.on({ - "visibilitychanged": this.update, - scope: this - }); - } + this.update(); } return activated; }, @@ -134,7 +125,7 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, { update: function(options) { var mapBounds = this.getMapBounds(); if (mapBounds !== null && ((options && options.force) || - (this.layer.calculateInRange() && this.invalidBounds(mapBounds)))) { + (this.layer.visibility && this.layer.calculateInRange() && this.invalidBounds(mapBounds)))) { this.calculateBounds(mapBounds); this.resolution = this.layer.map.getResolution(); this.triggerRead(options);