OpenLayers OpenLayers

Changeset 7678

Show
Ignore:
Timestamp:
08/01/08 21:56:36 (4 months ago)
Author:
crschmidt
Message:

"panTo should use tween if new center is in the current bounds + a ratio".
Add a bounds.scale method (takes a ratio and an optional center) and
call it from the panTo to give a ratio we can pan inside of. Patch by
sbenthall, r=me,elemoine (Closes #1341)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/BaseTypes/Bounds.js

    r6833 r7678  
    218218        return new OpenLayers.LonLat( (this.left + this.right) / 2, 
    219219                                      (this.bottom + this.top) / 2); 
     220    }, 
     221 
     222    /** 
     223     * Method: scale 
     224     * Scales the bounds around a pixel or lonlat. Note that the new  
     225     *     bounds may return non-integer properties, even if a pixel 
     226     *     is passed.  
     227     *  
     228     * Parameters: 
     229     * ratio - {Float}  
     230     * origin - {<OpenLayers.Pixel> or <OpenLayers.LonLat>} 
     231     *          Default is center. 
     232     * 
     233     * Returns: 
     234     * {<OpenLayers.Bound>} A new bounds that is scaled by ratio 
     235     *                      from origin. 
     236     */ 
     237 
     238    scale: function(ratio, origin){ 
     239        if(origin == null){ 
     240            origin = this.getCenterLonLat(); 
     241        } 
     242 
     243        var bounds = []; 
     244         
     245        var origx,origy; 
     246 
     247        // get origin coordinates 
     248        if(origin.CLASS_NAME == "OpenLayers.LonLat"){ 
     249            origx = origin.lon; 
     250            origy = origin.lat; 
     251        } else { 
     252            origx = origin.x; 
     253            origy = origin.y; 
     254        } 
     255 
     256        var left = (this.left - origx) * ratio + origx; 
     257        var bottom = (this.bottom - origy) * ratio + origy; 
     258        var right = (this.right - origx) * ratio + origx; 
     259        var top = (this.top - origy) * ratio + origy; 
     260 
     261        return new OpenLayers.Bounds(left, bottom, right, top); 
    220262    }, 
    221263 
  • trunk/openlayers/lib/OpenLayers/Map.js

    r7627 r7678  
    198198 
    199199    /** 
     200     * Property: panRatio 
     201     * {Float} The ratio of the current extent within 
     202     *         which panning will tween. 
     203     */ 
     204    panRatio: 1.5,     
     205 
     206    /** 
    200207     * Property: viewRequestID 
    201208     * {String} Used to store a unique identifier that changes when the map  
     
    13691376     */ 
    13701377    panTo: function(lonlat) { 
    1371         if (this.panMethod && this.getExtent().containsLonLat(lonlat)) { 
     1378        if (this.panMethod && this.getExtent().scale(this.panRatio).containsLonLat(lonlat)) { 
    13721379            if (!this.panTween) { 
    13731380                this.panTween = new OpenLayers.Tween(this.panMethod); 
  • trunk/openlayers/tests/BaseTypes/Bounds.html

    r6724 r7678  
    558558    } 
    559559 
     560    function test_Bounds_scale(t) { 
     561        t.plan(3); 
     562 
     563        origBounds = new OpenLayers.Bounds(1,2,3,4); 
     564        bounds = origBounds.scale(2);   
     565        var b = new OpenLayers.Bounds(0,1,4,5); 
     566        t.ok(bounds.equals(b), "Bounds scale correctly with default origin at center") 
     567 
     568        var origin = new OpenLayers.Pixel(0,1); 
     569        bounds = origBounds.scale(2,origin); 
     570        b = new OpenLayers.Bounds(2,3,6,7); 
     571        t.ok(bounds.equals(b), "Bounds scale correctly with offset origin"); 
     572 
     573        origin = new OpenLayers.Pixel(5,1); 
     574        bounds = bounds.scale(2, origin); 
     575        b = new OpenLayers.Bounds(-1, 5, 7, 13); 
     576        t.ok(bounds.equals(b), "Bounds scale correctly with offset origin"); 
     577 
     578    } 
    560579 
    561580  </script>