| | 402 | var gotControl = map1.getControl(control.id); |
|---|
| | 403 | t.ok(gotControl == control, "got right control"); |
|---|
| | 404 | |
|---|
| | 405 | gotControl = map1.getControl("bogus id"); |
|---|
| | 406 | t.ok(gotControl == null, "getControl() for bad id returns null"); |
|---|
| | 407 | } |
|---|
| | 408 | |
|---|
| | 409 | function test_19_Map_removeControl(t) { |
|---|
| | 410 | t.plan(6); |
|---|
| | 411 | |
|---|
| | 412 | var oldNumControls, newNumControls; |
|---|
| | 413 | |
|---|
| | 414 | var map1 = new OpenLayers.Map('map'); |
|---|
| | 415 | oldNumControls = map1.controls.length; |
|---|
| | 416 | |
|---|
| | 417 | var control = new OpenLayers.Control(); |
|---|
| | 418 | map1.addControl(control); |
|---|
| | 419 | |
|---|
| | 420 | //add control |
|---|
| | 421 | newNumControls = map1.controls.length; |
|---|
| | 422 | t.ok( newNumControls = oldNumControls + 1, "adding a control increases control count") |
|---|
| | 423 | |
|---|
| | 424 | var foundDiv = false; |
|---|
| | 425 | for(var i=0; i < map1.viewPortDiv.childNodes.length; i++) { |
|---|
| | 426 | var childNode = map1.viewPortDiv.childNodes[i]; |
|---|
| | 427 | if (childNode == control.div) { |
|---|
| | 428 | foundDiv = true; |
|---|
| | 429 | } |
|---|
| | 430 | } |
|---|
| | 431 | t.ok(foundDiv, "new control's div correctly added to viewPort"); |
|---|
| | 432 | |
|---|
| | 433 | //remove control |
|---|
| | 434 | map1.removeControl(control.id) |
|---|
| | 435 | newNumControls = map1.controls.length; |
|---|
| | 436 | t.ok( newNumControls == oldNumControls, "removing the control decreases control count") |
|---|
| | 437 | |
|---|
| | 438 | var gotControl = map1.getControl(control.id); |
|---|
| | 439 | t.ok( gotControl == null, "control no longer in map's controls array"); |
|---|
| | 440 | |
|---|
| | 441 | var foundDiv = false; |
|---|
| | 442 | for(var i=0; i < map1.viewPortDiv.childNodes.length; i++) { |
|---|
| | 443 | var childNode = map1.viewPortDiv.childNodes[i]; |
|---|
| | 444 | if (childNode == control.div) { |
|---|
| | 445 | foundDiv = true; |
|---|
| | 446 | } |
|---|
| | 447 | } |
|---|
| | 448 | t.ok(!foundDiv, "control no longer child of viewPort"); |
|---|
| | 449 | |
|---|
| | 450 | //remove bogus |
|---|
| | 451 | map1.removeControl("bogus id"); |
|---|
| | 452 | newNumControls = map1.controls.length; |
|---|
| | 453 | t.ok( newNumControls == oldNumControls, "removing bad controlid doesnt crash or decrease control count") |
|---|
| | 454 | } |
|---|
| | 455 | |
|---|