diff --git a/lib/OpenLayers.js b/lib/OpenLayers.js index b0ad334e22..21864c7148 100644 --- a/lib/OpenLayers.js +++ b/lib/OpenLayers.js @@ -180,6 +180,8 @@ "OpenLayers/Renderer/SVG.js", "OpenLayers/Renderer/VML.js", "OpenLayers/Layer/Vector.js", + "OpenLayers/Strategy.js", + "OpenLayers/Protocol.js", "OpenLayers/Layer/PointTrack.js", "OpenLayers/Layer/GML.js", "OpenLayers/Style.js", diff --git a/lib/OpenLayers/Layer/Vector.js b/lib/OpenLayers/Layer/Vector.js index be62a5576f..565568e53d 100644 --- a/lib/OpenLayers/Layer/Vector.js +++ b/lib/OpenLayers/Layer/Vector.js @@ -125,7 +125,19 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, { * {} */ styleMap: null, - + + /** + * Property: strategies + * {Array(})} Optional list of strategies for the layer. + */ + strategies: null, + + /** + * Property: 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} + */ + format: null, + + /** + * Property: options + * Any options sent to the constructor. + */ + options: null, + + /** + * Constructor: OpenLayers.Protocol + * Abstract class for vector protocols. Create instances of a subclass. + * + * Parameters: + * options - {Object} Optional object whose properties will be set on the + * instance. + */ + initialize: function(options) { + OpenLayers.Util.extend(this, options); + this.options = options; + }, + + /** + * APIMethod: destroy + * Clean up the protocol. + */ + destroy: function() { + this.options = null; + this.format = null; + }, + + /** + * Method: read + * Construct a request for reading new features. + * + * Parameters: + * options - {Object} Optional object for configuring the request. + */ + read: function() { + }, + + + /** + * Method: create + * Construct a request for writing newly created features. + * + * Parameters: + * features - {Array({})} or + * {} + * options - {Object} Optional object for configuring the request. + */ + create: function() { + }, + + /** + * Method: update + * Construct a request updating modified features. + * + * Parameters: + * features - {Array({})} or + * {} + * options - {Object} Optional object for configuring the request. + */ + update: function() { + }, + + /** + * Method: delete + * Construct a request deleting a removed feature. + * + * Parameters: + * feature - {} + * options - {Object} Optional object for configuring the request. + */ + "delete": function() { + }, + + /** + * Method: commit + * Go over the features and for each take action + * based on the feature state. Possible actions are create, + * update and delete. + * + * Parameters: + * features - {Array({})} + * options - {Object} Map of options, the keys of the map are + * 'create', 'update', and 'delete' + */ + commit: function() { + }, + + CLASS_NAME: "OpenLayers.Protocol" +}); + +/** + * Class: OpenLayers.Protocol.Response + * Protocols return Response objects to their users. + */ +OpenLayers.Protocol.Response = new OpenLayers.Class({ + /** + * Property: code + * {Integer} - OpenLayers.Protocol.Response.SUCCESS or + * OpenLayers.Protocol.Response.FAILURE + */ + code: null, + + /** + * Property: features + * {Array({})} or {} + * The features returned in the response by the server. + */ + features: null, + + /** + * Property: reqFeatures + * {Array({})} or {} + * The features provided by the user and placed in the request by the + * protocol. + */ + reqFeatures: null, + + /** + * Property: priv + */ + priv: null, + + /** + * Constructor: OpenLayers.Protocol.Response + * + * Parameters: + * options - {Object} Optional object whose properties will be set on the + * instance. + */ + initialize: function(options) { + OpenLayers.Util.extend(this, options); + }, + + /** + * Method: success + * + * Returns: + * {Boolean} - true on success, false otherwise + */ + success: function() { + return !!(this.code & OpenLayers.Protocol.Response.SUCCESS_MASK); + }, + + CLASS_NAME: "OpenLayers.Protocol.Response" +}); + +OpenLayers.Protocol.Response.SUCCESS_MASK = 0x000000ff; +OpenLayers.Protocol.Response.SUCCESS = 0x00000001; + +OpenLayers.Protocol.Response.FAILURE_MASK = 0x0000ff00; +OpenLayers.Protocol.Response.FAILURE = 0x00000100; diff --git a/lib/OpenLayers/Strategy.js b/lib/OpenLayers/Strategy.js new file mode 100755 index 0000000000..f0e1afb691 --- /dev/null +++ b/lib/OpenLayers/Strategy.js @@ -0,0 +1,72 @@ +/* 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. */ + +/** + * Class: OpenLayers.Strategy + * Abstract vector layer strategy class. Not to be instantiated directly. Use + * one of the strategy subclasses instead. + */ +OpenLayers.Strategy = OpenLayers.Class({ + + /** + * Property: layer + * {} + */ + layer: null, + + /** + * Property: options + * {Object} Any options sent to the constructor. + */ + options: null, + + /** + * Constructor: OpenLayers.Strategy + * Abstract class for vector strategies. Create instances of a subclass. + * + * Parameters: + * options - {Object} Optional object whose properties will be set on the + * instance. + */ + initialize: function(options) { + OpenLayers.Util.extend(this, options); + this.options = options; + }, + + /** + * APIMethod: destroy + * Clean up the strategy. + */ + destroy: function() { + this.deactivate(); + this.layer = null; + }, + + /** + * Method: setLayer. + * + * Parameters: + * {} + */ + setLayer: function(layer) { + this.layer = layer; + }, + + /** + * Method: activate + * Activate the strategy. Register any listeners, do appropriate setup. + */ + activate: function() { + }, + + /** + * Method: deactivate + * Deactivate the strategy. Unregister any listeners, do appropriate + * tear-down. + */ + deactivate: function() { + }, + + CLASS_NAME: "OpenLayers.Strategy" +}); diff --git a/tests/Protocol.html b/tests/Protocol.html new file mode 100644 index 0000000000..3ff909497f --- /dev/null +++ b/tests/Protocol.html @@ -0,0 +1,30 @@ + + + + + + + + diff --git a/tests/Strategy.html b/tests/Strategy.html new file mode 100644 index 0000000000..ff59028c3c --- /dev/null +++ b/tests/Strategy.html @@ -0,0 +1,30 @@ + + + + + + + + diff --git a/tests/list-tests.html b/tests/list-tests.html index ddeeaed9e7..5e5c5cbbac 100644 --- a/tests/list-tests.html +++ b/tests/list-tests.html @@ -110,6 +110,7 @@
  • Popup/AnchoredBubble.html
  • Popup/FramedCloud.html
  • Projection.html
  • +
  • Protocol.html
  • Renderer.html
  • Renderer/Elements.html
  • Renderer/SVG.html
  • @@ -117,6 +118,7 @@
  • Request.html
  • Request/XMLHttpRequest.html
  • Rule.html
  • +
  • Strategy.html
  • Style.html
  • StyleMap.html
  • Tile.html