Strategy.Fixed should listen to refresh event, (Closes #1939), r=tschaub
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9164 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -299,7 +299,7 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
|
||||
* the refresh event.
|
||||
*/
|
||||
refresh: function(obj) {
|
||||
if(this.inRange && this.visibility) {
|
||||
if(this.calculateInRange() && this.visibility) {
|
||||
this.events.triggerEvent("refresh", obj);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -53,6 +53,10 @@ OpenLayers.Strategy.Fixed = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
*/
|
||||
activate: function() {
|
||||
if(OpenLayers.Strategy.prototype.activate.apply(this, arguments)) {
|
||||
this.layer.events.on({
|
||||
"refresh": this.load,
|
||||
scope: this
|
||||
});
|
||||
if(this.layer.visibility == true || this.preload) {
|
||||
this.load();
|
||||
} else {
|
||||
@@ -66,16 +70,38 @@ OpenLayers.Strategy.Fixed = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: deactivate
|
||||
* Deactivate the strategy. Undo what is done in <activate>.
|
||||
*
|
||||
* Returns:
|
||||
* {Boolean} The strategy was successfully deactivated.
|
||||
*/
|
||||
deactivate: function() {
|
||||
var deactivated = OpenLayers.Strategy.prototype.deactivate.call(this);
|
||||
if(deactivated) {
|
||||
this.layer.events.un({
|
||||
"refresh": this.load,
|
||||
"visibilitychanged": this.load,
|
||||
scope: this
|
||||
});
|
||||
}
|
||||
return deactivated;
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: load
|
||||
* Tells protocol to load data and unhooks the visibilitychanged event
|
||||
*
|
||||
* Parameters:
|
||||
* options - {Object} options to pass to protocol read.
|
||||
*/
|
||||
load: function() {
|
||||
load: function(options) {
|
||||
this.layer.events.triggerEvent("loadstart");
|
||||
this.layer.protocol.read({
|
||||
this.layer.protocol.read(OpenLayers.Util.applyDefaults({
|
||||
callback: this.merge,
|
||||
scope: this
|
||||
});
|
||||
}, options));
|
||||
this.layer.events.un({
|
||||
"visibilitychanged": this.load,
|
||||
scope: this
|
||||
@@ -87,6 +113,7 @@ OpenLayers.Strategy.Fixed = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
* Add all features to the layer.
|
||||
*/
|
||||
merge: function(resp) {
|
||||
this.layer.destroyFeatures();
|
||||
var features = resp.features;
|
||||
if (features && features.length > 0) {
|
||||
var remote = this.layer.projection;
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
|
||||
function test_events(t) {
|
||||
|
||||
t.plan(2);
|
||||
t.plan(3);
|
||||
|
||||
var log = {
|
||||
loadstart: 0,
|
||||
@@ -93,6 +93,13 @@
|
||||
|
||||
t.eq(log.loadstart, 1, "loadstart triggered");
|
||||
t.eq(log.loadend, 1, "loadend triggered");
|
||||
var log = {};
|
||||
layer.protocol.read = function(obj) {
|
||||
log.obj = obj;
|
||||
}
|
||||
layer.refresh({whee: 'chicken'});
|
||||
|
||||
t.eq(log.obj && log.obj.whee, "chicken", "properties passed to read on refresh correctly.");
|
||||
|
||||
map.destroy();
|
||||
|
||||
@@ -101,7 +108,7 @@
|
||||
|
||||
function test_merge(t) {
|
||||
|
||||
t.plan(5);
|
||||
t.plan(6);
|
||||
|
||||
var strategy = new OpenLayers.Strategy.Fixed();
|
||||
|
||||
@@ -124,6 +131,14 @@
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// give the layer some existing features (one)
|
||||
layer.addFeatures([
|
||||
new OpenLayers.Feature.Vector(
|
||||
new OpenLayers.Geometry.Point(0, 0)
|
||||
)
|
||||
]);
|
||||
|
||||
map.addLayer(layer);
|
||||
map.zoomToMaxExtent();
|
||||
|
||||
@@ -140,6 +155,9 @@
|
||||
// call merge with a mocked up response
|
||||
strategy.merge({features: features});
|
||||
|
||||
// confirm that the original features were destroyed
|
||||
t.eq(layer.features.length, 2, "old features destroyed");
|
||||
|
||||
// confirm that loadend was called
|
||||
t.eq(log.loadend, 1, "merge triggers loadend");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user