summaryrefslogtreecommitdiff
path: root/misc/openlayers/tests/Layer/WrapDateLine.html
blob: efe89030a683145e2646f7b429271272fc630679 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<html>
<head>
<script src="../OLLoader.js"></script>
  <script type="text/javascript">
    // turn off animation frame handling, so we can check img urls in tests
    delete OpenLayers.Layer.Grid.prototype.queueTileDraw;

    var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
    var layer; 

    var name = 'Test Layer';
    var url = "http://octo.metacarta.com/cgi-bin/mapserv";
    var params = { map: '/mapdata/vmap_wms.map', 
                   layers: 'basic', 
                   format: 'image/png'};

    
    function test_Layer_WrapDateLine_adjustBounds(t) {
        t.plan(10);
        
        
        var map = new OpenLayers.Map('map');
        layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true});
        map.addLayer(layer);
        map.zoomToMaxExtent();
        var bounds = layer.adjustBounds(new OpenLayers.Bounds(-270,-90,-180,0));
        t.ok( bounds.equals(new OpenLayers.Bounds(90,-90,180,0)), "-270,-90,-180,0 wraps to 90,-90,180,0");
        bounds = layer.adjustBounds(new OpenLayers.Bounds(180,-90,270,0));
        t.ok( bounds.equals(new OpenLayers.Bounds(-180,-90,-90,0)), "180,-90,270,0 wraps to -180,-90,-90,0");
        bounds = layer.adjustBounds(new OpenLayers.Bounds(-180,-90,0,0));
        t.ok( bounds.equals(new OpenLayers.Bounds(-180,-90,0,0)), "-180,-90,0,0 doesn't wrap");
        bounds = layer.adjustBounds(new OpenLayers.Bounds(-181,-90,-179,0));
        t.ok( bounds.equals(new OpenLayers.Bounds(-181,-90,-179,0)), "-181,-90,-179,0 doesn't wrap, because it straddles the dateline");
        bounds = layer.adjustBounds(new OpenLayers.Bounds(-180,-180,-90,-90));
        t.ok( bounds.equals(new OpenLayers.Bounds(-180,-180,-90,-90)), "-180,-180,-90,-90 doesn't wrap, because we don't wrap lats.");
        layer = new OpenLayers.Layer.WMS(name, url, params);
        map.addLayer(layer);
        var testBounds = null;
        var outBounds = null;
        var testList = [
          new OpenLayers.Bounds(-270,-90,-180,0),
          new OpenLayers.Bounds(180,-90,270,0),
          new OpenLayers.Bounds(-180,-90,0,0),
          new OpenLayers.Bounds(-181,-90,-179,0),
          new OpenLayers.Bounds(-180,-180,-90,-90)
        ];          
        for (var i = 0; i < testList.length; i++) {
            outBounds = layer.adjustBounds(testList[i]);
            t.ok( outBounds.equals(testList[i]), testList[i]+" doesn't wrap in non-wrapping layer.");
        }
        map.destroy();
    }
    function test_Layer_WrapDateLine_getLonLat(t) {
        t.plan(12);
        var map = new OpenLayers.Map('map');
        layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true});
        map.addLayer(layer);
        map.zoomToMaxExtent();
        var testLonLats = [
            new OpenLayers.LonLat(-185,5),
            new OpenLayers.LonLat(-180,-95),
            new OpenLayers.LonLat(-180,95),
            new OpenLayers.LonLat(180,-95),
            new OpenLayers.LonLat(180,95),
            new OpenLayers.LonLat(185,5)
        ];
        var outLonLats = [
            new OpenLayers.LonLat(175,5),
            new OpenLayers.LonLat(-180,-95),
            new OpenLayers.LonLat(-180,95),
            new OpenLayers.LonLat(180,-95),
            new OpenLayers.LonLat(180,95),
            new OpenLayers.LonLat(-175,5)
        ];    
            
        for (var i = 0; i < testLonLats.length; i++) {
            var pixel = layer.getViewPortPxFromLonLat(testLonLats[i]);
            var lonlat = layer.getLonLatFromViewPortPx(pixel);
            lonlat.lon = Math.round(lonlat.lon);
            lonlat.lat = Math.round(lonlat.lat);
            t.ok(outLonLats[i].equals(lonlat), testLonLats[i] + " wraps to " + outLonLats[i]+ " (what happened: " + lonlat + ")");   
        }
        
        layer = new OpenLayers.Layer.WMS(name, url, params);
        map.addLayer(layer);
        var outLonLats = [
            new OpenLayers.LonLat(-185,5),
            new OpenLayers.LonLat(-180,-95),
            new OpenLayers.LonLat(-180,95),
            new OpenLayers.LonLat(180,-95),
            new OpenLayers.LonLat(180,95),
            new OpenLayers.LonLat(185,5)
        ];    
        for (var i = 0; i < testLonLats.length; i++) {
            var pixel = layer.getViewPortPxFromLonLat(testLonLats[i]);
            var lonlat = layer.getLonLatFromViewPortPx(pixel);
            lonlat.lon = Math.round(lonlat.lon);
            lonlat.lat = Math.round(lonlat.lat);
            t.ok(outLonLats[i].equals(lonlat), testLonLats[i] + " wraps to " + outLonLats[i]+ " (what happened: " + lonlat + ")");   
        }
        map.destroy();
        
    }
    function test_Layer_WrapDateLine_ZoomToExtent (t) {
        t.plan( 4 );

        var url = "http://octo.metacarta.com/cgi-bin/mapserv";
        layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true});
        var m = new OpenLayers.Map('map');
        m.addLayer(layer);
        m.setCenter = function(myCenter) { this.center = myCenter; }
        var testBounds = [
            new OpenLayers.Bounds(-185,-90,-175,-85),
            new OpenLayers.Bounds(0,-90,-170,-85),
            new OpenLayers.Bounds(-270,-90,-180,-85),
            new OpenLayers.Bounds(0,0,45,45)
        ];
        var outCenters = [
            new OpenLayers.LonLat(-180,-87.5),
            new OpenLayers.LonLat(95,-87.5),
            new OpenLayers.LonLat(135,-87.5),
            new OpenLayers.LonLat(22.5,22.5)
        ];
        for (var i = 0; i < testBounds.length; i++) {
            m.zoomToExtent(testBounds[i]);
            t.ok(m.center.equals(outCenters[i]), "Map center from bounds " + testBounds[i] + " should be " + outCenters[i] + ", got " + m.center);  
        }
        m.destroy();
        
    
    }
    function test_Layer_WrapDateLine_WMS (t) {
        t.plan( 4 );

        var url = "http://octo.metacarta.com/cgi-bin/mapserv";
        layer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true,encodeBBOX:true, buffer: 2});
        var m = new OpenLayers.Map('map', {tileManager: null, adjustZoom: function(z) {return z;}});
        m.addLayer(layer);
        m.zoomToMaxExtent();
        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=&SRS=EPSG%3A4326&BBOX=0%2C-90%2C180%2C90&WIDTH=256&HEIGHT=256", "cell [3][0] is wrapped around the world.");
        t.eq(layer.grid[3][1].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=&SRS=EPSG%3A4326&BBOX=-180%2C-90%2C0%2C90&WIDTH=256&HEIGHT=256", "cell [3][1] is wrapped around the world.");
        t.eq(layer.grid[3][2].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=&SRS=EPSG%3A4326&BBOX=0%2C-90%2C180%2C90&WIDTH=256&HEIGHT=256", "cell [3][2] is not wrapped at all.");
        t.ok(layer.grid[0][2].url == null, "no latitudinal wrapping - tile not loaded if outside maxExtent");
        m.destroy();

    }
    function test_Layer_WrapDateLine_KaMap (t) {
        t.plan( 4 );

        var layer = new OpenLayers.Layer.KaMap( "Blue Marble NG",
             "http://www.openlayers.org/world/index.php",
             {g: "satellite", map: "world"},
             {wrapDateLine: true, buffer: 2} ); 
        var m = new OpenLayers.Map('map', {tileManager: null, adjustZoom: function(z) {return z;}});
        m.addLayer(layer);
        m.zoomToMaxExtent();
        t.eq(layer.grid[4][7].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=0&l=-256&s=221471921.25", "grid[5][7] kamap is okay");
        t.eq(layer.grid[4][6].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=0&l=0&s=221471921.25", "grid[5][6] kamap is okay");
        t.eq(layer.grid[4][5].url, "http://www.openlayers.org/world/index.php?g=satellite&map=world&i=jpeg&t=0&l=-256&s=221471921.25", "grid[5][5] is okay");
        t.ok(layer.grid[7][6].url == null, "no latitudinal wrapping - tile not loaded if outside maxExtent");
        m.destroy();
    }
    function test_Layer_WrapDateLine_WMS_Overlay (t) {
        t.plan( 4 );
        var url = "http://octo.metacarta.com/cgi-bin/mapserv";
        baselayer = new OpenLayers.Layer.WMS(name, url, params, {'wrapDateLine':true, buffer: 2});
        var layer = new OpenLayers.Layer.WMS( "DM Solutions Demo",
            "http://www2.dmsolutions.ca/cgi-bin/mswms_gmap",
            {layers: "bathymetry,land_fn,park,drain_fn,drainage," +
                     "prov_bound,fedlimit,rail,road,popplace",
             transparent: "true", format: "image/png"},
            {wrapDateLine: true, encodeBBOX:true, buffer:2});
        var m = new OpenLayers.Map('map', {tileManager: null, adjustZoom: function(z) {return z;}});
        m.addLayers([baselayer,layer]);
        m.zoomToMaxExtent();
        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=&SRS=EPSG%3A4326&BBOX=0%2C-90%2C180%2C90&WIDTH=256&HEIGHT=256", "grid[0][0] wms overlay is okay");
        t.eq(layer.grid[3][1].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=&SRS=EPSG%3A4326&BBOX=-180%2C-90%2C0%2C90&WIDTH=256&HEIGHT=256", "grid[0][3] wms overlay is okay");
        t.eq(layer.grid[3][2].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=&SRS=EPSG%3A4326&BBOX=0%2C-90%2C180%2C90&WIDTH=256&HEIGHT=256", "grid[3][0] wms overlay okay");
        t.ok(layer.grid[0][2].url == null, "no latitudinal wrapping - tile not loaded if outside maxExtent");
        m.destroy();
    }

  </script>
</head>
<body>
<div id="map" style="width:1000px;height:550px"></div>
</body>
</html>