3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
5 var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
8 var name = 'Test Layer';
9 var url = "http://octo.metacarta.com/cgi-bin/mapserv";
10 var params = { map: '/mapdata/vmap_wms.map',
15 function test_Layer_WrapDateLine_adjustBounds(t) {
19 var map = new OpenLayers.Map('map');
20 layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true});
22 map.zoomToMaxExtent();
23 var bounds = layer.adjustBounds(new OpenLayers.Bounds(-270,-90,-180,0));
24 t.ok( bounds.equals(new OpenLayers.Bounds(90,-90,180,0)), "-270,-90,-180,0 wraps to 90,-90,180,0");
25 bounds = layer.adjustBounds(new OpenLayers.Bounds(180,-90,270,0));
26 t.ok( bounds.equals(new OpenLayers.Bounds(-180,-90,-90,0)), "180,-90,270,0 wraps to -180,-90,-90,0");
27 bounds = layer.adjustBounds(new OpenLayers.Bounds(-180,-90,0,0));
28 t.ok( bounds.equals(new OpenLayers.Bounds(-180,-90,0,0)), "-180,-90,0,0 doesn't wrap");
29 bounds = layer.adjustBounds(new OpenLayers.Bounds(-181,-90,-179,0));
30 t.ok( bounds.equals(new OpenLayers.Bounds(-181,-90,-179,0)), "-181,-90,-179,0 doesn't wrap, because it straddles the dateline");
31 bounds = layer.adjustBounds(new OpenLayers.Bounds(-180,-180,-90,-90));
32 t.ok( bounds.equals(new OpenLayers.Bounds(-180,-180,-90,-90)), "-180,-180,-90,-90 doesn't wrap, because we don't wrap lats.");
33 layer = new OpenLayers.Layer.WMS(name, url, params);
35 var testBounds = null;
38 new OpenLayers.Bounds(-270,-90,-180,0),
39 new OpenLayers.Bounds(180,-90,270,0),
40 new OpenLayers.Bounds(-180,-90,0,0),
41 new OpenLayers.Bounds(-181,-90,-179,0),
42 new OpenLayers.Bounds(-180,-180,-90,-90)
44 for (var i = 0; i < testList.length; i++) {
45 outBounds = layer.adjustBounds(testList[i]);
46 t.ok( outBounds.equals(testList[i]), testList[i]+" doesn't wrap in non-wrapping layer.");
50 function test_Layer_WrapDateLine_getLonLat(t) {
52 var map = new OpenLayers.Map('map');
53 layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true});
55 map.zoomToMaxExtent();
57 new OpenLayers.LonLat(-185,5),
58 new OpenLayers.LonLat(-180,-95),
59 new OpenLayers.LonLat(-180,95),
60 new OpenLayers.LonLat(180,-95),
61 new OpenLayers.LonLat(180,95),
62 new OpenLayers.LonLat(185,5)
65 new OpenLayers.LonLat(175,5),
66 new OpenLayers.LonLat(-180,-95),
67 new OpenLayers.LonLat(-180,95),
68 new OpenLayers.LonLat(180,-95),
69 new OpenLayers.LonLat(180,95),
70 new OpenLayers.LonLat(-175,5)
73 for (var i = 0; i < testLonLats.length; i++) {
74 var pixel = layer.getViewPortPxFromLonLat(testLonLats[i]);
75 var lonlat = layer.getLonLatFromViewPortPx(pixel);
76 lonlat.lon = Math.round(lonlat.lon);
77 lonlat.lat = Math.round(lonlat.lat);
78 t.ok(outLonLats[i].equals(lonlat), testLonLats[i] + " wraps to " + outLonLats[i]+ " (what happened: " + lonlat + ")");
81 layer = new OpenLayers.Layer.WMS(name, url, params);
84 new OpenLayers.LonLat(-185,5),
85 new OpenLayers.LonLat(-180,-95),
86 new OpenLayers.LonLat(-180,95),
87 new OpenLayers.LonLat(180,-95),
88 new OpenLayers.LonLat(180,95),
89 new OpenLayers.LonLat(185,5)
91 for (var i = 0; i < testLonLats.length; i++) {
92 var pixel = layer.getViewPortPxFromLonLat(testLonLats[i]);
93 var lonlat = layer.getLonLatFromViewPortPx(pixel);
94 lonlat.lon = Math.round(lonlat.lon);
95 lonlat.lat = Math.round(lonlat.lat);
96 t.ok(outLonLats[i].equals(lonlat), testLonLats[i] + " wraps to " + outLonLats[i]+ " (what happened: " + lonlat + ")");
101 function test_Layer_WrapDateLine_ZoomToExtent (t) {
104 var url = "http://octo.metacarta.com/cgi-bin/mapserv";
105 layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true});
106 var m = new OpenLayers.Map('map');
108 m.setCenter = function(myCenter) { this.center = myCenter; }
110 new OpenLayers.Bounds(-185,-90,-175,-85),
111 new OpenLayers.Bounds(0,-90,-170,-85),
112 new OpenLayers.Bounds(-270,-90,-180,-85),
113 new OpenLayers.Bounds(0,0,45,45)
116 new OpenLayers.LonLat(-180,-87.5),
117 new OpenLayers.LonLat(95,-87.5),
118 new OpenLayers.LonLat(135,-87.5),
119 new OpenLayers.LonLat(22.5,22.5)
121 for (var i = 0; i < testBounds.length; i++) {
122 m.zoomToExtent(testBounds[i]);
123 t.ok(m.center.equals(outCenters[i]), "Map center from bounds " + testBounds[i] + " should be " + outCenters[i] + ", got " + m.center);
129 function test_Layer_WrapDateLine_WMS (t) {
132 var url = "http://octo.metacarta.com/cgi-bin/mapserv";
133 layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true,encodeBBOX:true});
134 var m = new OpenLayers.Map('map');
137 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.");
138 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");
139 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.");
143 function test_Layer_WrapDateLine_KaMap (t) {
146 var layer = new OpenLayers.Layer.KaMap( "Blue Marble NG",
147 "http://www.openlayers.org/world/index.php",
148 {g: "satellite", map: "world"},
149 {wrapDateLine: true} );
150 var m = new OpenLayers.Map('map');
153 t.eq(layer.grid[0][0].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=-1280&l=0&s=221471921.25", "grid[0][0] kamap is okay");
154 t.eq(layer.grid[0][3].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=-1280&l=-256&s=221471921.25", "grid[0][3] kamap is okay");
155 t.eq(layer.grid[3][0].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=-512&l=0&s=221471921.25", "grid[3][0] is okay");
158 function test_Layer_WrapDateLine_WMS_Overlay (t) {
160 var url = "http://octo.metacarta.com/cgi-bin/mapserv";
161 baselayer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true});
162 var layer = new OpenLayers.Layer.WMS( "DM Solutions Demo",
163 "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap",
164 {layers: "bathymetry,land_fn,park,drain_fn,drainage," +
165 "prov_bound,fedlimit,rail,road,popplace",
166 transparent: "true", format: "image/png"},
167 {wrapDateLine: true, reproject: false,encodeBBOX:true});
168 var m = new OpenLayers.Map('map');
169 m.addLayers([baselayer,layer]);
171 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");
172 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");
173 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");
180 <div id="map" style="width:1000px;height:550px"></div>