| | 1 | <html> |
|---|
| | 2 | <head> |
|---|
| | 3 | <script src="../../lib/OpenLayers.js"></script> |
|---|
| | 4 | <script type="text/javascript"><!-- |
|---|
| | 5 | var isMozilla = (navigator.userAgent.indexOf("compatible") == -1); |
|---|
| | 6 | var layer; |
|---|
| | 7 | |
|---|
| | 8 | var name = 'Test Layer'; |
|---|
| | 9 | var url = "http://octo.metacarta.com/cgi-bin/mapserv"; |
|---|
| | 10 | var params = { map: '/mapdata/vmap_wms.map', |
|---|
| | 11 | layers: 'basic', |
|---|
| | 12 | format: 'image/png'}; |
|---|
| | 13 | |
|---|
| | 14 | |
|---|
| | 15 | function test_Layer_WrapDateLine_adjustBounds(t) { |
|---|
| | 16 | t.plan(10); |
|---|
| | 17 | var map = new OpenLayers.Map('map'); |
|---|
| | 18 | layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true}); |
|---|
| | 19 | map.addLayer(layer); |
|---|
| | 20 | map.zoomToMaxExtent(); |
|---|
| | 21 | var bounds = layer.adjustBounds(new OpenLayers.Bounds(-270,-90,-180,0)); |
|---|
| | 22 | t.ok( bounds.equals(new OpenLayers.Bounds(90,-90,180,0)), "-270,-90,-180,0 wraps to 90,-90,180,0"); |
|---|
| | 23 | bounds = layer.adjustBounds(new OpenLayers.Bounds(180,-90,270,0)); |
|---|
| | 24 | t.ok( bounds.equals(new OpenLayers.Bounds(-180,-90,-90,0)), "180,-90,270,0 wraps to -180,-90,-90,0"); |
|---|
| | 25 | bounds = layer.adjustBounds(new OpenLayers.Bounds(-180,-90,0,0)); |
|---|
| | 26 | t.ok( bounds.equals(new OpenLayers.Bounds(-180,-90,0,0)), "-180,-90,0,0 doesn't wrap"); |
|---|
| | 27 | bounds = layer.adjustBounds(new OpenLayers.Bounds(-181,-90,-179,0)); |
|---|
| | 28 | t.ok( bounds.equals(new OpenLayers.Bounds(-181,-90,-179,0)), "-181,-90,-179,0 doesn't wrap, because it straddles the dateline"); |
|---|
| | 29 | bounds = layer.adjustBounds(new OpenLayers.Bounds(-180,-180,-90,-90)); |
|---|
| | 30 | t.ok( bounds.equals(new OpenLayers.Bounds(-180,-180,-90,-90)), "-180,-180,-90,-90 doesn't wrap, because we don't wrap lats."); |
|---|
| | 31 | layer = new OpenLayers.Layer.WMS(name, url, params); |
|---|
| | 32 | map.addLayer(layer); |
|---|
| | 33 | var testBounds = null; |
|---|
| | 34 | var outBounds = null; |
|---|
| | 35 | var testList = [ |
|---|
| | 36 | new OpenLayers.Bounds(-270,-90,-180,0), |
|---|
| | 37 | new OpenLayers.Bounds(180,-90,270,0), |
|---|
| | 38 | new OpenLayers.Bounds(-180,-90,0,0), |
|---|
| | 39 | new OpenLayers.Bounds(-181,-90,-179,0), |
|---|
| | 40 | new OpenLayers.Bounds(-180,-180,-90,-90), |
|---|
| | 41 | ]; |
|---|
| | 42 | for (var i = 0; i < testList.length; i++) { |
|---|
| | 43 | outBounds = layer.adjustBounds(testList[i]); |
|---|
| | 44 | t.ok( outBounds.equals(testList[i]), testList[i]+" doesn't wrap in non-wrapping layer."); |
|---|
| | 45 | } |
|---|
| | 46 | } |
|---|
| | 47 | function test_Layer_WrapDateLine_getLonLat(t) { |
|---|
| | 48 | t.plan(12); |
|---|
| | 49 | var map = new OpenLayers.Map('map'); |
|---|
| | 50 | layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true}); |
|---|
| | 51 | map.addLayer(layer); |
|---|
| | 52 | map.zoomToMaxExtent(); |
|---|
| | 53 | var testLonLats = [ |
|---|
| | 54 | new OpenLayers.LonLat(-185,5), |
|---|
| | 55 | new OpenLayers.LonLat(-180,-95), |
|---|
| | 56 | new OpenLayers.LonLat(-180,95), |
|---|
| | 57 | new OpenLayers.LonLat(180,-95), |
|---|
| | 58 | new OpenLayers.LonLat(180,95), |
|---|
| | 59 | new OpenLayers.LonLat(185,5) |
|---|
| | 60 | ]; |
|---|
| | 61 | var outLonLats = [ |
|---|
| | 62 | new OpenLayers.LonLat(175,5), |
|---|
| | 63 | new OpenLayers.LonLat(-180,-95), |
|---|
| | 64 | new OpenLayers.LonLat(-180,95), |
|---|
| | 65 | new OpenLayers.LonLat(180,-95), |
|---|
| | 66 | new OpenLayers.LonLat(180,95), |
|---|
| | 67 | new OpenLayers.LonLat(-175,5) |
|---|
| | 68 | ]; |
|---|
| | 69 | |
|---|
| | 70 | for (var i = 0; i < testLonLats.length; i++) { |
|---|
| | 71 | var pixel = layer.getViewPortPxFromLonLat(testLonLats[i]); |
|---|
| | 72 | var lonlat = layer.getLonLatFromViewPortPx(pixel); |
|---|
| | 73 | lonlat.lon = Math.round(lonlat.lon); |
|---|
| | 74 | lonlat.lat = Math.round(lonlat.lat); |
|---|
| | 75 | t.ok(outLonLats[i].equals(lonlat), testLonLats[i] + " wraps to " + outLonLats[i]+ " (what happened: " + lonlat + ")"); |
|---|
| | 76 | } |
|---|
| | 77 | |
|---|
| | 78 | layer = new OpenLayers.Layer.WMS(name, url, params); |
|---|
| | 79 | map.addLayer(layer); |
|---|
| | 80 | var outLonLats = [ |
|---|
| | 81 | new OpenLayers.LonLat(-185,5), |
|---|
| | 82 | new OpenLayers.LonLat(-180,-95), |
|---|
| | 83 | new OpenLayers.LonLat(-180,95), |
|---|
| | 84 | new OpenLayers.LonLat(180,-95), |
|---|
| | 85 | new OpenLayers.LonLat(180,95), |
|---|
| | 86 | new OpenLayers.LonLat(185,5) |
|---|
| | 87 | ]; |
|---|
| | 88 | for (var i = 0; i < testLonLats.length; i++) { |
|---|
| | 89 | var pixel = layer.getViewPortPxFromLonLat(testLonLats[i]); |
|---|
| | 90 | var lonlat = layer.getLonLatFromViewPortPx(pixel); |
|---|
| | 91 | lonlat.lon = Math.round(lonlat.lon); |
|---|
| | 92 | lonlat.lat = Math.round(lonlat.lat); |
|---|
| | 93 | t.ok(outLonLats[i].equals(lonlat), testLonLats[i] + " wraps to " + outLonLats[i]+ " (what happened: " + lonlat + ")"); |
|---|
| | 94 | } |
|---|
| | 95 | |
|---|
| | 96 | } |
|---|
| | 97 | function test_Layer_WrapDateLine_ZoomToExtent (t) { |
|---|
| | 98 | t.plan( 4 ); |
|---|
| | 99 | |
|---|
| | 100 | var url = "http://octo.metacarta.com/cgi-bin/mapserv"; |
|---|
| | 101 | layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true}); |
|---|
| | 102 | var m = new OpenLayers.Map('map'); |
|---|
| | 103 | m.addLayer(layer); |
|---|
| | 104 | m.setCenter = function(myCenter) { this.center = myCenter; } |
|---|
| | 105 | var testBounds = [ |
|---|
| | 106 | new OpenLayers.Bounds(-185,-90,-175,-85), |
|---|
| | 107 | new OpenLayers.Bounds(0,-90,-170,-85), |
|---|
| | 108 | new OpenLayers.Bounds(-270,-90,-180,-85), |
|---|
| | 109 | new OpenLayers.Bounds(0,0,45,45) |
|---|
| | 110 | ]; |
|---|
| | 111 | var outCenters = [ |
|---|
| | 112 | new OpenLayers.LonLat(-180,-87.5), |
|---|
| | 113 | new OpenLayers.LonLat(95,-87.5), |
|---|
| | 114 | new OpenLayers.LonLat(135,-87.5), |
|---|
| | 115 | new OpenLayers.LonLat(22.5,22.5) |
|---|
| | 116 | ]; |
|---|
| | 117 | for (var i = 0; i < testBounds.length; i++) { |
|---|
| | 118 | m.zoomToExtent(testBounds[i]); |
|---|
| | 119 | t.ok(m.center.equals(outCenters[i]), "Map center from bounds " + testBounds[i] + " should be " + outCenters[i] + ", got " + m.center); |
|---|
| | 120 | } |
|---|
| | 121 | |
|---|
| | 122 | |
|---|
| | 123 | } |
|---|
| | 124 | function test_Layer_WrapDateLine_WMS (t) { |
|---|
| | 125 | t.plan( 3 ); |
|---|
| | 126 | |
|---|
| | 127 | var url = "http://octo.metacarta.com/cgi-bin/mapserv"; |
|---|
| | 128 | layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true}); |
|---|
| | 129 | var m = new OpenLayers.Map('map'); |
|---|
| | 130 | m.addLayer(layer); |
|---|
| | 131 | m.zoomToMaxExtent(); |
|---|
| | 132 | t.eq(layer.grid[3][0].url, "http://octo.metacarta.com/cgi-bin/mapserv?MAP=%2Fmapdata%2Fvmap_wms.map&LAYERS=basic&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=0%2C-90%2C180%2C90&WIDTH=256&HEIGHT=256", "cell [3][0] is wrapped around the world."); |
|---|
| | 133 | t.eq(layer.grid[0][0].url, "http://octo.metacarta.com/cgi-bin/mapserv?MAP=%2Fmapdata%2Fvmap_wms.map&LAYERS=basic&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=0%2C450%2C180%2C630&WIDTH=256&HEIGHT=256", "cell [0][0] is wrapped around the world lon, but not lat"); |
|---|
| | 134 | t.eq(layer.grid[0][3].url, "http://octo.metacarta.com/cgi-bin/mapserv?MAP=%2Fmapdata%2Fvmap_wms.map&LAYERS=basic&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=-180%2C450%2C0%2C630&WIDTH=256&HEIGHT=256", "cell [3][0] is not wrapped at all."); |
|---|
| | 135 | |
|---|
| | 136 | } |
|---|
| | 137 | function test_Layer_WrapDateLine_KaMap (t) { |
|---|
| | 138 | t.plan( 3 ); |
|---|
| | 139 | |
|---|
| | 140 | var layer = new OpenLayers.Layer.KaMap( "Blue Marble NG", |
|---|
| | 141 | "http://www.openlayers.org/world/index.php", |
|---|
| | 142 | {g: "satellite", map: "world"}, |
|---|
| | 143 | {wrapDateLine: true} ); |
|---|
| | 144 | var m = new OpenLayers.Map('map'); |
|---|
| | 145 | m.addLayer(layer); |
|---|
| | 146 | m.zoomToMaxExtent(); |
|---|
| | 147 | t.eq(layer.grid[0][0].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=-768&l=0&s=221471921.25", "grid[0][0] kamap is okay"); |
|---|
| | 148 | t.eq(layer.grid[0][3].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=-768&l=-256&s=221471921.25", "grid[0][3] kamap is okay"); |
|---|
| | 149 | t.eq(layer.grid[3][0].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=0&l=0&s=221471921.25", "grid[3][0] is okay"); |
|---|
| | 150 | } |
|---|
| | 151 | function test_Layer_WrapDateLine_WMS_Overlay (t) { |
|---|
| | 152 | t.plan( 3 ); |
|---|
| | 153 | var url = "http://octo.metacarta.com/cgi-bin/mapserv"; |
|---|
| | 154 | baselayer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true}); |
|---|
| | 155 | var layer = new OpenLayers.Layer.WMS( "DM Solutions Demo", |
|---|
| | 156 | "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap", |
|---|
| | 157 | {layers: "bathymetry,land_fn,park,drain_fn,drainage," + |
|---|
| | 158 | "prov_bound,fedlimit,rail,road,popplace", |
|---|
| | 159 | transparent: "true", format: "image/png"}, |
|---|
| | 160 | {wrapDateLine: true, reproject: false}); |
|---|
| | 161 | var m = new OpenLayers.Map('map'); |
|---|
| | 162 | m.addLayers([baselayer,layer]); |
|---|
| | 163 | m.zoomToMaxExtent(); |
|---|
| | 164 | t.eq(layer.grid[0][0].url, "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap?LAYERS=bathymetry%2Cland_fn%2Cpark%2Cdrain_fn%2Cdrainage%2Cprov_bound%2Cfedlimit%2Crail%2Croad%2Cpopplace&TRANSPARENT=true&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=0%2C450%2C180%2C630&WIDTH=256&HEIGHT=256", "grid[0][0] wms overlay is okay"); |
|---|
| | 165 | t.eq(layer.grid[0][3].url, "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap?LAYERS=bathymetry%2Cland_fn%2Cpark%2Cdrain_fn%2Cdrainage%2Cprov_bound%2Cfedlimit%2Crail%2Croad%2Cpopplace&TRANSPARENT=true&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=-180%2C450%2C0%2C630&WIDTH=256&HEIGHT=256", "grid[0][3] wms overlay is okay"); |
|---|
| | 166 | t.eq(layer.grid[3][0].url, "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap?LAYERS=bathymetry%2Cland_fn%2Cpark%2Cdrain_fn%2Cdrainage%2Cprov_bound%2Cfedlimit%2Crail%2Croad%2Cpopplace&TRANSPARENT=true&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&EXCEPTIONS=application%2Fvnd.ogc.se_inimage&SRS=EPSG%3A4326&BBOX=0%2C-90%2C180%2C90&WIDTH=256&HEIGHT=256", "grid[3][0] wms overlay okay"); |
|---|
| | 167 | } |
|---|
| | 168 | // --> |
|---|
| | 169 | </script> |
|---|
| | 170 | </head> |
|---|
| | 171 | <body> |
|---|
| | 172 | <div id="map" style="width:1000px;height:550px"></div> |
|---|
| | 173 | </body> |
|---|
| | 174 | </html> |