Adding strategy and protocol base classes for better vector behavior. This just sets the common API for strategy and protocol. In general, a vector layer can have many strategies. A setLayer method gets called on each of these layers. When a layer is added to a map, any strategies on that layer get activated. When the layer is destroyed, any strategies get destroyed (this could be changed to deactivate for symmetry). A vector layer may also have a protocol. A protocol is typically constructed with a format. The layer doesn't need to know about the format. The protocol doesn't need to know about the layer. Strategies coordinate feature management for a layer. Specific strategies and protocols to follow. r=crschmidt (closes #1646)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@7650 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2008-07-31 21:27:35 +00:00
parent 5191dac459
commit 360d7412f0
7 changed files with 341 additions and 1 deletions

View File

@@ -125,7 +125,19 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
* {<OpenLayers.StyleMap>}
*/
styleMap: null,
/**
* Property: strategies
* {Array(<OpenLayers.Strategy>})} Optional list of strategies for the layer.
*/
strategies: null,
/**
* Property: protocol
* {<OpenLayers.Protocol>} Optional protocol for the layer.
*/
protocol: null,
/**
* Property: renderers
* {Array(String)} List of supported Renderer classes. Add to this list to
@@ -194,6 +206,14 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
this.features = [];
this.selectedFeatures = [];
// Allow for custom layer behavior
if(this.strategies){
for(var i=0, len=this.strategies.length; i<len; i++) {
this.strategies[i].setLayer(this);
}
}
},
/**
@@ -201,6 +221,16 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
* Destroy this layer
*/
destroy: function() {
if (this.stategies) {
for(var i=0, len=this.strategies.length; i<len; i++) {
this.strategies[i].destroy();
}
this.strategies = null;
}
if (this.protocol) {
this.protocol.destroy();
this.protocol = null;
}
this.destroyFeatures();
this.features = null;
this.selectedFeatures = null;
@@ -258,6 +288,11 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
this.renderer.map = this.map;
this.renderer.setSize(this.map.getSize());
}
if(this.strategies) {
for(var i=0, len=this.strategies.length; i<len; i++) {
this.strategies[i].activate();
}
}
},
/**