OpenLayers OpenLayers

Changeset 1702

Show
Ignore:
Timestamp:
10/17/06 18:23:19 (2 years ago)
Author:
crschmidt
Message:

Use calculateBounds function from patch on #228. This is a refactoring of the
code that Tim Schaub contributed on that patch. Thanks Tim!

Files:

Legend:

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

    r1695 r1702  
    446446    }, 
    447447 
    448     /** Calculates based on resolution, center, and mapsize 
    449      *  
    450      * @param {float} resolution Specific resolution to get an extent for. 
    451      *                           If null, this.getResolution() is called 
     448    /**  
    452449     * @returns A Bounds object which represents the lon/lat bounds of the  
    453450     *          current viewPort. 
    454451     * @type OpenLayers.Bounds 
    455452     */ 
    456     getExtent: function(resolution) { 
    457         var extent = null; 
    458  
    459         var center = this.map.getCenter(); 
    460         if (center != null) { 
    461  
    462             if (resolution == null) { 
    463                 resolution = this.getResolution(); 
    464             } 
    465             var size = this.map.getSize(); 
    466             var w_deg = size.w * resolution; 
    467             var h_deg = size.h * resolution; 
    468  
    469             extent = new OpenLayers.Bounds(center.lon - w_deg / 2, 
    470                                            center.lat - h_deg / 2, 
    471                                            center.lon + w_deg / 2, 
    472                                            center.lat + h_deg / 2); 
    473  
    474         } 
    475  
    476         return extent; 
     453    getExtent: function() { 
     454        // just use stock map calculateBounds function -- passing no arguments 
     455        //  means it will user map's current center & resolution 
     456        // 
     457        return this.map.calculateBounds(); 
    477458    }, 
    478459 
  • trunk/openlayers/lib/OpenLayers/Map.js

    r1695 r1702  
    607607        return size; 
    608608    }, 
     609 
     610    /**  
     611     * @param {OpenLayers.LonLat} center Default is this.getCenter() 
     612     * @param {float} resolution Default is this.getResolution()  
     613     *  
     614     * @returns A Bounds based on resolution, center, and current mapsize. 
     615     * @type OpenLayers.Bounds 
     616     */ 
     617    calculateBounds: function(center, resolution) { 
     618 
     619        var extent = null; 
     620         
     621        if (center == null) { 
     622            center = this.getCenter(); 
     623        }                 
     624        if (resolution == null) { 
     625            resolution = this.getResolution(); 
     626        } 
     627     
     628        if ((center != null) && (resolution != null)) { 
     629 
     630            var size = this.getSize(); 
     631            var w_deg = size.w * resolution; 
     632            var h_deg = size.h * resolution; 
     633         
     634            extent = new OpenLayers.Bounds(center.lon - w_deg / 2, 
     635                                           center.lat - h_deg / 2, 
     636                                           center.lon + w_deg / 2, 
     637                                           center.lat + h_deg / 2); 
     638         
     639        } 
     640 
     641        return extent; 
     642    }, 
     643 
    609644 
    610645  /********************************************************/