diff --git a/lib/OpenLayers/Layer/Image.js b/lib/OpenLayers/Layer/Image.js index ed12041510..659dc11619 100644 --- a/lib/OpenLayers/Layer/Image.js +++ b/lib/OpenLayers/Layer/Image.js @@ -1,6 +1,7 @@ /* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license. * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt * for the full text of the license. */ + /** * @fileoverview Image Layer * @author Tim Schaub @@ -15,9 +16,11 @@ OpenLayers.Layer.Image = OpenLayers.Class.create(); OpenLayers.Layer.Image.prototype = OpenLayers.Class.inherit(OpenLayers.Layer, { - /** @type String */ - name: null, - + /** By default, Layer.Image will be a baselayer + * + * @type Boolean */ + isBaseLayer: true, + /** @type String */ url: null, @@ -27,14 +30,10 @@ OpenLayers.Layer.Image.prototype = /** @type OpenLayers.Size */ size: null, - /** @type Object */ - options: null, - /** @type OpenLayers.Tile.Image */ tile: null, - /** - * The ratio of height/width represented by a single pixel in the graphic + /** The ratio of height/width represented by a single pixel in the graphic * * @type Float */ aspectRatio: null, @@ -52,14 +51,10 @@ OpenLayers.Layer.Image.prototype = this.url = url; this.extent = extent; this.size = size; - this.aspectRatio = (this.extent.getHeight() / this.size.h) / - (this.extent.getWidth() / this.size.w); OpenLayers.Layer.prototype.initialize.apply(this, [name, options]); - // unless explicitly set in options, the layer will be a base layer - if((options == null) || (options.isBaseLayer == null)) { - this.isBaseLayer = true; - } + this.aspectRatio = (this.extent.getHeight() / this.size.h) / + (this.extent.getWidth() / this.size.w); }, /** @@ -95,41 +90,19 @@ OpenLayers.Layer.Image.prototype = return obj; }, - /** - * This is a bad method to have here. It would be nicer to be able - * to ask Layer directly. - */ - shouldCalcResolutions: function() { - var props = new Array( - 'scales', 'resolutions', - 'maxScale', 'minScale', - 'maxResolution', 'minResolution', - 'minExtent', 'maxExtent', - 'numZoomLevels', 'maxZoomLevel' - ); - for(var i=0; i < props.length; i++) { - var property = props[i]; - if(this.options[property] != null) { - return false; - } - } - return true; - }, - - /** * @param {OpenLayers.Map} map */ setMap: function(map) { // If nothing to do with resolutions has been set, assume a single // resolution determined by extent/size - if(this.shouldCalcResolutions()) { - this.options.resolutions = [this.extent.getWidth() / this.size.w]; + if( this.options.maxResolution == null ) { + this.options.maxResolution = this.extent.getWidth() / this.size.w; } OpenLayers.Layer.prototype.setMap.apply(this, arguments); }, - /** When zooming or first rendering, create a new tile for the image. + /** Create the tile for the image or resize it for the new resolution * * @param {OpenLayers.Bounds} bounds * @param {Boolean} zoomChanged @@ -142,15 +115,6 @@ OpenLayers.Layer.Image.prototype = if(zoomChanged || firstRendering) { - //clear out the old tile - if(this.tile) { - this.tile.destroy(); - this.tile = null; - } - - //determine new tile bounds - var tileBounds = this.extent.clone(); - //determine new tile size var tileWidth = this.extent.getWidth() / this.map.getResolution(); var tileHeight = this.extent.getHeight() / @@ -158,11 +122,18 @@ OpenLayers.Layer.Image.prototype = var tileSize = new OpenLayers.Size(tileWidth, tileHeight); //determine new position (upper left corner of new bounds) - var ul = new OpenLayers.LonLat(tileBounds.left, tileBounds.top); - var pos = this.map.getLayerPxFromLonLat(ul); + var ul = new OpenLayers.LonLat(this.extent.left, this.extent.top); + var ulPx = this.map.getLayerPxFromLonLat(ul); - this.tile = new OpenLayers.Tile.Image(this, pos, tileBounds, - this.url, tileSize); + if(firstRendering) { + //create the new tile + this.tile = new OpenLayers.Tile.Image(this, ulPx, this.extent, + this.url, tileSize); + } else { + //just resize the tile and set it's new position + this.tile.size = tileSize.clone(); + this.tile.position = ulPx.clone(); + } this.tile.draw(); } }, @@ -172,10 +143,13 @@ OpenLayers.Layer.Image.prototype = */ setUrl: function(newUrl) { this.url = newUrl; - this.moveTo(); + this.draw(); }, - /** + /** The url we return is always the same (the image itself never changes) + * so we can ignore the bounds parameter (it will always be the same, + * anyways) + * * @param {OpenLayers.Bounds} bounds */ getURL: function(bounds) {