| 142 | | |
|---|
| | 156 | |
|---|
| | 157 | function test_07_Layer_Grid_moveTo(t) { |
|---|
| | 158 | |
|---|
| | 159 | t.plan(13); |
|---|
| | 160 | |
|---|
| | 161 | var map = new OpenLayers.Map('map'); |
|---|
| | 162 | layer = new OpenLayers.Layer.WMS(name, url, params); |
|---|
| | 163 | layer.destroy = function() {}; //we're going to do funky things with the grid |
|---|
| | 164 | map.addLayer(layer); |
|---|
| | 165 | |
|---|
| | 166 | //make sure null bounds doesnt cause script error. |
|---|
| | 167 | // no test necessary, just action |
|---|
| | 168 | map.getExtent = function() { return null; } |
|---|
| | 169 | layer.singleTile = false; |
|---|
| | 170 | layer.moveTo(); //checks to make sure null bounds doesnt break us |
|---|
| | 171 | |
|---|
| | 172 | |
|---|
| | 173 | |
|---|
| | 174 | //observing globals |
|---|
| | 175 | layer.initSingleTile = function(bounds) { |
|---|
| | 176 | g_WhichFunc = "InitSingle"; |
|---|
| | 177 | g_Bounds = bounds; |
|---|
| | 178 | }; |
|---|
| | 179 | layer.initGriddedTiles = function(bounds) { |
|---|
| | 180 | g_WhichFunc = "InitGridded"; |
|---|
| | 181 | g_Bounds = bounds; |
|---|
| | 182 | }; |
|---|
| | 183 | layer.moveGriddedTiles = function(bounds) { |
|---|
| | 184 | g_WhichFunc = "MoveGridded"; |
|---|
| | 185 | g_Bounds = bounds; |
|---|
| | 186 | }; |
|---|
| | 187 | var clearTestBounds = function() { |
|---|
| | 188 | g_WhichFunc = null; |
|---|
| | 189 | g_Bounds = null; |
|---|
| | 190 | }; |
|---|
| | 191 | |
|---|
| | 192 | //default map extent (tested every time below) |
|---|
| | 193 | b = new OpenLayers.Bounds(0,0,100,100); |
|---|
| | 194 | map.getExtent = function() { |
|---|
| | 195 | return b; |
|---|
| | 196 | }; |
|---|
| | 197 | var tilesBounds = null; |
|---|
| | 198 | layer.getTilesBounds = function() { |
|---|
| | 199 | return tilesBounds; |
|---|
| | 200 | } |
|---|
| | 201 | |
|---|
| | 202 | |
|---|
| | 203 | //FORCE |
|---|
| | 204 | |
|---|
| | 205 | //empty grid |
|---|
| | 206 | layer.grid = new Array(); |
|---|
| | 207 | //grid |
|---|
| | 208 | clearTestBounds(); |
|---|
| | 209 | layer.singleTile = false; |
|---|
| | 210 | layer.moveTo() |
|---|
| | 211 | t.ok(g_Bounds.equals(b), "if grid is empty, initGridded called"); |
|---|
| | 212 | |
|---|
| | 213 | //singletile |
|---|
| | 214 | clearTestBounds(); |
|---|
| | 215 | layer.singleTile = true; |
|---|
| | 216 | layer.moveTo() |
|---|
| | 217 | t.ok(g_Bounds.equals(b), "if grid is empty, initSingleTile called"); |
|---|
| | 218 | |
|---|
| | 219 | //zoomChanged |
|---|
| | 220 | zoomChanged = true; |
|---|
| | 221 | layer.grid = [ [ {} ] ]; |
|---|
| | 222 | |
|---|
| | 223 | //grid |
|---|
| | 224 | clearTestBounds(); |
|---|
| | 225 | layer.singleTile = false; |
|---|
| | 226 | layer.moveTo(null, zoomChanged); |
|---|
| | 227 | t.ok(g_Bounds.equals(b), "if layer has grid but zoomChanged is called, initGridded called"); |
|---|
| | 228 | |
|---|
| | 229 | //singletile |
|---|
| | 230 | clearTestBounds(); |
|---|
| | 231 | layer.singleTile = true; |
|---|
| | 232 | layer.moveTo(null, zoomChanged); |
|---|
| | 233 | t.ok(g_Bounds.equals(b), "if layer has grid but zoomChanged is called, initSingleTile called"); |
|---|
| | 234 | |
|---|
| | 235 | |
|---|
| | 236 | layer.getTilesBounds = function() { |
|---|
| | 237 | return tilesBounds; |
|---|
| | 238 | } |
|---|
| | 239 | |
|---|
| | 240 | |
|---|
| | 241 | |
|---|
| | 242 | //NO FORCE |
|---|
| | 243 | zoomChanged = false; |
|---|
| | 244 | layer.grid = [ [ {} ] ]; |
|---|
| | 245 | |
|---|
| | 246 | //single tile |
|---|
| | 247 | layer.singleTile = true; |
|---|
| | 248 | |
|---|
| | 249 | //DRAGGING |
|---|
| | 250 | var dragging = true; |
|---|
| | 251 | |
|---|
| | 252 | //in bounds |
|---|
| | 253 | clearTestBounds(); |
|---|
| | 254 | tilesBounds = new OpenLayers.Bounds(-10,-10,110,110); |
|---|
| | 255 | layer.moveTo(null, zoomChanged, dragging); |
|---|
| | 256 | t.ok(g_Bounds == null, "if dragging and tile in bounds, no init()"); |
|---|
| | 257 | |
|---|
| | 258 | //out bounds |
|---|
| | 259 | clearTestBounds(); |
|---|
| | 260 | tilesBounds = new OpenLayers.Bounds(10,10,120,120); |
|---|
| | 261 | layer.moveTo(null, zoomChanged, dragging); |
|---|
| | 262 | t.ok(g_Bounds == null, "if dragging and tile out of bounds, no init()"); |
|---|
| | 263 | |
|---|
| | 264 | //NOT DRAGGING |
|---|
| | 265 | dragging = false; |
|---|
| | 266 | |
|---|
| | 267 | //in bounds |
|---|
| | 268 | clearTestBounds(); |
|---|
| | 269 | tilesBounds = new OpenLayers.Bounds(-10,-10,110,110); |
|---|
| | 270 | layer.moveTo(null, zoomChanged, dragging); |
|---|
| | 271 | t.ok(g_Bounds == null, "if dragging and tile in bounds, no init()"); |
|---|
| | 272 | |
|---|
| | 273 | //out bounds |
|---|
| | 274 | clearTestBounds(); |
|---|
| | 275 | tilesBounds = new OpenLayers.Bounds(10,10,120,120); |
|---|
| | 276 | layer.moveTo(null, zoomChanged, dragging); |
|---|
| | 277 | t.ok(g_WhichFunc == "InitSingle", "if not dragging and tile out of bounds, we call initSingleTile()"); |
|---|
| | 278 | t.ok(g_Bounds.equals(b), "if not dragging and tile out of bounds, we call initSingleTile() with correct bounds"); |
|---|
| | 279 | |
|---|
| | 280 | |
|---|
| | 281 | //gridded |
|---|
| | 282 | layer.grid = [ [ {} ] ]; |
|---|
| | 283 | layer.singleTile = false; |
|---|
| | 284 | |
|---|
| | 285 | // drastic pan |
|---|
| | 286 | clearTestBounds(); |
|---|
| | 287 | tilesBounds = new OpenLayers.Bounds(-150,-150,-120,-120); |
|---|
| | 288 | layer.moveTo(null, zoomChanged); |
|---|
| | 289 | t.ok(g_WhichFunc == "InitGridded", "if tiles drastically out of bounds, we call initGriddedTile()"); |
|---|
| | 290 | t.ok(g_Bounds.equals(b), "if tiles drastically out of bounds, we call initGriddedTile() with correct bounds"); |
|---|
| | 291 | |
|---|
| | 292 | //regular move |
|---|
| | 293 | clearTestBounds(); |
|---|
| | 294 | tilesBounds = new OpenLayers.Bounds(10,10,120,120); |
|---|
| | 295 | layer.moveTo(null, zoomChanged); |
|---|
| | 296 | t.ok(g_WhichFunc == "MoveGridded", "if tiles not drastically out of bounds, we call moveGriddedTile()"); |
|---|
| | 297 | t.ok(g_Bounds.equals(b), "if tiles not drastically out of bounds, we call moveGriddedTile() with correct bounds"); |
|---|
| | 298 | } |
|---|