OpenLayers OpenLayers

Changeset 5672

Show
Ignore:
Timestamp:
01/07/08 13:57:38 (1 year ago)
Author:
tschaub
Message:

giving navigation history control onPreviousChange and onNextChange methods and an example to demonstrate their use

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/tschaub/history/examples/navigation-history.html

    r5671 r5672  
    3030                    type: OpenLayers.Control.BUTTON, 
    3131                    trigger: function() {nav.previous();}, 
    32                     active: true 
    3332                }); 
     33                nav.onPreviousChange = function(state, length) { 
     34                    if(state) { 
     35                        prev.activate(); 
     36                        document.getElementById("previous").disabled = false; 
     37                    } else { 
     38                        prev.deactivate(); 
     39                        document.getElementById("previous").disabled = true; 
     40                    } 
     41                    OpenLayers.Console.log( 
     42                        length + " items remaining in previous history" 
     43                    ); 
     44                }                         
    3445                map.addControl(prev); 
    3546                 
    3647                next = new OpenLayers.Control({ 
    3748                    type: OpenLayers.Control.BUTTON, 
    38                     trigger: function() {nav.next();}, 
    39                     active: true 
     49                    trigger: function() {nav.next();} 
    4050                }); 
     51                nav.onNextChange = function(state, length) { 
     52                    if(state) { 
     53                        next.activate(); 
     54                        document.getElementById("next").disabled = false; 
     55                    } else { 
     56                        next.deactivate(); 
     57                        document.getElementById("next").disabled = true; 
     58                    } 
     59                    OpenLayers.Console.log( 
     60                        length + " items remaining in next history" 
     61                    ); 
     62                } 
    4163                map.addControl(next); 
    4264 
     
    5577 
    5678        <div id="map"></div> 
    57         zoom to <button onclick="prev.trigger();">previous</button> 
    58         <button onclick="next.trigger();">next</button><br /> 
     79        zoom to <button onclick="prev.trigger();" id="previous" disabled="disabled">previous</button> 
     80        <button onclick="next.trigger();" id="next" disabled="disabled">next</button><br /> 
    5981 
    6082        <div id="docs"></div> 
  • sandbox/tschaub/history/lib/OpenLayers/Control/NavigationHistory.js

    r5671 r5672  
    112112        this.clear(); 
    113113    }, 
     114     
     115    /** 
     116     * APIMethod: onPreviousChange 
     117     * Called when the previous history stack changes.  This function will 
     118     *     be called with two arguments, the state ({Object}) that will be 
     119     *     restored if previous is called and the number ({Integer}) of items 
     120     *     remaining in the previous history. 
     121     */ 
     122    onPreviousChange: function(state, length) {}, 
     123     
     124    /** 
     125     * APIMethod: onNextChange 
     126     * Called when the next history stack changes.  This function will 
     127     *     be called with two arguments, the state ({Object}) that will be 
     128     *     restored if next is called and the number ({Integer}) of items 
     129     *     remaining in the next history. 
     130     */ 
     131    onNextChange: function(state, length) {}, 
    114132     
    115133    /** 
     
    174192            this.restore(state); 
    175193            this.restoring = false; 
     194            this.onNextChange(this.nextStack[0], this.nextStack.length); 
     195            this.onPreviousChange( 
     196                this.previousStack[1], this.previousStack.length - 1 
     197            ); 
    176198        } else { 
    177199            this.previousStack.unshift(current); 
     
    197219            this.restore(state); 
    198220            this.restoring = false; 
     221            this.onNextChange(this.nextStack[0], this.nextStack.length); 
     222            this.onPreviousChange( 
     223                this.previousStack[1], this.previousStack.length - 1 
     224            ); 
    199225        } 
    200226        return state; 
     
    233259                    var state = this.on[type].apply(this, arguments); 
    234260                    this.previousStack.unshift(state); 
     261                    if(this.previousStack.length > 1) { 
     262                        this.onPreviousChange( 
     263                            this.previousStack[1], this.previousStack.length - 1 
     264                        ); 
     265                    } 
    235266                    if(this.previousStack.length > (this.limit + 1)) { 
    236267                        this.previousStack.pop(); 
     
    238269                    if(this.nextStack.length > 0) { 
    239270                        this.nextStack = []; 
     271                        this.onNextChange(null, 0); 
    240272                    } 
    241273                }