| 1 |
<html> |
|---|
| 2 |
<head> |
|---|
| 3 |
<script src="../../lib/OpenLayers.js"></script> |
|---|
| 4 |
<script type="text/javascript"> |
|---|
| 5 |
var layer; |
|---|
| 6 |
|
|---|
| 7 |
function test_Layer_Image_constructor (t) { |
|---|
| 8 |
t.plan( 13 ); |
|---|
| 9 |
|
|---|
| 10 |
var options = { chicken: 151, foo: "bar", projection: "none" }; |
|---|
| 11 |
var layer = new OpenLayers.Layer.Image('Test Layer', |
|---|
| 12 |
'http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif', |
|---|
| 13 |
new OpenLayers.Bounds(-180, -88.759, 180, 88.759), |
|---|
| 14 |
new OpenLayers.Size(580, 288), options); |
|---|
| 15 |
|
|---|
| 16 |
t.ok( layer instanceof OpenLayers.Layer.Image, "new OpenLayers.Layer.Image returns object" ); |
|---|
| 17 |
t.eq( layer.CLASS_NAME, "OpenLayers.Layer.Image", "CLASS_NAME variable set correctly"); |
|---|
| 18 |
|
|---|
| 19 |
t.eq( layer.name, "Test Layer", "layer.name is correct" ); |
|---|
| 20 |
t.ok( layer.id != null, "Layer is given an id"); |
|---|
| 21 |
t.eq( layer.projection, "none", "default layer projection correctly set"); |
|---|
| 22 |
t.ok( ((layer.chicken == 151) && (layer.foo == "bar")), "layer.options correctly set to Layer Object" ); |
|---|
| 23 |
t.ok( ((layer.options["chicken"] == 151) && (layer.options["foo"] == "bar")), "layer.options correctly backed up" ); |
|---|
| 24 |
|
|---|
| 25 |
options.chicken = 552; |
|---|
| 26 |
|
|---|
| 27 |
t.eq( layer.options["chicken"], 151 , "layer.options correctly made fresh copy" ); |
|---|
| 28 |
|
|---|
| 29 |
t.eq( layer.isBaseLayer, true, "Default img layer is base layer" ); |
|---|
| 30 |
|
|---|
| 31 |
layer = new OpenLayers.Layer.Image('Test Layer', |
|---|
| 32 |
'http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif', |
|---|
| 33 |
new OpenLayers.Bounds(-180, -88.759, 180, 88.759), |
|---|
| 34 |
new OpenLayers.Size(580, 288)); |
|---|
| 35 |
t.ok( layer instanceof OpenLayers.Layer.Image, "new OpenLayers.Layer.Image returns object" ); |
|---|
| 36 |
t.eq( layer.name, "Test Layer", "layer.name is correct" ); |
|---|
| 37 |
t.ok( layer.projection == null, "default layer projection correctly set"); |
|---|
| 38 |
t.ok( layer.options instanceof Object, "layer.options correctly initialized as a non-null Object" ); |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
function test_maxExtent(t) { |
|---|
| 42 |
t.plan(2); |
|---|
| 43 |
var layer; |
|---|
| 44 |
|
|---|
| 45 |
// test that the image extent is set as the default maxExtent |
|---|
| 46 |
var extent = new OpenLayers.Bounds(1, 2, 3, 4); |
|---|
| 47 |
var size = new OpenLayers.Size(2, 2); |
|---|
| 48 |
layer = new OpenLayers.Layer.Image("Test", "foo", extent, size); |
|---|
| 49 |
t.eq(layer.maxExtent.toString(), extent.toString(), "extent set as default maxExtent"); |
|---|
| 50 |
|
|---|
| 51 |
// test that the maxExtent can be set explicitly |
|---|
| 52 |
var maxExtent = new OpenLayers.Bounds(10, 20, 30, 40); |
|---|
| 53 |
layer = new OpenLayers.Layer.Image("Test", "foo", extent, size, {maxExtent: maxExtent}); |
|---|
| 54 |
t.eq(layer.maxExtent.toString(), maxExtent.toString(), "maxExtent can be set explicitly"); |
|---|
| 55 |
|
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
function test_Layer_Image_tileTests (t) { |
|---|
| 59 |
t.plan(7); |
|---|
| 60 |
var map = new OpenLayers.Map('map'); |
|---|
| 61 |
|
|---|
| 62 |
layer = new OpenLayers.Layer.Image('Test Layer', |
|---|
| 63 |
'http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif', |
|---|
| 64 |
new OpenLayers.Bounds(-180, -88.759, 180, 88.759), |
|---|
| 65 |
new OpenLayers.Size(580, 288)); |
|---|
| 66 |
|
|---|
| 67 |
map.addLayer(layer); |
|---|
| 68 |
map.zoomToMaxExtent(); |
|---|
| 69 |
|
|---|
| 70 |
// no resolution info was sent, so maxResolution should be calculated |
|---|
| 71 |
// by aspectRatio*extent/size (this is the pixel aspect ratio) |
|---|
| 72 |
var aspectRatio = (layer.extent.getHeight() / layer.size.h) / |
|---|
| 73 |
(layer.extent.getWidth() / layer.size.w); |
|---|
| 74 |
t.eq(aspectRatio, layer.aspectRatio, "aspectRatio is properly set"); |
|---|
| 75 |
var maxExtent = aspectRatio * layer.extent.getWidth() / layer.size.w; |
|---|
| 76 |
t.eq(maxExtent, layer.maxResolution, "maxResolution is properly set"); |
|---|
| 77 |
|
|---|
| 78 |
t.eq(layer.tile.position.x,-42, "Tile x positioned correctly at maxextent"); |
|---|
| 79 |
t.eq(layer.tile.position.y,106, "Tile y positioned correctly at maxextent"); |
|---|
| 80 |
t.eq(layer.tile.imgDiv.src, "http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif", "URL is correct"); |
|---|
| 81 |
map.zoomIn(); |
|---|
| 82 |
t.eq(layer.tile.imgDiv.src, "http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif", "URL is correct"); |
|---|
| 83 |
layer.setUrl('http://labs.metacarta.com/wms/vmap0?LAYERS=basic&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&FORMAT=image%2Fjpeg&SRS=EPSG%3A4326&BBOX=-180,-90,0,90&WIDTH=256&HEIGHT=256'); |
|---|
| 84 |
t.eq(layer.tile.imgDiv.src, "http://labs.metacarta.com/wms/vmap0?LAYERS=basic&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&FORMAT=image%2Fjpeg&SRS=EPSG%3A4326&BBOX=-180,-90,0,90&WIDTH=256&HEIGHT=256", "URL is correct after setURL"); |
|---|
| 85 |
} |
|---|
| 86 |
/****** |
|---|
| 87 |
* |
|---|
| 88 |
* |
|---|
| 89 |
* HERE IS WHERE SOME TESTS SHOULD BE PUT TO CHECK ON THE LONLAT-PX TRANSLATION |
|---|
| 90 |
* FUNCTIONS AND RESOLUTION AND GETEXTENT GETZOOMLEVEL, ETC |
|---|
| 91 |
* |
|---|
| 92 |
* |
|---|
| 93 |
*/ |
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
function test_Layer_Image_destroy_before_use (t) { |
|---|
| 97 |
t.plan(1); |
|---|
| 98 |
var map = new OpenLayers.Map('map'); |
|---|
| 99 |
layer = new OpenLayers.Layer.Image('Test', 'http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif', new OpenLayers.Bounds(-180, -88.759, 180, 88.759), new OpenLayers.Size(580, 288)); |
|---|
| 100 |
map.addLayer(layer); |
|---|
| 101 |
map.removeLayer(layer); |
|---|
| 102 |
layer.destroy(); |
|---|
| 103 |
t.ok(true, "destroy() didn't throw an error"); |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
function test_Layer_Image_destroy (t) { |
|---|
| 107 |
t.plan( 4 ); |
|---|
| 108 |
|
|---|
| 109 |
var map = new OpenLayers.Map('map'); |
|---|
| 110 |
|
|---|
| 111 |
layer = new OpenLayers.Layer.Image('Test Layer', |
|---|
| 112 |
'http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif', |
|---|
| 113 |
new OpenLayers.Bounds(-180, -88.759, 180, 88.759), |
|---|
| 114 |
new OpenLayers.Size(580, 288)); |
|---|
| 115 |
|
|---|
| 116 |
map.addLayer(layer); |
|---|
| 117 |
map.zoomToMaxExtent(); |
|---|
| 118 |
|
|---|
| 119 |
layer.destroy(); |
|---|
| 120 |
|
|---|
| 121 |
t.eq( layer.name, null, "layer.name is null after destroy" ); |
|---|
| 122 |
t.eq( layer.div, null, "layer.div is null after destroy" ); |
|---|
| 123 |
t.eq( layer.map, null, "layer.map is null after destroy" ); |
|---|
| 124 |
t.eq( layer.options, null, "layer.options is null after destroy" ); |
|---|
| 125 |
|
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
</script> |
|---|
| 129 |
</head> |
|---|
| 130 |
<body> |
|---|
| 131 |
<div id="map" style="width:500px;height:500px"></div> |
|---|
| 132 |
<div id="map2" style="width:100px;height:100px"></div> |
|---|
| 133 |
</body> |
|---|
| 134 |
</html> |
|---|