fix for #785 - fix up gutter logic a little bit. on a path to getting all gutter info in one place

git-svn-id: http://svn.openlayers.org/trunk/openlayers@3555 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2007-07-02 22:51:50 +00:00
parent d2c2b011e7
commit bb6f69d83f
9 changed files with 37 additions and 37 deletions
+8 -5
View File
@@ -381,6 +381,14 @@ OpenLayers.Layer.prototype = {
this.setTileSize(); this.setTileSize();
} }
}, },
/**
* @returns The size that the image should be, taking into account gutters
* @tile OpenLayers.Size
*/
getImageSize: function() {
return (this.imageSize || this.tileSize);
},
/** /**
* APIMethod: setTileSize * APIMethod: setTileSize
@@ -405,11 +413,6 @@ OpenLayers.Layer.prototype = {
this.imageOffset = new OpenLayers.Pixel(-this.gutter, -this.gutter); this.imageOffset = new OpenLayers.Pixel(-this.gutter, -this.gutter);
this.imageSize = new OpenLayers.Size(tileSize.w + (2 * this.gutter), this.imageSize = new OpenLayers.Size(tileSize.w + (2 * this.gutter),
tileSize.h + (2 * this.gutter)); tileSize.h + (2 * this.gutter));
} else {
// layers without gutters may have null tile size - as long
// as they don't rely on Tile.Image
this.imageSize = tileSize;
this.imageOffset = new OpenLayers.Pixel(0, 0);
} }
}, },
+1 -4
View File
@@ -172,15 +172,12 @@ OpenLayers.Layer.Image.prototype =
}, },
/** /**
* Set the tile size based on the map size. This also sets layer.imageSize * Set the tile size based on the map size.
* and layer.imageOffset for use by Tile.Image.
*/ */
setTileSize: function() { setTileSize: function() {
var tileWidth = this.extent.getWidth() / this.map.getResolution(); var tileWidth = this.extent.getWidth() / this.map.getResolution();
var tileHeight = this.extent.getHeight() / this.map.getResolution(); var tileHeight = this.extent.getHeight() / this.map.getResolution();
this.tileSize = new OpenLayers.Size(tileWidth, tileHeight); this.tileSize = new OpenLayers.Size(tileWidth, tileHeight);
this.imageSize = this.tileSize;
this.imageOffset = new OpenLayers.Pixel(0, 0);
}, },
/** /**
+6 -4
View File
@@ -119,15 +119,17 @@ OpenLayers.Layer.MapServer.prototype =
bounds = this.adjustBounds(bounds); bounds = this.adjustBounds(bounds);
// Make a list, so that getFullRequestString uses literal "," // Make a list, so that getFullRequestString uses literal ","
var extent = [bounds.left, bounds. bottom, bounds.right, bounds.top]; var extent = [bounds.left, bounds. bottom, bounds.right, bounds.top];
var imageSize = this.getImageSize();
// make lists, so that literal ','s are used // make lists, so that literal ','s are used
var url = this.getFullRequestString( var url = this.getFullRequestString(
{mapext: extent, {mapext: extent,
imgext: extent, imgext: extent,
map_size: [this.imageSize.w, this.imageSize.h], map_size: [imageSize.w, imageSize.h],
imgx: this.imageSize.w / 2, imgx: imageSize.w / 2,
imgy: this.imageSize.h / 2, imgy: imageSize.h / 2,
imgxy: [this.imageSize.w, this.imageSize.h] imgxy: [imageSize.w, imageSize.h]
}); });
return url; return url;
+1 -4
View File
@@ -125,16 +125,13 @@ OpenLayers.Layer.MapServer.Untiled.prototype =
/** /**
* Method: setTileSize * Method: setTileSize
* Set the tile size based on the map size. This also sets layer.imageSize * Set the tile size based on the map size.
* and layer.imageOffset for use by Tile.Image.
*/ */
setTileSize: function() { setTileSize: function() {
var tileSize = this.map.getSize(); var tileSize = this.map.getSize();
tileSize.w = tileSize.w * this.ratio; tileSize.w = tileSize.w * this.ratio;
tileSize.h = tileSize.h * this.ratio; tileSize.h = tileSize.h * this.ratio;
this.tileSize = tileSize; this.tileSize = tileSize;
this.imageSize = tileSize;
this.imageOffset = new OpenLayers.Pixel(0, 0);
}, },
/** /**
+4 -2
View File
@@ -142,10 +142,12 @@ OpenLayers.Layer.WMS.prototype =
*/ */
getURL: function (bounds) { getURL: function (bounds) {
bounds = this.adjustBounds(bounds); bounds = this.adjustBounds(bounds);
var imageSize = this.getImageSize();
return this.getFullRequestString( return this.getFullRequestString(
{BBOX:bounds.toBBOX(), {BBOX:bounds.toBBOX(),
WIDTH:this.imageSize.w, WIDTH:imageSize.w,
HEIGHT:this.imageSize.h}); HEIGHT:imageSize.h});
}, },
/** /**
+1 -4
View File
@@ -147,16 +147,13 @@ OpenLayers.Layer.WMS.Untiled.prototype =
/** /**
* Method: setTileSize * Method: setTileSize
* Set the tile size based on the map size. This also sets layer.imageSize * Set the tile size based on the map size.
* and layer.imageOffset for use by Tile.Image.
*/ */
setTileSize: function() { setTileSize: function() {
var tileSize = this.map.getSize(); var tileSize = this.map.getSize();
tileSize.w = tileSize.w * this.ratio; tileSize.w = tileSize.w * this.ratio;
tileSize.h = tileSize.h * this.ratio; tileSize.h = tileSize.h * this.ratio;
this.tileSize = tileSize; this.tileSize = tileSize;
this.imageSize = tileSize;
this.imageOffset = new OpenLayers.Pixel(0, 0);
}, },
/** /**
+11 -6
View File
@@ -107,13 +107,14 @@ OpenLayers.Tile.Image.prototype =
OpenLayers.Util.modifyDOMElement(this.frame, OpenLayers.Util.modifyDOMElement(this.frame,
null, this.position, this.size); null, this.position, this.size);
var imageSize = this.layer.getImageSize();
if (this.layer.alpha) { if (this.layer.alpha) {
OpenLayers.Util.modifyAlphaImageDiv(this.imgDiv, OpenLayers.Util.modifyAlphaImageDiv(this.imgDiv,
null, null, this.layer.imageSize, this.url); null, null, imageSize, this.url);
} else { } else {
this.imgDiv.src = this.url; this.imgDiv.src = this.url;
OpenLayers.Util.modifyDOMElement(this.imgDiv, OpenLayers.Util.modifyDOMElement(this.imgDiv,
null, null, this.layer.imageSize) ; null, null, imageSize) ;
} }
this.drawn = true; this.drawn = true;
return true; return true;
@@ -153,10 +154,14 @@ OpenLayers.Tile.Image.prototype =
* Creates the imgDiv property on the tile. * Creates the imgDiv property on the tile.
*/ */
initImgDiv: function() { initImgDiv: function() {
var offset = this.layer.imageOffset;
var size = this.layer.getImageSize();
if (this.layer.alpha) { if (this.layer.alpha) {
this.imgDiv = OpenLayers.Util.createAlphaImageDiv(null, this.imgDiv = OpenLayers.Util.createAlphaImageDiv(null,
this.layer.imageOffset, offset,
this.layer.imageSize, size,
null, null,
"relative", "relative",
null, null,
@@ -165,8 +170,8 @@ OpenLayers.Tile.Image.prototype =
true); true);
} else { } else {
this.imgDiv = OpenLayers.Util.createImage(null, this.imgDiv = OpenLayers.Util.createImage(null,
this.layer.imageOffset, offset,
this.layer.imageSize, size,
null, null,
"relative", "relative",
null, null,
+1 -4
View File
@@ -39,7 +39,7 @@
} }
function test_50_Layer_Image_tileTests (t) { function test_50_Layer_Image_tileTests (t) {
t.plan(9); t.plan(6);
var map = new OpenLayers.Map('map'); var map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.Image('Test Layer', layer = new OpenLayers.Layer.Image('Test Layer',
@@ -49,9 +49,6 @@
map.addLayer(layer); map.addLayer(layer);
map.zoomToMaxExtent(); map.zoomToMaxExtent();
t.ok(layer.imageSize, "layer.imageSize is set");
t.ok(layer.tileSize, "layer.tileSize is set");
t.ok(layer.tileSize.equals(layer.imageSize), "tileSize equals imageSize");
// no resolution info was sent, so maxResolution should be calculated // no resolution info was sent, so maxResolution should be calculated
// by aspectRatio*extent/size (this is the pixel aspect ratio) // by aspectRatio*extent/size (this is the pixel aspect ratio)
+4 -4
View File
@@ -188,11 +188,11 @@
map.setCenter(new OpenLayers.LonLat(0,0), 5); map.setCenter(new OpenLayers.LonLat(0,0), 5);
var tile = layer.grid[0][0]; var tile = layer.grid[0][0];
t.ok(tile.layer.imageSize.equals(tile.size), t.ok(tile.layer.imageSize == null,
"zero size gutter doesn't change image size"); "zero size gutter doesn't set image size");
t.ok(tile.layer.imageOffset.equals(new OpenLayers.Pixel(0, 0)), t.ok(tile.layer.imageOffset == null,
"zero size gutter doesn't affect image offset"); "zero size gutter doesn't set image offset");
var zero_gutter_bounds = tile.bounds; var zero_gutter_bounds = tile.bounds;