Changeset 1229
- Timestamp:
- 10/17/08 15:27:17 (3 months ago)
- Files:
-
- sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/Strategy.js (modified) (1 diff)
- sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/Strategy/ProtocolListener.js (modified) (9 diffs)
- sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/tests/core/Strategy/test_ProtocolListener.html (added)
- sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/tests/core/Strategy/test_Search.html (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/Strategy.js
r1223 r1229 24 24 /** 25 25 * Namespace: mapfish.Protocol 26 * Contains mapfish strategies.26 * Contains MapFish Strategies. 27 27 */ 28 28 sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/Strategy/ProtocolListener.js
r1223 r1229 25 25 /** 26 26 * Class: mapfish.Strategy.ProtocolListener 27 * A strategy that draws vector features when the protocol reads 28 * feature data. This strategy is to be used with a layer whose 29 * protocol is a TriggerEventDecorator. 30 * This strategy binds itself to the TriggerEventDecorator 31 * "crudfinished" and "clear" events 27 * A strategy that listens to "crudfinished" and "clear" events triggered 28 * by a <mapfish.Protocol.TriggerEventDecorator> protocol, upon receiving 29 * a "crudfinished" event and if the request is of type "read", the 30 * strategy adds the received features to the layer, upon receiving a 31 * "clear" event, the strategy destroys the features in the layer. A 32 * <mapfish.Protocol.TriggerEventDecorator> protocol must be 33 * configured in the layer for this strategy to work as expected. 32 34 * 33 35 * Example usage: 34 36 * (start code) 35 *36 37 * var layer = new OpenLayers.Layer.Vector( 37 38 * "some layer name", { 38 39 * protocol: new mapfish.Protocol.TriggerEventDecorator(someProtocol), 39 * strategies: [new mapfish.Strategy.ProtocolListener( )]40 * strategies: [new mapfish.Strategy.ProtocolListener({append: true})] 40 41 * } 41 42 * ); 42 *43 43 * (end) 44 44 * … … 51 51 * APIProperty: append 52 52 * {Boolean} If false, existing layer features are destroyed 53 * before adding newly read features. 53 * before adding newly read features. Defaults to false. 54 54 */ 55 55 append: false, 56 57 /** 58 * APIProperty: recenter 59 * {Boolean} If true, map is recentered to features extent. 60 * Defaults to false. 61 */ 62 recenter: false, 56 63 57 64 /** … … 69 76 /** 70 77 * Method: activate 71 * Set up strategy with regard to drawing layer feature on protocol read actions. 78 * Set up strategy with regard to adding features to the layer when 79 * receiving crudfinished events and destroying the layer features 80 * when receiving clear events. 72 81 * 73 82 * Returns: … … 85 94 if (activated) { 86 95 this.layer.protocol.events.on({ 87 'crudfinished': this.onCrudfinished,88 'clear': this.onClear,96 "crudfinished": this.onCrudfinished, 97 "clear": this.onClear, 89 98 scope: this 90 99 }); … … 95 104 /** 96 105 * Method: deactivate 97 * Tear down strategy with regard to drawing layer feature on protocol read actions.106 * Tear down strategy. 98 107 * 99 108 * Returns: … … 104 113 if (deactivated) { 105 114 this.layer.protocol.events.un({ 106 'crudfinished': this.onCrudfinished,107 'clear': this.onClear,115 "crudfinished": this.onCrudfinished, 116 "clear": this.onClear, 108 117 scope: this 109 118 }); … … 120 129 */ 121 130 onCrudfinished: function(response) { 122 if (response.requestType == 'read') {131 if (response.requestType == "read") { 123 132 this.addFeatures(response.features) 124 133 } … … 138 147 if (features && features.length > 0) { 139 148 this.layer.addFeatures(features); 149 if (this.recenter) { 150 this.layer.map.zoomToExtent(this.layer.getDataExtent()) 151 } 140 152 } 141 153 }, … … 145 157 * Callback function called on protocol clear event. 146 158 */ 147 onClear: function( response) {159 onClear: function() { 148 160 this.layer.destroyFeatures() 149 161 },