#529 give tiles gutters - all layers that use Tile.Image must now look after layer.imageSize and layer.imageOffset - this is handled by layer.setTileSize - for untiled layers, setTileSize must be defined by the subclass - gutters are currently supported in Layer.Mapserver and Layer.WMS

git-svn-id: http://svn.openlayers.org/trunk/openlayers@2979 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2007-04-02 17:18:38 +00:00
parent 7f0ccb69f0
commit b6a5e6619a
14 changed files with 351 additions and 56 deletions
+84 -2
View File
@@ -65,12 +65,45 @@ OpenLayers.Layer.prototype = {
* @type Boolean
*/
inRange: false,
/**
* For layers that use Tile.Image, the image size is cached here. For
* layers without a gutter, the image size is equal to the tile size.
* For layers with a gutter, the image is larger than the tile by twice
* the gutter in each dimension.
*
* @type OpenLayers.Size
* @private
*/
imageSize: null,
/**
* For layers that use Tile.Image, the image offset is cached here.
* Layers without a gutter have zero offset. For layers with a gutter,
* the image offset represents displacement due to the gutter.
*
* @type OpenLayers.Pixel
* @private
*/
imageOffset: null,
// OPTIONS
/** @type Array */
options: null,
/** Determines the width (in pixels) of the gutter around image tiles
* to ignore. By setting this property to a non-zero value, images
* will be requested that are wider and taller than the tile size by
* a value of 2 x gutter. This allows artifacts of rendering at tile
* edges to be ignored. Set a gutter value that is equal to half the size
* of the widest symbol that needs to be displayed. Defaults to zero.
* Non-tiled layers always have zero gutter.
*
* @type Int
*/
gutter: 0,
/** @type String */
projection: null,
@@ -243,9 +276,41 @@ OpenLayers.Layer.prototype = {
if (!this.isBaseLayer) {
this.inRange = this.calculateInRange();
}
}
// deal with gutters
this.setTileSize();
},
/**
* Set the tile size based on the map size. This also sets layer.imageSize
* and layer.imageOffset for use by Tile.Image.
*
* @param OpenLayers.Size
*/
setTileSize: function(size) {
var tileSize = (size) ? size :
((this.tileSize) ? this.tileSize :
this.map.getTileSize());
this.tileSize = tileSize;
if(this.gutter) {
// layers with gutters need non-null tile sizes
//if(tileSize == null) {
// OpenLayers.console.error("Error in layer.setMap() for " +
// this.name + ": layers with gutters " +
// "need non-null tile sizes");
//}
this.imageOffset = new OpenLayers.Pixel(-this.gutter, -this.gutter);
this.imageSize = new OpenLayers.Size(tileSize.w + (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);
}
},
/**
* @returns Whether or not the layer should be displayed (if in range)
* @type Boolean
@@ -559,6 +624,23 @@ OpenLayers.Layer.prototype = {
return px;
},
/**
* Adjusts the extent of a bounds in map units by the layer's gutter
* in pixels.
*
* @param {OpenLayers.Bounds} bounds
* @type OpenLayers.Bounds
* @return A bounds adjusted in height and width by the gutter
*/
adjustBoundsByGutter: function(bounds) {
var mapGutter = this.gutter * this.map.getResolution();
bounds = new OpenLayers.Bounds(bounds.left - mapGutter,
bounds.bottom - mapGutter,
bounds.right + mapGutter,
bounds.top + mapGutter);
return bounds;
},
/**
* Sets the opacity for the entire layer (all images)
* @param {Float} opacity
@@ -566,7 +648,7 @@ OpenLayers.Layer.prototype = {
setOpacity: function(opacity) {
this.opacity = opacity;
for(var i=0; i<this.div.childNodes.length; ++i) {
var element = this.div.childNodes[i];
var element = this.div.childNodes[i].firstChild;
OpenLayers.Util.modifyDOMElement(element, null, null, null,
null, null, null, opacity);
}