From e3490e7aba10960e5fd4e5df17858cb162a106b8 Mon Sep 17 00:00:00 2001 From: crschmidt Date: Sun, 5 Aug 2007 13:38:55 +0000 Subject: [PATCH] Two size/resize issues on singleTile layers, #886, with tests by Andreas. Many thanks, Andreas! git-svn-id: http://svn.openlayers.org/trunk/openlayers@3861 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/Grid.js | 19 ++++++++++++++++--- tests/Layer/test_Grid.html | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index e3a12174d5..03f345d029 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -196,8 +196,8 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { setTileSize: function(size) { if (this.singleTile) { var size = this.map.getSize().clone(); - size.h = size.h * this.ratio; - size.w = size.w * this.ratio; + size.h = parseInt(size.h * this.ratio); + size.w = parseInt(size.w * this.ratio); } OpenLayers.Layer.HTTPRequest.prototype.setTileSize.apply(this, [size]); }, @@ -268,7 +268,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { var ul = new OpenLayers.LonLat(tileBounds.left, tileBounds.top); var px = this.map.getLayerPxFromLonLat(ul); - + if (!this.grid.length) { this.grid[0] = []; } @@ -651,5 +651,18 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, { } }, + /** + * Method: onMapResize + * For singleTile layers, this will replace the tile with the + * a new one with updated tileSize and extent. + */ + onMapResize: function() { + if (this.singleTile) { + this.clearGrid(); + this.setTileSize(); + this.initSingleTile(this.map.getExtent()); + } + }, + CLASS_NAME: "OpenLayers.Layer.Grid" }); diff --git a/tests/Layer/test_Grid.html b/tests/Layer/test_Grid.html index ce1cbb3575..8573f48651 100644 --- a/tests/Layer/test_Grid.html +++ b/tests/Layer/test_Grid.html @@ -513,6 +513,21 @@ entry = g_unregistered["loadend"]; t.ok( entry && entry[0] == layer && entry[1] == tile.onLoadEnd, "loadend correctly unregistered"); } + + function test_16_Layer_Grid_tileSizeIsInteger(t) { + t.plan(1); + + var map = new OpenLayers.Map('map'); + var layer = new OpenLayers.Layer.Grid(name, url, params, { + singleTile: true, + ratio: 1.5 + }); + map.addLayers([layer]); + + width = layer.tileSize.w; + height = layer.tileSize.h; + t.ok(width == parseInt(width) && height == parseInt(height), "calculated tileSize width/height are integer values"); + } function test_99_Layer_Grid_destroy (t) { @@ -547,6 +562,6 @@ - +