From 39201a042757bb4b23fd68b2334770d3855d85e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Junod?= Date: Tue, 5 Aug 2008 11:55:24 +0000 Subject: [PATCH] Adding OpenLayers.Strategy.Fixed: A simple strategy that requests features once and never requests new data. r=elemoine, (Closes #1664) git-svn-id: http://svn.openlayers.org/trunk/openlayers@7707 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers.js | 1 + lib/OpenLayers/Strategy/Fixed.js | 63 ++++++++++++++++++++++++++++++++ tests/Strategy/Fixed.html | 34 +++++++++++++++++ tests/list-tests.html | 1 + 4 files changed, 99 insertions(+) create mode 100644 lib/OpenLayers/Strategy/Fixed.js create mode 100644 tests/Strategy/Fixed.html diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index fa7a798a5b..6057ce6d54 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -181,6 +181,7 @@ "OpenLayers/Renderer/VML.js", "OpenLayers/Layer/Vector.js", "OpenLayers/Strategy.js", + "OpenLayers/Strategy/Fixed.js", "OpenLayers/Protocol.js", "OpenLayers/Layer/PointTrack.js", "OpenLayers/Layer/GML.js", diff --git a/lib/OpenLayers/Strategy/Fixed.js b/lib/OpenLayers/Strategy/Fixed.js new file mode 100644 index 0000000000..551d834691 --- /dev/null +++ b/lib/OpenLayers/Strategy/Fixed.js @@ -0,0 +1,63 @@ +/* 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.Fixed = OpenLayers.Class(OpenLayers.Strategy, { + + /** + * 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: reads all features from the protocol and add them + * to the layer. + */ + activate: function() { + OpenLayers.Strategy.prototype.activate.apply(this, arguments); + this.layer.protocol.read({ + callback: this.merge, + 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" +}); diff --git a/tests/Strategy/Fixed.html b/tests/Strategy/Fixed.html new file mode 100644 index 0000000000..953fe717c6 --- /dev/null +++ b/tests/Strategy/Fixed.html @@ -0,0 +1,34 @@ + + + + + + +
+ + diff --git a/tests/list-tests.html b/tests/list-tests.html index 185a32aaca..3617f2536a 100644 --- a/tests/list-tests.html +++ b/tests/list-tests.html @@ -121,6 +121,7 @@
  • Request/XMLHttpRequest.html
  • Rule.html
  • Strategy.html
  • +
  • Strategy/Fixed.html
  • Style.html
  • StyleMap.html
  • Tile.html