Adding an option to make the bbox strategy more agressive. Thanks for completing the tests crschmidt. r=crschmidt,igrcic (closes #1830)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9087 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -24,6 +24,12 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, {
|
|||||||
*/
|
*/
|
||||||
bounds: null,
|
bounds: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: resolution
|
||||||
|
* {Float} The current data resolution.
|
||||||
|
*/
|
||||||
|
resolution: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIProperty: ratio
|
* APIProperty: ratio
|
||||||
* {Float} The ratio of the data bounds to the viewport bounds (in each
|
* {Float} The ratio of the data bounds to the viewport bounds (in each
|
||||||
@@ -31,6 +37,21 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, {
|
|||||||
*/
|
*/
|
||||||
ratio: 2,
|
ratio: 2,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: resFactor
|
||||||
|
* {Float} Optional factor used to determine when previously requested
|
||||||
|
* features are invalid. If set, the resFactor will be compared to the
|
||||||
|
* resolution of the previous request to the current map resolution.
|
||||||
|
* If resFactor > (old / new) and 1/resFactor < (old / new). If you
|
||||||
|
* set a resFactor of 1, data will be requested every time the
|
||||||
|
* resolution changes. If you set a resFactor of 3, data will be
|
||||||
|
* requested if the old resolution is 3 times the new, or if the new is
|
||||||
|
* 3 times the old. If the old bounds do not contain the new bounds
|
||||||
|
* new data will always be requested (with or without considering
|
||||||
|
* resFactor).
|
||||||
|
*/
|
||||||
|
resFactor: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Property: response
|
* Property: response
|
||||||
* {<OpenLayers.Protocol.Response>} The protocol response object returned
|
* {<OpenLayers.Protocol.Response>} The protocol response object returned
|
||||||
@@ -107,6 +128,7 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, {
|
|||||||
var mapBounds = this.getMapBounds();
|
var mapBounds = this.getMapBounds();
|
||||||
if ((options && options.force) || this.invalidBounds(mapBounds)) {
|
if ((options && options.force) || this.invalidBounds(mapBounds)) {
|
||||||
this.calculateBounds(mapBounds);
|
this.calculateBounds(mapBounds);
|
||||||
|
this.resolution = this.layer.map.getResolution();
|
||||||
this.triggerRead();
|
this.triggerRead();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -130,6 +152,10 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Method: invalidBounds
|
* Method: invalidBounds
|
||||||
|
* Determine whether the previously requested set of features is invalid.
|
||||||
|
* This occurs when the new map bounds do not contain the previously
|
||||||
|
* requested bounds. In addition, if <resFactor> is set, it will be
|
||||||
|
* considered.
|
||||||
*
|
*
|
||||||
* Parameters:
|
* Parameters:
|
||||||
* mapBounds - {<OpenLayers.Bounds>} the current map extent, will be
|
* mapBounds - {<OpenLayers.Bounds>} the current map extent, will be
|
||||||
@@ -142,7 +168,12 @@ OpenLayers.Strategy.BBOX = OpenLayers.Class(OpenLayers.Strategy, {
|
|||||||
if(!mapBounds) {
|
if(!mapBounds) {
|
||||||
mapBounds = this.getMapBounds();
|
mapBounds = this.getMapBounds();
|
||||||
}
|
}
|
||||||
return !this.bounds || !this.bounds.containsBounds(mapBounds);
|
var invalid = !this.bounds || !this.bounds.containsBounds(mapBounds);
|
||||||
|
if(!invalid && this.resFactor) {
|
||||||
|
var ratio = this.resolution / this.layer.map.getResolution();
|
||||||
|
invalid = (ratio >= this.resFactor || ratio <= (1 / this.resFactor));
|
||||||
|
}
|
||||||
|
return invalid;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -166,6 +166,33 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_resFactor(t) {
|
||||||
|
t.plan(2);
|
||||||
|
|
||||||
|
var map = new OpenLayers.Map("map");
|
||||||
|
var bbox = new OpenLayers.Strategy.BBOX();
|
||||||
|
var fakeProtocol = new OpenLayers.Protocol({
|
||||||
|
'read': function() {
|
||||||
|
t.ok(true, "read called once without resfactor");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var layer = new OpenLayers.Layer.Vector("test", {
|
||||||
|
strategies: [bbox],
|
||||||
|
protocol: fakeProtocol,
|
||||||
|
isBaseLayer: true
|
||||||
|
});
|
||||||
|
map.addLayer(layer);
|
||||||
|
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
||||||
|
map.zoomIn();
|
||||||
|
|
||||||
|
fakeProtocol.read = function() {
|
||||||
|
t.ok("read called again on zooming with resFactor: 1");
|
||||||
|
}
|
||||||
|
bbox.resFactor = 1;
|
||||||
|
map.zoomIn();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function test_createFilter(t) {
|
function test_createFilter(t) {
|
||||||
t.plan(3);
|
t.plan(3);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user