OpenLayers OpenLayers

Changeset 1737

Show
Ignore:
Timestamp:
10/25/06 19:05:23 (2 years ago)
Author:
tschaub
Message:

Pull in euzuro's patch from #366 - changing how maxResolution is set and a number of other efficiency changes

Files:

Legend:

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

    r1721 r1737  
    22 * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt  
    33 * for the full text of the license. */ 
     4  
    45/** 
    56 * @fileoverview Image Layer 
     
    1617  OpenLayers.Class.inherit(OpenLayers.Layer, { 
    1718 
    18     /** @type String */ 
    19     name: null, 
    20  
     19    /** By default, Layer.Image will be a baselayer 
     20     *  
     21     * @type Boolean */ 
     22    isBaseLayer: true, 
     23     
    2124    /** @type String */ 
    2225    url: null, 
     
    2831    size: null, 
    2932 
    30     /** @type Object */ 
    31     options: null, 
    32  
    3333    /** @type OpenLayers.Tile.Image */ 
    3434    tile: null, 
    3535 
    36     /** 
    37      * The ratio of height/width represented by a single pixel in the graphic 
     36    /** The ratio of height/width represented by a single pixel in the graphic 
    3837     *  
    3938     * @type Float */ 
     
    5352        this.extent = extent; 
    5453        this.size = size; 
     54        OpenLayers.Layer.prototype.initialize.apply(this, [name, options]); 
     55 
    5556        this.aspectRatio = (this.extent.getHeight() / this.size.h) / 
    5657                           (this.extent.getWidth() / this.size.w); 
    57         OpenLayers.Layer.prototype.initialize.apply(this, [name, options]); 
    58  
    59         // unless explicitly set in options, the layer will be a base layer 
    60         if((options == null) || (options.isBaseLayer == null)) { 
    61             this.isBaseLayer = true; 
    62         } 
    6358    },     
    6459 
     
    9792     
    9893    /** 
    99      * This is a bad method to have here.  It would be nicer to be able 
    100      * to ask Layer directly. 
    101      */ 
    102     shouldCalcResolutions: function() { 
    103         var props = new Array( 
    104             'scales', 'resolutions', 
    105             'maxScale', 'minScale',  
    106             'maxResolution', 'minResolution',  
    107             'minExtent', 'maxExtent', 
    108             'numZoomLevels', 'maxZoomLevel' 
    109         ); 
    110         for(var i=0; i < props.length; i++) { 
    111             var property = props[i]; 
    112             if(this.options[property] != null) { 
    113                 return false; 
    114             } 
    115         } 
    116         return true; 
    117     }, 
    118          
    119      
    120     /** 
    12194     * @param {OpenLayers.Map} map 
    12295     */ 
     
    12497        // If nothing to do with resolutions has been set, assume a single 
    12598        //  resolution determined by extent/size 
    126         if(this.shouldCalcResolutions()) { 
    127             this.options.resolutions = [this.extent.getWidth() / this.size.w]
     99        if( this.options.maxResolution == null ) { 
     100           this.options.maxResolution = this.extent.getWidth() / this.size.w
    128101        } 
    129102        OpenLayers.Layer.prototype.setMap.apply(this, arguments); 
    130103    }, 
    131104 
    132     /** When zooming or first rendering, create a new tile for the image. 
     105    /** Create the tile for the image or resize it for the new resolution 
    133106     *  
    134107     * @param {OpenLayers.Bounds} bounds 
     
    143116        if(zoomChanged || firstRendering) { 
    144117 
    145             //clear out the old tile 
    146             if(this.tile) { 
    147                 this.tile.destroy(); 
    148                 this.tile = null; 
    149             } 
    150              
    151             //determine new tile bounds 
    152             var tileBounds = this.extent.clone(); 
    153  
    154118            //determine new tile size 
    155119            var tileWidth = this.extent.getWidth() / this.map.getResolution(); 
     
    159123             
    160124            //determine new position (upper left corner of new bounds) 
    161             var ul = new OpenLayers.LonLat(tileBounds.left, tileBounds.top); 
    162             var pos = this.map.getLayerPxFromLonLat(ul); 
     125            var ul = new OpenLayers.LonLat(this.extent.left, this.extent.top); 
     126            var ulPx = this.map.getLayerPxFromLonLat(ul); 
    163127 
    164             this.tile = new OpenLayers.Tile.Image(this, pos, tileBounds,  
    165                                                   this.url, tileSize); 
     128            if(firstRendering) { 
     129                //create the new tile 
     130                this.tile = new OpenLayers.Tile.Image(this, ulPx, this.extent,  
     131                                                      this.url, tileSize); 
     132            } else { 
     133                //just resize the tile and set it's new position 
     134                this.tile.size = tileSize.clone(); 
     135                this.tile.position = ulPx.clone(); 
     136            } 
    166137            this.tile.draw(); 
    167138        } 
     
    173144    setUrl: function(newUrl) { 
    174145        this.url = newUrl; 
    175         this.moveTo(); 
     146        this.draw(); 
    176147    }, 
    177148 
    178     /** 
     149    /** The url we return is always the same (the image itself never changes) 
     150     *   so we can ignore the bounds parameter (it will always be the same,  
     151     *   anyways)  
     152     *  
    179153     * @param {OpenLayers.Bounds} bounds 
    180154     */