Files
openlayers/lib/OpenLayers/Strategy/Fixed.js
crschmidt 256f027c7c Commit a change to the Strategy/Fixed to behave more like GeoRSS/Text/GML
layers, and not load by default if the layer is not visible. Includes tests.
Default Behavior can be changed with 
'OpenLayers.Strategy.Fixed.prototype.preload=true;'. With review from elemoine,
comments from tschaub, review from me. Patch by Edgemaster. (Closes #1852) 


git-svn-id: http://svn.openlayers.org/trunk/openlayers@8775 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
2009-01-28 01:43:04 +00:00

97 lines
2.6 KiB
JavaScript

/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
* full text of the license. */
/**
* @requires OpenLayers/Strategy.js
*/
/**
* Class: OpenLayers.Strategy.Fixed
* A simple strategy that requests features once and never requests new data.
*
* Inherits from:
* - <OpenLayers.Strategy>
*/
OpenLayers.Strategy.Fixed = OpenLayers.Class(OpenLayers.Strategy, {
/**
* APIProperty: preload
* {Boolean} Load data before layer made visible. Enabling this may result
* in considerable overhead if your application loads many data layers
* that are not visible by default. Default is true.
*/
preload: false,
/**
* Constructor: OpenLayers.Strategy.Fixed
* Create a new Fixed strategy.
*
* Parameters:
* options - {Object} Optional object whose properties will be set on the
* instance.
*/
initialize: function(options) {
OpenLayers.Strategy.prototype.initialize.apply(this, [options]);
},
/**
* APIMethod: destroy
* Clean up the strategy.
*/
destroy: function() {
OpenLayers.Strategy.prototype.destroy.apply(this, arguments);
},
/**
* Method: activate
* Activate the strategy: load data or add listener to load when visible
*
* Returns:
* {Boolean} True if the strategy was successfully activated or false if
* the strategy was already active.
*/
activate: function() {
if(OpenLayers.Strategy.prototype.activate.apply(this, arguments)) {
if(this.layer.visibility == true || this.preload) {
this.load();
} else {
this.layer.events.on({
"visibilitychanged": this.load,
scope: this
});
}
return true;
}
return false;
},
/**
* Method: load
* Tells protocol to load data and unhooks the visibilitychanged event
*/
load: function() {
this.layer.protocol.read({
callback: this.merge,
scope: this
});
this.layer.events.un({
"visibilitychanged": this.load,
scope: this
});
},
/**
* Method: merge
* Add all features to the layer.
*/
merge: function(resp) {
var features = resp.features;
if (features && features.length > 0) {
this.layer.addFeatures(features);
}
},
CLASS_NAME: "OpenLayers.Strategy.Fixed"
});