1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2 * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3 * full text of the license. */
6 * @requires OpenLayers/Strategy.js
10 * Class: OpenLayers.Strategy.Fixed
11 * A simple strategy that requests features once and never requests new data.
14 * - <OpenLayers.Strategy>
16 OpenLayers.Strategy.Fixed = OpenLayers.Class(OpenLayers.Strategy, {
19 * APIProperty: preload
20 * {Boolean} Load data before layer made visible. Enabling this may result
21 * in considerable overhead if your application loads many data layers
22 * that are not visible by default. Default is true.
27 * Constructor: OpenLayers.Strategy.Fixed
28 * Create a new Fixed strategy.
31 * options - {Object} Optional object whose properties will be set on the
34 initialize: function(options) {
35 OpenLayers.Strategy.prototype.initialize.apply(this, [options]);
40 * Clean up the strategy.
43 OpenLayers.Strategy.prototype.destroy.apply(this, arguments);
48 * Activate the strategy: load data or add listener to load when visible
51 * {Boolean} True if the strategy was successfully activated or false if
52 * the strategy was already active.
54 activate: function() {
55 if(OpenLayers.Strategy.prototype.activate.apply(this, arguments)) {
56 this.layer.events.on({
60 if(this.layer.visibility == true || this.preload) {
63 this.layer.events.on({
64 "visibilitychanged": this.load,
75 * Deactivate the strategy. Undo what is done in <activate>.
78 * {Boolean} The strategy was successfully deactivated.
80 deactivate: function() {
81 var deactivated = OpenLayers.Strategy.prototype.deactivate.call(this);
83 this.layer.events.un({
85 "visibilitychanged": this.load,
94 * Tells protocol to load data and unhooks the visibilitychanged event
97 * options - {Object} options to pass to protocol read.
99 load: function(options) {
100 this.layer.events.triggerEvent("loadstart");
101 this.layer.protocol.read(OpenLayers.Util.applyDefaults({
102 callback: this.merge,
105 this.layer.events.un({
106 "visibilitychanged": this.load,
113 * Add all features to the layer.
115 merge: function(resp) {
116 this.layer.destroyFeatures();
117 var features = resp.features;
118 if (features && features.length > 0) {
119 var remote = this.layer.projection;
120 var local = this.layer.map.getProjectionObject();
121 if(!local.equals(remote)) {
123 for(var i=0, len=features.length; i<len; ++i) {
124 geom = features[i].geometry;
126 geom.transform(remote, local);
130 this.layer.addFeatures(features);
132 this.layer.events.triggerEvent("loadend");
135 CLASS_NAME: "OpenLayers.Strategy.Fixed"