Add a getTileBounds method to gridded layers. Thanks to crschmidt for the tests on this one. Committed with a few minor ndoc changes (closes 482).
git-svn-id: http://svn.openlayers.org/trunk/openlayers@4088 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -229,13 +229,16 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: getTilesBounds
|
||||
* Get the bounds of the grid
|
||||
*
|
||||
* Return:
|
||||
* APIMethod: getTileBounds
|
||||
* Returns The tile bounds for a layer given a pixel location.
|
||||
*
|
||||
* Parameters:
|
||||
* viewPortPx - {<OpenLayers.Pixel>} The location in the viewport.
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Bounds>} A Bounds object representing the bounds of all the
|
||||
* currently loaded tiles (including those partially or not at all seen
|
||||
* onscreen)
|
||||
* currently loaded tiles (including those partially or not at all seen
|
||||
* onscreen).
|
||||
*/
|
||||
getTilesBounds: function() {
|
||||
var bounds = null;
|
||||
@@ -673,5 +676,31 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: getTileBounds
|
||||
* Returns The tile bounds for a layer given a pixel location
|
||||
*
|
||||
* Parameters:
|
||||
* viewPortPx - {OpenLayers.Pixel} The location in the viewport
|
||||
*/
|
||||
getTileBounds: function(viewPortPx) {
|
||||
var maxExtent = this.map.getMaxExtent();
|
||||
var resolution = this.getResolution();
|
||||
var tileMapWidth = resolution * this.tileSize.w;
|
||||
var tileMapHeight = resolution * this.tileSize.h;
|
||||
var mapPoint = this.getLonLatFromViewPortPx(viewPortPx);
|
||||
var tileLeft = maxExtent.left + (tileMapWidth *
|
||||
Math.floor((mapPoint.lon -
|
||||
maxExtent.left) /
|
||||
tileMapWidth));
|
||||
var tileBottom = maxExtent.bottom + (tileMapHeight *
|
||||
Math.floor((mapPoint.lat -
|
||||
maxExtent.bottom) /
|
||||
tileMapHeight));
|
||||
return new OpenLayers.Bounds(tileLeft, tileBottom,
|
||||
tileLeft + tileMapWidth,
|
||||
tileBottom + tileMapHeight);
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Layer.Grid"
|
||||
});
|
||||
|
||||
@@ -225,6 +225,28 @@ OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
||||
|
||||
return obj;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: getTileBounds
|
||||
* Returns The tile bounds for a layer given a pixel location.
|
||||
*
|
||||
* Parameters:
|
||||
* viewPortPx - {<OpenLayers.Pixel>} The location in the viewport.
|
||||
*
|
||||
* Returns:
|
||||
* {<OpenLayers.Bounds>} Bounds of the tile at the given pixel location.
|
||||
*/
|
||||
getTileBounds: function(viewPortPx) {
|
||||
var resolution = this.getResolution();
|
||||
var tileMapWidth = resolution * this.tileSize.w;
|
||||
var tileMapHeight = resolution * this.tileSize.h;
|
||||
var mapPoint = this.getLonLatFromViewPortPx(viewPortPx);
|
||||
var tileLeft = tileMapWidth * Math.floor(mapPoint.lon / tileMapWidth);
|
||||
var tileBottom = tileMapHeight * Math.floor(mapPoint.lat / tileMapHeight);
|
||||
return new OpenLayers.Bounds(tileLeft, tileBottom,
|
||||
tileLeft + tileMapWidth,
|
||||
tileBottom + tileMapHeight);
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Layer.KaMap"
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user