OpenLayers OpenLayers

Ticket #110: animatedPanning.patch

File animatedPanning.patch, 4.7 kB (added by euzuro, 2 years ago)

patchification of code from portugal.. thanks duarte for the leads!

  • lib/OpenLayers/Map.js

    old new  
    126126 
    127127    /** @type string */ 
    128128    theme: null, 
     129     
     130    //ANIMATION 
     131     
     132    /** @type Boolean */ 
     133    animated: true, 
    129134 
     135    /** steps in the slide 
     136     *  
     137     * @type int */ 
     138    slideSteps: 20,  
     139     
     140    /** millisecondss between each step 
     141     *  
     142     * @type int */ 
     143    slideWait: 20, 
     144 
     145    /** power used to calculate width of slide steps 
     146     *  
     147     * @type float*/ 
     148    slidePower: 0.7, 
     149 
     150    /** @type int */ 
     151    animatedPanningIntervalID: null, 
     152 
     153 
     154 
    130155    /** 
    131156     * @constructor 
    132157     *  
     
    703728     *  
    704729     * @param {int} dx 
    705730     * @param {int} dy 
     731     * @param {Boolean} animated 
    706732     */ 
    707     pan: function(dx, dy) { 
     733    pan: function(dx, dy, animated) { 
    708734 
    709         // getCenter 
    710         var centerPx = this.getViewPortPxFromLonLat(this.getCenter()); 
     735        if (animated == null) { 
     736            animated = this.animated; 
     737        } 
    711738 
    712         // adjust 
    713         var newCenterPx = centerPx.add(dx, dy); 
    714          
    715         // only call setCenter if there has been a change 
    716         if (!newCenterPx.equals(centerPx)) { 
    717             var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx); 
    718             this.setCenter(newCenterLonLat); 
     739        if (animated) { 
     740            this.panSlide(dx, dy,  
     741                          this.slideSteps,  
     742                          this.slideWait,  
     743                          this.slidePower); 
     744        } else { 
     745 
     746            // getCenter 
     747            var centerPx = this.getViewPortPxFromLonLat(this.getCenter()); 
     748     
     749            // adjust 
     750            var newCenterPx = centerPx.add(dx, dy); 
     751     
     752            // only call setCenter if there has been a change 
     753            if (!newCenterPx.equals(centerPx)) { 
     754                var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx); 
     755                this.setCenter(newCenterLonLat, null, null, this.animated); 
     756            } 
    719757        } 
    720  
    721758   }, 
    722759 
    723760    /** 
     
    827864        } 
    828865    }, 
    829866 
     867    /** Position changer with Memory by www.hesido.com 
     868     *  modified by dncpax for OpenLayers 
     869     *  
     870     * @param {int} slideX 
     871     * @param {int} slideY 
     872     * @param {int} totalSteps 
     873     * @param {int} intervals 
     874     * @param {float} power  
     875     */ 
     876    panSlide: function( slideX, slideY, totalSteps, interval, power) { 
     877        if (this.animatedPanningIntervalID) { 
     878            window.clearInterval(this.animatedPanningIntervalID); 
     879            this.animatedPanningIntervalID = null; 
     880        } 
     881        var context = { 
     882            'map': this, 
     883            'slideX': slideX, 
     884            'slideY': slideY, 
     885            'totalSteps': totalSteps, 
     886            'step': 0, 
     887            'power': power 
     888        }; 
     889        var move = function() { 
     890            var dx = OpenLayers.Util.easeInOut(this.slideX,  
     891                                                this.totalSteps,  
     892                                                this.step,  
     893                                                this.power); 
     894            var dy = OpenLayers.Util.easeInOut(this.slideY, 
     895                                                this.totalSteps,  
     896                                                this.step,  
     897                                                this.power); 
     898            this.map.pan(dx, dy, false); 
     899            this.step++; 
     900            if (this.step > this.totalSteps) { 
     901                window.clearInterval(this.map.animatedPanningIntervalID); 
     902                this.map.animatedPanningIntervalID = null; 
     903            } 
     904        }; 
     905 
     906        this.animatedPanningIntervalID =  
     907            window.setInterval(move.bindAsEventListener(context),  
     908                               interval); 
     909}, 
     910 
     911 
    830912    /** 
    831913     * @private  
    832914     *  
  • lib/OpenLayers/Util.js

    old new  
    954954                                  : url.substr(0, qMark); 
    955955    } 
    956956    return head; 
     957}; 
     958 
     959 
     960 
     961/** Generic Animation Step Value Generator By www.hesido.com, slightly modified 
     962 *  
     963 *  
     964 * @param {int} delta 
     965 * @param {int} totalSteps 
     966 * @param {int} step 
     967 * @param {float} power 
     968 *  
     969 * @returns The delta to the next position in the animation movement 
     970 * @type int 
     971 */ 
     972OpenLayers.Util.easeInOut = function(delta, totalSteps, step, power) { 
     973    var prevStepVal = Math.pow(((1/totalSteps)*(step-1)),power) * delta; 
     974    var stepVal = Math.pow(((1/totalSteps)*step),power) * delta; 
     975    return Math.ceil(stepVal) - Math.ceil(prevStepVal); 
    957976};