From 2e67a6aedf557379c49cb4ebb4ab013595b8dc6f Mon Sep 17 00:00:00 2001 From: euzuro Date: Wed, 19 Jul 2006 15:20:25 +0000 Subject: [PATCH] add getTile() function to Grid.js. with tests git-svn-id: http://svn.openlayers.org/trunk/openlayers@981 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Layer/Grid.js | 24 ++++++++++++++++++++++++ tests/test_Layer_Grid.html | 25 +++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/lib/OpenLayers/Layer/Grid.js b/lib/OpenLayers/Layer/Grid.js index 2604cd7454..93e4206d8e 100644 --- a/lib/OpenLayers/Layer/Grid.js +++ b/lib/OpenLayers/Layer/Grid.js @@ -101,6 +101,30 @@ OpenLayers.Layer.Grid.prototype = this.tileSize = size.clone(); } }, + + /** + * @param {String} tileID + * + * @returns The OpenLayers.Tile with the corresponding ID from the grid. + * if no tile is found, returns null + * @type OpenLayers.Tile + */ + getTile: function(tileID) { + var foundTile = null; + if (this.grid) { + + for(var iRow = 0; iRow < this.grid.length; iRow++) { + var row = this.grid[iRow]; + for(var iCol = 0; iCol < row.length; iCol++) { + var tile = row[iCol]; + if (tile.id == tileID) { + foundTile = tile; + } + } + } + } + return foundTile; + }, /** This function is called whenever the map is moved. All the moving * of actual 'tiles' is done by the map, but moveTo's role is to accept diff --git a/tests/test_Layer_Grid.html b/tests/test_Layer_Grid.html index 345106ad02..8c1b878766 100644 --- a/tests/test_Layer_Grid.html +++ b/tests/test_Layer_Grid.html @@ -173,6 +173,31 @@ } + function test_11_Layer_Grid_getTile(t) { + + t.plan(2); + + var options = {tileSize: new OpenLayers.Size(500,50)}; + var map = new OpenLayers.Map('map', options); + + //test with tile creation + layer = new OpenLayers.Layer.WMS(name, url, params); + map.addLayer(layer); + + map.setCenter(new OpenLayers.LonLat(0,0), 5); + + //grab a reference to one of the tiles + var tile = layer.grid[0][0]; + + var gotTile = layer.getTile(tile.id); + + t.ok( gotTile == tile, "got right tile"); + + gotTile = layer.getTile("chicken"); + t.ok( gotTile == null, "getTile() of bogus id returns null"); + } + + function test_99_Layer_Grid_destroy (t) { t.plan( 4 );