Fixing KaMap layer
This also fixes an issue that has gone unnoticed for a while: the grid did not cover the bottom of the map viewport, but instead covered an invisible area above the top of the map viewport.
This commit is contained in:
@@ -92,8 +92,8 @@ OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
* resolution - {Number}
|
* resolution - {Number}
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* {Object} Object containing properties tilelon, tilelat, tileoffsetlat,
|
* {Object} Object containing properties tilelon, tilelat, tileoffsetx,
|
||||||
* tileoffsetlat, tileoffsetx, tileoffsety
|
* tileoffsety, startcol, startrow
|
||||||
*/
|
*/
|
||||||
calculateGridLayout: function(bounds, origin, resolution) {
|
calculateGridLayout: function(bounds, origin, resolution) {
|
||||||
var tilelon = resolution*this.tileSize.w;
|
var tilelon = resolution*this.tileSize.w;
|
||||||
@@ -103,22 +103,42 @@ OpenLayers.Layer.KaMap = OpenLayers.Class(OpenLayers.Layer.Grid, {
|
|||||||
var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
|
var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
|
||||||
var tilecolremain = offsetlon/tilelon - tilecol;
|
var tilecolremain = offsetlon/tilelon - tilecol;
|
||||||
var tileoffsetx = -tilecolremain * this.tileSize.w;
|
var tileoffsetx = -tilecolremain * this.tileSize.w;
|
||||||
var tileoffsetlon = tilecol * tilelon;
|
|
||||||
|
|
||||||
var offsetlat = bounds.top;
|
var offsetlat = bounds.top;
|
||||||
var tilerow = Math.ceil(offsetlat/tilelat) + this.buffer;
|
var tilerow = Math.floor(offsetlat/tilelat) + this.buffer;
|
||||||
var tilerowremain = tilerow - offsetlat/tilelat;
|
var tilerowremain = tilerow - offsetlat/tilelat;
|
||||||
var tileoffsety = -(tilerowremain+1) * this.tileSize.h;
|
var tileoffsety = -(tilerowremain+1) * this.tileSize.h;
|
||||||
var tileoffsetlat = tilerow * tilelat;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tilelon: tilelon, tilelat: tilelat,
|
tilelon: tilelon, tilelat: tilelat,
|
||||||
tileoffsetlon: tileoffsetlon, tileoffsetlat: tileoffsetlat,
|
|
||||||
tileoffsetx: tileoffsetx, tileoffsety: tileoffsety,
|
tileoffsetx: tileoffsetx, tileoffsety: tileoffsety,
|
||||||
startcol: tilecol, startrow: tilerow
|
startcol: tilecol, startrow: tilerow
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method: getTileBoundsForGridIndex
|
||||||
|
*
|
||||||
|
* Parameters:
|
||||||
|
* row - {Number} The row of the grid
|
||||||
|
* col - {Number} The column of the grid
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* {<OpenLayers.Bounds>} The bounds for the tile at (row, col)
|
||||||
|
*/
|
||||||
|
getTileBoundsForGridIndex: function(row, col) {
|
||||||
|
var origin = this.getTileOrigin();
|
||||||
|
var tileLayout = this.gridLayout;
|
||||||
|
var tilelon = tileLayout.tilelon;
|
||||||
|
var tilelat = tileLayout.tilelat;
|
||||||
|
var minX = (tileLayout.startcol + col) * tilelon;
|
||||||
|
var minY = (tileLayout.startrow - row) * tilelat;
|
||||||
|
return new OpenLayers.Bounds(
|
||||||
|
minX, minY,
|
||||||
|
minX + tilelon, minY + tilelat
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIMethod: clone
|
* APIMethod: clone
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -154,9 +154,9 @@
|
|||||||
var m = new OpenLayers.Map('map', {adjustZoom: function(z) {return z;}});
|
var m = new OpenLayers.Map('map', {adjustZoom: function(z) {return z;}});
|
||||||
m.addLayer(layer);
|
m.addLayer(layer);
|
||||||
m.zoomToMaxExtent();
|
m.zoomToMaxExtent();
|
||||||
t.eq(layer.grid[5][7].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=0&l=-256&s=221471921.25", "grid[5][7] kamap is okay");
|
t.eq(layer.grid[4][7].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=0&l=-256&s=221471921.25", "grid[5][7] kamap is okay");
|
||||||
t.eq(layer.grid[5][6].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=0&l=0&s=221471921.25", "grid[5][6] kamap is okay");
|
t.eq(layer.grid[4][6].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=0&l=0&s=221471921.25", "grid[5][6] kamap is okay");
|
||||||
t.eq(layer.grid[5][5].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=0&l=-256&s=221471921.25", "grid[5][5] is okay");
|
t.eq(layer.grid[4][5].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=0&l=-256&s=221471921.25", "grid[5][5] is okay");
|
||||||
t.ok(layer.grid[7][6].url == null, "no latitudinal wrapping - tile not loaded if outside maxExtent");
|
t.ok(layer.grid[7][6].url == null, "no latitudinal wrapping - tile not loaded if outside maxExtent");
|
||||||
m.destroy();
|
m.destroy();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user