fix tests, and add new ones
This commit is contained in:
@@ -21,14 +21,13 @@
|
||||
|
||||
|
||||
function test_Layer_Grid_constructor (t) {
|
||||
t.plan( 6 );
|
||||
t.plan( 5 );
|
||||
|
||||
layer = new OpenLayers.Layer.Grid(name, url, params, null);
|
||||
t.ok( layer instanceof OpenLayers.Layer.Grid, "returns OpenLayers.Layer.Grid object" );
|
||||
t.eq( layer.buffer, 0, "buffer default is 0");
|
||||
t.eq( layer.ratio, 1.5, "ratio default is 1.5");
|
||||
t.eq( layer.numLoadingTiles, 0, "numLoadingTiles starts at 0");
|
||||
t.eq( layer.backBufferData, {}, "backBufferData set to empty object");
|
||||
|
||||
var obj = {};
|
||||
var func = function() {};
|
||||
@@ -50,7 +49,7 @@
|
||||
}
|
||||
|
||||
function test_Layer_Grid_clearTiles (t) {
|
||||
t.plan(3);
|
||||
t.plan(4);
|
||||
|
||||
var map = new OpenLayers.Map('map');
|
||||
layer = new OpenLayers.Layer.WMS(name, url, params);
|
||||
@@ -86,6 +85,7 @@
|
||||
t.ok( layer.grid != null, "layer.grid does not get nullified" );
|
||||
t.eq(tilesDeleted, numTiles, "all tiles destroy()ed properly");
|
||||
t.ok(allTilesUnhooked, "all tiles unhooked before being destroyed");
|
||||
t.eq(layer.gridResolution, null, "gridResolution set to null");
|
||||
|
||||
OpenLayers.Tile.Image.prototype.destroy =
|
||||
OpenLayers.Tile.Image.prototype._destroy;
|
||||
@@ -168,6 +168,7 @@
|
||||
var map = new OpenLayers.Map('map');
|
||||
layer = new OpenLayers.Layer.WMS(name, url, params);
|
||||
layer.destroy = function() {}; //we're going to do funky things with the grid
|
||||
layer.applyBackBuffer = function() {}; // backbuffering isn't under test here
|
||||
map.addLayer(layer);
|
||||
|
||||
//make sure null bounds doesnt cause script error.
|
||||
@@ -391,6 +392,8 @@
|
||||
getLayerPxFromLonLat: function(ul) {
|
||||
t.ok(ul.equals(desiredUL), "correct ul passed to translation");
|
||||
return translatedPX;
|
||||
},
|
||||
getResolution: function() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -588,7 +591,7 @@
|
||||
|
||||
function test_Layer_Grid_destroy (t) {
|
||||
|
||||
t.plan( 9 );
|
||||
t.plan( 10 );
|
||||
|
||||
var map = new OpenLayers.Map('map');
|
||||
layer = new OpenLayers.Layer.Grid(name, url, params);
|
||||
@@ -605,17 +608,21 @@
|
||||
map.setCenter(new OpenLayers.LonLat(0,0), 10);
|
||||
map.setCenter(new OpenLayers.LonLat(1,1));
|
||||
|
||||
|
||||
//grab a reference to one of the tiles
|
||||
var tile = layer.grid[1][1];
|
||||
t.eq( tile.imgDiv.className, "olTileImage", "Tile has an image" );
|
||||
|
||||
// add a fake back buffer to the layer
|
||||
var backBuffer = document.createElement('div');
|
||||
layer.backBuffer = backBuffer
|
||||
layer.div.appendChild(backBuffer);
|
||||
|
||||
layer.destroy();
|
||||
t.eq( tile.imgDiv, null, "Tile destroyed" );
|
||||
t.eq( layer.timerId, null, "Tile loading timeout cleared");
|
||||
|
||||
t.ok( layer.grid == null, "tiles appropriately destroyed")
|
||||
t.eq( layer.backBufferData, null, "backBufferData set to null");
|
||||
t.ok( backBuffer.parentNode === layer.div, "back buffer removed");
|
||||
t.eq( layer.backBuffer, null, "backBuffer set not null in the layer");
|
||||
|
||||
// destroy after remove from map
|
||||
layer = new OpenLayers.Layer.WMS(name, url, params);
|
||||
@@ -782,23 +789,20 @@
|
||||
// initial resolution is 0.025
|
||||
resolution = undefined;
|
||||
map.setCenter(new OpenLayers.LonLat(0, 0), 2);
|
||||
t.eq(resolution, undefined,
|
||||
t.eq(resolution, 0.025,
|
||||
'applyBackBuffer not called on first moveTo');
|
||||
layer.backBufferData.resolution = 0.025;
|
||||
|
||||
// move to (-90, 45)
|
||||
resolution = undefined;
|
||||
map.setCenter(new OpenLayers.LonLat(-90, 45));
|
||||
t.eq(resolution, 0.025,
|
||||
'applyBackBuffer called when map is moved');
|
||||
layer.backBufferData.resolution = 0.025;
|
||||
|
||||
// change to resolution 1
|
||||
resolution = undefined;
|
||||
map.zoomTo(0);
|
||||
t.eq(resolution, 1,
|
||||
'applyBackBuffer called when map is zoomed out');
|
||||
layer.backBufferData.resolution = 1;
|
||||
|
||||
// change to resolution 0.5
|
||||
resolution = undefined;
|
||||
@@ -828,23 +832,20 @@
|
||||
// initial resolution is 0.025
|
||||
resolution = undefined;
|
||||
map.setCenter(new OpenLayers.LonLat(0, 0), 2);
|
||||
t.eq(resolution, undefined,
|
||||
t.eq(resolution, 0.025,
|
||||
'applyBackBuffer not called on first moveTo');
|
||||
layer.backBufferData.resolution = 0.025;
|
||||
|
||||
// move to (-90, 45)
|
||||
resolution = undefined;
|
||||
map.setCenter(new OpenLayers.LonLat(-90, 45));
|
||||
t.eq(resolution, undefined,
|
||||
'applyBackBuffer not called when map is moved');
|
||||
layer.backBufferData.resolution = 0.025;
|
||||
|
||||
// change to resolution 1
|
||||
resolution = undefined;
|
||||
map.zoomTo(0);
|
||||
t.eq(resolution, 1,
|
||||
'applyBackBuffer called when map is zoomed out');
|
||||
layer.backBufferData.resolution = 1;
|
||||
|
||||
// change to resolution 0.5
|
||||
map.zoomTo(1);
|
||||
@@ -853,6 +854,7 @@
|
||||
|
||||
map.destroy();
|
||||
}
|
||||
|
||||
function test_transformDiv(t) {
|
||||
|
||||
t.plan(8);
|
||||
@@ -933,7 +935,8 @@
|
||||
backBuffer = document.createElement('div');
|
||||
return backBuffer;
|
||||
};
|
||||
layer.backBufferData = {resolution: 32, lonlat: map.getCenter()};
|
||||
layer.gridResolution = 32;
|
||||
layer.grid[0][0].bounds = new OpenLayers.Bounds(0, 1, 1, 0);
|
||||
layer.applyBackBuffer(2);
|
||||
t.ok(layer.backBuffer === backBuffer,
|
||||
'back buffer set in layer');
|
||||
@@ -953,7 +956,8 @@
|
||||
backBuffer = document.createElement('div');
|
||||
return backBuffer;
|
||||
};
|
||||
layer.backBufferData = {resolution: 32, lonlat: map.getCenter()};
|
||||
layer.gridResolution = 32;
|
||||
layer.grid[0][0].bounds = new OpenLayers.Bounds(0, 1, 1, 0);
|
||||
map.layerContainerDiv.style.left = '20px';
|
||||
map.layerContainerDiv.style.top = '-20px';
|
||||
layer.applyBackBuffer(2);
|
||||
@@ -974,7 +978,7 @@
|
||||
}
|
||||
|
||||
function test_createBackBuffer(t) {
|
||||
t.plan(6);
|
||||
t.plan(7);
|
||||
|
||||
var map = new OpenLayers.Map('map');
|
||||
var layer = new OpenLayers.Layer.WMS('', '', {}, {
|
||||
@@ -991,8 +995,10 @@
|
||||
return;
|
||||
};
|
||||
backBuffer = layer.createBackBuffer();
|
||||
t.eq(backBuffer, undefined,
|
||||
'createBackBuffer returns undefined if createBackBuffer returns undefined');
|
||||
t.ok(backBuffer != undefined,
|
||||
'createBackBuffer returns a back buffer');
|
||||
t.eq(backBuffer.childNodes.length, 0,
|
||||
'returned back buffer has no child nodes');
|
||||
|
||||
OpenLayers.Tile.Image.prototype.createBackBuffer = function() {
|
||||
return document.createElement('div');
|
||||
@@ -1013,22 +1019,25 @@
|
||||
OpenLayers.Tile.Image.prototype.createBackBuffer = createBackBuffer;
|
||||
}
|
||||
|
||||
function test_updateBackBufferData(t) {
|
||||
t.plan(1);
|
||||
function test_removeBackBuffer(t) {
|
||||
t.plan(3);
|
||||
|
||||
var map = new OpenLayers.Map('map', {
|
||||
resolutions: [32, 16]
|
||||
});
|
||||
var layer = new OpenLayers.Layer.WMS('', '', {}, {
|
||||
isBaseLayer: true
|
||||
});
|
||||
var map = new OpenLayers.Map('map');
|
||||
var layer = new OpenLayers.Layer.WMS('', '', {}, {isBaseLayer: true});
|
||||
map.addLayer(layer);
|
||||
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
||||
|
||||
layer.backBufferData = {};
|
||||
layer.updateBackBufferData();
|
||||
t.eq(layer.backBufferData.resolution, 32,
|
||||
'backBufferData has correct resolution');
|
||||
// add a fake back buffer
|
||||
var backBuffer = document.createElement('div');
|
||||
layer.backBuffer = backBuffer;
|
||||
layer.div.appendChild(backBuffer);
|
||||
layer.backBufferResolution = 32;
|
||||
|
||||
layer.removeBackBuffer();
|
||||
t.eq(layer.backBuffer, null, 'backBuffer set to null in layer');
|
||||
t.eq(layer.backBufferResolution, null,
|
||||
'backBufferResolution set to null in layer');
|
||||
t.ok(backBuffer.parentNode !== layer.div,
|
||||
'back buffer removed from layer');
|
||||
|
||||
map.destroy();
|
||||
}
|
||||
@@ -1054,11 +1063,6 @@
|
||||
map.addLayer(layer);
|
||||
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
|
||||
|
||||
// pretend the image has been loaded
|
||||
layer.updateBackBufferData();
|
||||
layer.grid[0][0].isLoading = false; // this is to be able to create
|
||||
// a back buffer
|
||||
|
||||
// move
|
||||
map.setCenter(new OpenLayers.LonLat(10, 10));
|
||||
t.ok(layer.backBuffer && layer.backBuffer.parentNode === layer.div,
|
||||
@@ -1073,7 +1077,7 @@
|
||||
}
|
||||
|
||||
function test_backbuffer_scaled_layer(t) {
|
||||
t.plan(15);
|
||||
t.plan(12);
|
||||
|
||||
//
|
||||
// set up
|
||||
@@ -1090,14 +1094,20 @@
|
||||
);
|
||||
|
||||
layer.serverResolutions = [32, 16, 8];
|
||||
layer.createBackBuffer = function() {
|
||||
return document.createElement('div');
|
||||
};
|
||||
|
||||
map.addLayer(layer);
|
||||
map.setCenter(new OpenLayers.LonLat(0, 0), 2);
|
||||
|
||||
layer.updateBackBufferData();
|
||||
layer.createBackBuffer = function() {
|
||||
return document.createElement('div');
|
||||
};
|
||||
|
||||
// we want to control when the back buffer is removed
|
||||
var removeBackBuffer = OpenLayers.Function.bind(
|
||||
layer.removeBackBuffer, layer);
|
||||
layer.removeBackBuffer = function() {};
|
||||
|
||||
// layer.updateBackBufferData();
|
||||
|
||||
//
|
||||
// test
|
||||
@@ -1105,65 +1115,63 @@
|
||||
|
||||
// change resolution from 8 to 4
|
||||
map.zoomTo(3);
|
||||
t.ok(layer.backBuffer == undefined,
|
||||
'[8->4] back buffer not applied');
|
||||
layer.updateBackBufferData();
|
||||
t.eq(layer.backBuffer.style.width, '100%',
|
||||
'[8->4] back buffer not scaled');
|
||||
removeBackBuffer();
|
||||
|
||||
// change resolution from 8 to 2
|
||||
map.zoomTo(2); layer.updateBackBufferData(); map.zoomTo(4);
|
||||
t.ok(layer.backBuffer == undefined,
|
||||
'[8->2] back buffer not applies');
|
||||
layer.updateBackBufferData();
|
||||
map.zoomTo(2); removeBackBuffer(); map.zoomTo(4);
|
||||
t.eq(layer.backBuffer.style.width, '100%',
|
||||
'[8->2] back buffer not scaled');
|
||||
removeBackBuffer();
|
||||
|
||||
// change resolution from 16 to 4
|
||||
map.zoomTo(1); layer.updateBackBufferData(); map.zoomTo(3);
|
||||
t.ok(layer.backBuffer != undefined,
|
||||
'[16->4] back buffer applied');
|
||||
map.zoomTo(1); removeBackBuffer(); map.zoomTo(3);
|
||||
t.eq(layer.backBuffer.style.width, '200%',
|
||||
'[16->4] back buffer width is as expected');
|
||||
t.eq(layer.backBuffer.style.width, '200%',
|
||||
'[16->4] back buffer height is as expected');
|
||||
layer.updateBackBufferData();
|
||||
removeBackBuffer();
|
||||
|
||||
// change resolution from 32 to 1
|
||||
map.zoomTo(0); layer.updateBackBufferData(); map.zoomTo(5);
|
||||
t.ok(layer.backBuffer != undefined,
|
||||
'[32->1] back buffer applied');
|
||||
map.zoomTo(0); removeBackBuffer(); map.zoomTo(5);
|
||||
t.eq(layer.backBuffer.style.width, '400%',
|
||||
'[32->1] back buffer width is as expected');
|
||||
t.eq(layer.backBuffer.style.width, '400%',
|
||||
'[32->1] back buffer height is as expected');
|
||||
layer.updateBackBufferData();
|
||||
removeBackBuffer();
|
||||
|
||||
// change resolution from 4 to 2
|
||||
map.zoomTo(3); layer.updateBackBufferData(); map.zoomTo(4);
|
||||
t.ok(layer.backBuffer == undefined,
|
||||
'[4->2] back buffer not applied');
|
||||
layer.updateBackBufferData();
|
||||
map.zoomTo(3); removeBackBuffer(); map.zoomTo(4);
|
||||
t.eq(layer.backBuffer.style.width, '100%',
|
||||
'[4->2] back buffer not scaled');
|
||||
removeBackBuffer();
|
||||
|
||||
// change resolution from 4 to 1
|
||||
map.zoomTo(3); layer.updateBackBufferData(); map.zoomTo(5);
|
||||
t.ok(layer.backBuffer == undefined,
|
||||
'[4->1] back buffer not applied');
|
||||
map.zoomTo(3); removeBackBuffer(); map.zoomTo(5);
|
||||
t.eq(layer.backBuffer.style.width, '100%',
|
||||
'[4->1] back buffer not scaled');
|
||||
removeBackBuffer();
|
||||
|
||||
// change resolution from 1 to 4
|
||||
map.zoomTo(5); layer.updateBackBufferData(); map.zoomTo(3);
|
||||
t.ok(layer.backBuffer == undefined,
|
||||
'[1->4] back buffer not applied');
|
||||
map.zoomTo(5); removeBackBuffer(); map.zoomTo(3);
|
||||
t.eq(layer.backBuffer.style.width, '100%',
|
||||
'[1->4] back buffer not scaled');
|
||||
removeBackBuffer();
|
||||
|
||||
// change resolution from 4 to 8
|
||||
map.zoomTo(3); layer.updateBackBufferData(); map.zoomTo(2);
|
||||
t.ok(layer.backBuffer == undefined,
|
||||
'[4->8] back buffer not applied');
|
||||
map.zoomTo(3); removeBackBuffer(); map.zoomTo(2);
|
||||
t.eq(layer.backBuffer.style.width, '100%',
|
||||
'[4->8] back buffer not scaled');
|
||||
removeBackBuffer();
|
||||
|
||||
// change resolution from 4 to 16
|
||||
map.zoomTo(3); layer.updateBackBufferData(); map.zoomTo(1);
|
||||
t.ok(layer.backBuffer != undefined,
|
||||
'[4->16] back buffer applied');
|
||||
map.zoomTo(3); removeBackBuffer(); map.zoomTo(1);
|
||||
t.eq(layer.backBuffer.style.width, '50%',
|
||||
'[4->16] back buffer width is as expected');
|
||||
t.eq(layer.backBuffer.style.width, '50%',
|
||||
'[4->16] back buffer height is as expected');
|
||||
removeBackBuffer();
|
||||
|
||||
//
|
||||
// tear down
|
||||
|
||||
Reference in New Issue
Block a user