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
This commit is contained in:
@@ -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",
|
||||
|
||||
63
lib/OpenLayers/Strategy/Fixed.js
Normal file
63
lib/OpenLayers/Strategy/Fixed.js
Normal file
@@ -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>
|
||||
*/
|
||||
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"
|
||||
});
|
||||
34
tests/Strategy/Fixed.html
Normal file
34
tests/Strategy/Fixed.html
Normal file
@@ -0,0 +1,34 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_activate(t) {
|
||||
t.plan(1);
|
||||
var featureList = ['foo', 'bar'];
|
||||
|
||||
var layer = new OpenLayers.Layer.Vector("Vector Layer", {
|
||||
strategies: [new OpenLayers.Strategy.Fixed()],
|
||||
|
||||
// a fake protocol
|
||||
protocol: {
|
||||
read: function(options) {
|
||||
options.callback.call(options.scope, {features: featureList});
|
||||
}
|
||||
},
|
||||
|
||||
addFeatures: function(features) {
|
||||
t.eq(features, featureList, "Features added to the layer");
|
||||
}
|
||||
});
|
||||
|
||||
var map = new OpenLayers.Map('map');
|
||||
map.addLayer(layer);
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map"/>
|
||||
</body>
|
||||
</html>
|
||||
@@ -121,6 +121,7 @@
|
||||
<li>Request/XMLHttpRequest.html</li>
|
||||
<li>Rule.html</li>
|
||||
<li>Strategy.html</li>
|
||||
<li>Strategy/Fixed.html</li>
|
||||
<li>Style.html</li>
|
||||
<li>StyleMap.html</li>
|
||||
<li>Tile.html</li>
|
||||
|
||||
Reference in New Issue
Block a user