Changeset 1229

Show
Ignore:
Timestamp:
10/17/08 15:27:17 (3 months ago)
Author:
dcorpataux
Message:

Protocol Listener? strategy, see #264

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/Strategy.js

    r1223 r1229  
    2424/** 
    2525 * Namespace: mapfish.Protocol 
    26  * Contains mapfish strategies. 
     26 * Contains MapFish Strategies. 
    2727 */ 
    2828 
  • sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/core/Strategy/ProtocolListener.js

    r1223 r1229  
    2525/** 
    2626 * 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. 
    3234 * 
    3335 * Example usage: 
    3436 * (start code) 
    35  * 
    3637 * var layer = new OpenLayers.Layer.Vector( 
    3738 *     "some layer name", { 
    3839 *         protocol: new mapfish.Protocol.TriggerEventDecorator(someProtocol), 
    39  *         strategies: [new mapfish.Strategy.ProtocolListener()] 
     40 *         strategies: [new mapfish.Strategy.ProtocolListener({append: true})] 
    4041 *     } 
    4142 * ); 
    42  * 
    4343 * (end) 
    4444 * 
     
    5151     * APIProperty: append 
    5252     * {Boolean} If false, existing layer features are destroyed 
    53      *     before adding newly read features. 
     53     *     before adding newly read features. Defaults to false. 
    5454     */ 
    5555    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, 
    5663 
    5764    /** 
     
    6976    /** 
    7077     * 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. 
    7281     * 
    7382     * Returns: 
     
    8594        if (activated) { 
    8695            this.layer.protocol.events.on({ 
    87                 'crudfinished': this.onCrudfinished, 
    88                 'clear': this.onClear, 
     96                "crudfinished": this.onCrudfinished, 
     97                "clear": this.onClear, 
    8998                scope: this 
    9099            }); 
     
    95104    /** 
    96105     * Method: deactivate 
    97      * Tear down strategy with regard to drawing layer feature on protocol read actions
     106     * Tear down strategy
    98107     * 
    99108     * Returns: 
     
    104113        if (deactivated) { 
    105114            this.layer.protocol.events.un({ 
    106                 'crudfinished': this.onCrudfinished, 
    107                 'clear': this.onClear, 
     115                "crudfinished": this.onCrudfinished, 
     116                "clear": this.onClear, 
    108117                scope: this 
    109118            }); 
     
    120129     */ 
    121130    onCrudfinished: function(response) { 
    122         if (response.requestType == 'read') { 
     131        if (response.requestType == "read") { 
    123132            this.addFeatures(response.features) 
    124133        } 
     
    138147        if (features && features.length > 0) { 
    139148            this.layer.addFeatures(features); 
     149            if (this.recenter) { 
     150                this.layer.map.zoomToExtent(this.layer.getDataExtent()) 
     151            } 
    140152        } 
    141153    }, 
     
    145157     * Callback function called on protocol clear event. 
    146158     */ 
    147     onClear: function(response) { 
     159    onClear: function() { 
    148160        this.layer.destroyFeatures() 
    149161    },