| | 475 | function test_Map_restrictedExtent(t) { |
|---|
| | 476 | t.plan(24); |
|---|
| | 477 | var extent = new OpenLayers.Bounds(-180, -90, 180, 90); |
|---|
| | 478 | var options = { |
|---|
| | 479 | maxResolution: "auto" |
|---|
| | 480 | }; |
|---|
| | 481 | var map = new OpenLayers.Map("map", options); |
|---|
| | 482 | var layer = new OpenLayers.Layer.WMS( |
|---|
| | 483 | "test", |
|---|
| | 484 | "http://octo.metacarta.com/cgi-bin/mapserv?", |
|---|
| | 485 | {map: "/mapdata/vmap_wms.map", layers: "basic"} |
|---|
| | 486 | ); |
|---|
| | 487 | map.addLayer(layer); |
|---|
| | 488 | map.zoomToMaxExtent(); |
|---|
| | 489 | var nw = new OpenLayers.LonLat(extent.left, extent.top); |
|---|
| | 490 | var ne = new OpenLayers.LonLat(extent.right, extent.top); |
|---|
| | 491 | var sw = new OpenLayers.LonLat(extent.left, extent.bottom); |
|---|
| | 492 | var se = new OpenLayers.LonLat(extent.right, extent.bottom); |
|---|
| | 493 | |
|---|
| | 494 | // try panning to northwest corner |
|---|
| | 495 | map.setOptions({restrictedExtent: extent}); |
|---|
| | 496 | map.setCenter(nw, 0); |
|---|
| | 497 | t.eq(map.getExtent().getCenterLonLat().toString(), |
|---|
| | 498 | extent.getCenterLonLat().toString(), |
|---|
| | 499 | "map extent properly restricted to northwest at zoom 0"); |
|---|
| | 500 | t.eq(map.zoom, 0, "zoom not restricted for nw, 0"); |
|---|
| | 501 | map.setCenter(nw, 5); |
|---|
| | 502 | t.eq(map.getExtent().top, extent.top, |
|---|
| | 503 | "map extent top properly restricted to northwest at zoom 5"); |
|---|
| | 504 | t.eq(map.getExtent().left, extent.left, |
|---|
| | 505 | "map extent left properly restricted to northwest at zoom 5"); |
|---|
| | 506 | t.eq(map.zoom, 5, "zoom not restricted for nw, 5"); |
|---|
| | 507 | map.setOptions({restrictedExtent: null}); |
|---|
| | 508 | map.setCenter(nw, 0); |
|---|
| | 509 | t.eq(map.getExtent().getCenterLonLat().toString(), |
|---|
| | 510 | nw.toString(), |
|---|
| | 511 | "map extent not restricted with null restrictedExtent for nw"); |
|---|
| | 512 | |
|---|
| | 513 | // try panning to northeast corner |
|---|
| | 514 | map.setOptions({restrictedExtent: extent}); |
|---|
| | 515 | map.setCenter(ne, 0); |
|---|
| | 516 | t.eq(map.getExtent().getCenterLonLat().toString(), |
|---|
| | 517 | extent.getCenterLonLat().toString(), |
|---|
| | 518 | "map extent properly restricted to northeast at zoom 0"); |
|---|
| | 519 | t.eq(map.zoom, 0, "zoom not restricted for ne, 0"); |
|---|
| | 520 | map.setCenter(ne, 5); |
|---|
| | 521 | t.eq(map.getExtent().top, extent.top, |
|---|
| | 522 | "map extent top properly restricted to northeast at zoom 5"); |
|---|
| | 523 | t.eq(map.getExtent().right, extent.right, |
|---|
| | 524 | "map extent right properly restricted to northeast at zoom 5"); |
|---|
| | 525 | t.eq(map.zoom, 5, "zoom not restricted for ne, 5"); |
|---|
| | 526 | map.setOptions({restrictedExtent: null}); |
|---|
| | 527 | map.setCenter(ne, 0); |
|---|
| | 528 | t.eq(map.getExtent().getCenterLonLat().toString(), |
|---|
| | 529 | ne.toString(), |
|---|
| | 530 | "map extent not restricted with null restrictedExtent for ne"); |
|---|
| | 531 | |
|---|
| | 532 | // try panning to southwest corner |
|---|
| | 533 | map.setOptions({restrictedExtent: extent}); |
|---|
| | 534 | map.setCenter(sw, 0); |
|---|
| | 535 | t.eq(map.getExtent().getCenterLonLat().toString(), |
|---|
| | 536 | extent.getCenterLonLat().toString(), |
|---|
| | 537 | "map extent properly restricted to southwest at zoom 0"); |
|---|
| | 538 | t.eq(map.zoom, 0, "zoom not restricted for sw, 0"); |
|---|
| | 539 | map.setCenter(sw, 5); |
|---|
| | 540 | t.eq(map.getExtent().bottom, extent.bottom, |
|---|
| | 541 | "map extent bottom properly restricted to southwest at zoom 5"); |
|---|
| | 542 | t.eq(map.getExtent().left, extent.left, |
|---|
| | 543 | "map extent left properly restricted to southwest at zoom 5"); |
|---|
| | 544 | t.eq(map.zoom, 5, "zoom not restricted for sw, 5"); |
|---|
| | 545 | map.setOptions({restrictedExtent: null}); |
|---|
| | 546 | map.setCenter(sw, 0); |
|---|
| | 547 | t.eq(map.getExtent().getCenterLonLat().toString(), |
|---|
| | 548 | sw.toString(), |
|---|
| | 549 | "map extent not restricted with null restrictedExtent for sw"); |
|---|
| | 550 | |
|---|
| | 551 | // try panning to southeast corner |
|---|
| | 552 | map.setOptions({restrictedExtent: extent}); |
|---|
| | 553 | map.setCenter(se, 0); |
|---|
| | 554 | t.eq(map.getExtent().getCenterLonLat().toString(), |
|---|
| | 555 | extent.getCenterLonLat().toString(), |
|---|
| | 556 | "map extent properly restricted to southeast at zoom 0"); |
|---|
| | 557 | t.eq(map.zoom, 0, "zoom not restricted for se, 0"); |
|---|
| | 558 | map.setCenter(se, 5); |
|---|
| | 559 | t.eq(map.getExtent().bottom, extent.bottom, |
|---|
| | 560 | "map extent bottom properly restricted to southeast at zoom 5"); |
|---|
| | 561 | t.eq(map.getExtent().right, extent.right, |
|---|
| | 562 | "map extent right properly restricted to southeast at zoom 5"); |
|---|
| | 563 | t.eq(map.zoom, 5, "zoom not restricted for se, 5"); |
|---|
| | 564 | map.setOptions({restrictedExtent: null}); |
|---|
| | 565 | map.setCenter(se, 0); |
|---|
| | 566 | t.eq(map.getExtent().getCenterLonLat().toString(), |
|---|
| | 567 | se.toString(), |
|---|
| | 568 | "map extent not restricted with null restrictedExtent for se"); |
|---|
| | 569 | } |
|---|
| | 570 | |
|---|