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 false.
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,
103
filter: this.layer.filter,
106
this.layer.events.un({
107
"visibilitychanged": this.load,
114
* Add all features to the layer.
116
merge: function(resp) {
117
this.layer.destroyFeatures();
118
var features = resp.features;
119
if (features && features.length > 0) {
120
var remote = this.layer.projection;
121
var local = this.layer.map.getProjectionObject();
122
if(!local.equals(remote)) {
124
for(var i=0, len=features.length; i<len; ++i) {
125
geom = features[i].geometry;
127
geom.transform(remote, local);
131
this.layer.addFeatures(features);
133
this.layer.events.triggerEvent("loadend");
136
CLASS_NAME: "OpenLayers.Strategy.Fixed"