diff --git a/lib/OpenLayers/Layer/UTFGrid.js b/lib/OpenLayers/Layer/UTFGrid.js index 850fd17650..82ed20abb2 100644 --- a/lib/OpenLayers/Layer/UTFGrid.js +++ b/lib/OpenLayers/Layer/UTFGrid.js @@ -172,11 +172,24 @@ OpenLayers.Layer.UTFGrid = OpenLayers.Class(OpenLayers.Layer.Grid, { getTile: function(loc) { var info = this.getTileInfo(loc); + var res = this.getServerResolution(); + + var gridOrigin = this.grid[0][0].bounds; + var gridColOffset = (gridOrigin.left - this.tileOrigin.lon) / (res * this.tileSize.w); + var gridRowOffset = (this.tileOrigin.lat - gridOrigin.top) / (res * this.tileSize.h); + + var fx = (loc.lon - this.tileOrigin.lon) / (res * this.tileSize.w); + var fy = (this.tileOrigin.lat - loc.lat) / (res * this.tileSize.h); + var globalCol = Math.floor(fx); + var globalRow = Math.floor(fy); + + var row = globalRow - Math.floor(gridRowOffset); + var col = globalCol - Math.floor(gridColOffset); + var tile = null; - //TODO how to find the tile instance given a lonLat - var row = this.grid[1]; //info.row]; - if (typeof(row) !== 'undefined' && row !== null) { - tile = row[1]; //info.col]; + var therow = this.grid[row]; + if (typeof(therow) !== 'undefined' && therow !== null) { + tile = therow[col]; } return tile; }, diff --git a/lib/OpenLayers/Tile/UTFGrid.js b/lib/OpenLayers/Tile/UTFGrid.js index 403c82b398..53949177b9 100644 --- a/lib/OpenLayers/Tile/UTFGrid.js +++ b/lib/OpenLayers/Tile/UTFGrid.js @@ -27,9 +27,9 @@ OpenLayers.Tile.UTFGrid = OpenLayers.Class(OpenLayers.Tile, { url: null, /** - * Property: imgDiv + * Property: json * TODO - * {HTMLImageElement} The image for this tile. + * {Object} The image for this tile. */ json: null, @@ -111,7 +111,6 @@ OpenLayers.Tile.UTFGrid = OpenLayers.Class(OpenLayers.Tile, { * TODO Investigate JSONP method to avoid xbrowser polucy * grid = function(e) { - console.log("-----------"); console.log(e); };