You can use below patch:<br><br>Index: lib/OpenLayers/Layer/Image.js<br>===================================================================<br>--- lib/OpenLayers/Layer/Image.js (revision 8489)<br>+++ lib/OpenLayers/Layer/Image.js (working copy)<br>
@@ -47,13 +47,6 @@<br> tile: null,<br> <br> /**<br>- * Property: aspectRatio<br>- * {Float} The ratio of height/width represented by a single pixel in the<br>- * graphic<br>- */<br>- aspectRatio: null,<br>
-<br>- /**<br> * Constructor: OpenLayers.Layer.Image<br> * Create a new image layer<br> *<br>@@ -69,9 +62,6 @@<br> this.extent = extent;<br> this.size = size;<br> OpenLayers.Layer.prototype.initialize.apply(this, [name, options]);<br>
-<br>- this.aspectRatio = (this.extent.getHeight() / this.size.h) /<br>- (this.extent.getWidth() / this.size.w);<br> }, <br> <br> /**<br>@@ -128,9 +118,9 @@<br> * image will be stretched in one dimension only.<br>
*/<br> if( this.options.maxResolution == null ) {<br>- this.options.maxResolution = this.aspectRatio *<br>- this.extent.getWidth() /<br>- this.size.w;<br>
+ var wRes = this.extent.getWidth() / this.size.w;<br>+ var hRes = this.extent.getHeight() / this.size.h;<br>+ this.options.maxResolution = Math.min(wRes, hRes);<br> }<br> OpenLayers.Layer.prototype.setMap.apply(this, arguments);<br>
},<br>@@ -155,8 +145,10 @@<br> this.setTileSize();<br> <br> //determine new position (upper left corner of new bounds)<br>- var ul = new OpenLayers.LonLat(this.extent.left, this.extent.top);<br>
- var ulPx = this.map.getLayerPxFromLonLat(ul);<br>+ var center = this.extent.getCenterLonLat();<br>+ var centerPx = this.map.getLayerPxFromLonLat(center);<br>+ var ulPx = new OpenLayers.Pixel(centerPx.x - (this.tileSize.w / 2),<br>
+ centerPx.y - (this.tileSize.h / 2));<br> <br> if(firstRendering) {<br> //create the new tile<br>@@ -175,10 +167,23 @@<br> * Set the tile size based on the map size.<br>
*/<br> setTileSize: function() {<br>- var tileWidth = this.extent.getWidth() / this.map.getResolution();<br>- var tileHeight = this.extent.getHeight() / this.map.getResolution();<br>- this.tileSize = new OpenLayers.Size(tileWidth, tileHeight);<br>
+ var w = this.extent.getWidth() / this.map.getResolution();<br>+ var h = this.extent.getHeight() / this.map.getResolution();<br>+ <br>+ this.tileSize = this.getLockedSize(w, h);<br> },<br>
+ <br>+ getLockedSize: function(w, h) {<br>+ var tileWidth = w;<br>+ var tileHeight = h;<br>+ if(this.size.h > this.size.w) {<br>+ tileHeight = Math.floor(this.size.h * (w / this.size.w));<br>
+ } else {<br>+ tileWidth = Math.floor(this.size.w * (h / this.size.h));<br>+ }<br>+ <br>+ return new OpenLayers.Size(tileWidth, tileHeight);<br>+ },<br> <br> /**<br> * APIMethod: setUrl<br>
<br>If this is the right way for the image layer, I will open a ticket for this patch.<br><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
Hi,<br>
<br>
I'm using OpenLayers to develop a viewing application for medical images. So far I'm just using static images, i.e. I'm using the Image layer, and I'm a bit puzzled as to the interdependence of bounds, extent, resolution and all this stuff. I simply want to fit an image which might be quite high-res into the viewport for a start and then let the users zoom in until the natural resolution of the image is reached. I played with all the parameters but to be honest I still haven't quite gotten the gist, so even after hours it seems as if I'm not a step further. A hint or short explanation as to how to approach this would be greatly appreciated!<br>
<br>
My code is something like this:<br>
var oMapWest = new OpenLayers.Map('viewportWest');<br>
var graphic = new OpenLayers.Layer.Image(<br>
'City Lights',<br>
'images/political_world_map.jpg', // which is 8000x4000pxs<br>
new OpenLayers.Bounds(-180, -90, 180, 90),<br>
new OpenLayers.Size(700, 350),<br>
{numZoomLevels:10}<br>
);<br>
oMapWest.addLayers([graphic]);<br>
oMapWest.zoomToMaxExtent();<br>
<br>
Thanks!<br>
<br>
Flo<br>
<br>
</blockquote></div><br><br clear="all"><br>-- <br>Li XinGang<br>EMail: <a href="mailto:slinavlee@gmail.com">slinavlee@gmail.com</a><br>Blog: <a href="http://avlee.cnblogs.com">avlee.cnblogs.com</a><br>Site: <a href="http://www.mapboost.org.cn">www.mapboost.org.cn</a><br>