summaryrefslogtreecommitdiff
path: root/misc/openlayers/tests/deprecated/Layer/MapServer/Untiled.html
blob: f2354922253bef2b559ada3eb9d73a3ddf00245d (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
<html>
<head>    

    <script src="../../../OLLoader.js"></script>
    <script src="../../../../lib/deprecated.js"></script>
    <script type="text/javascript">

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

    var name = 'Test Layer';
    var url = "http://labs.metacarta.com/cgi-bin/mapserv";
    var params = { map: '/mapdata/vmap_wms.map', 
                   layers: 'basic'};
    
    function test_Layer_MapServer_Untiled_constructor (t) {
        t.plan( 4 );

        var url = "http://labs.metacarta.com/cgi-bin/mapserv";
        layer = new OpenLayers.Layer.MapServer.Untiled(name, url, params);
        t.ok( layer instanceof OpenLayers.Layer.MapServer.Untiled, "new OpenLayers.Layer.MapServer returns object" );
        t.eq( layer.url, "http://labs.metacarta.com/cgi-bin/mapserv", "layer.url is correct (HTTPRequest inited)" );

        t.eq( layer.params.mode, "map", "default mode param correctly copied");
        t.eq( layer.params.map_imagetype, "png", "default imagetype correctly copied");


    }
    
    function test_Layer_MapServer_Untiled_clone (t) {
        t.plan(3);
        
        var url = "http://labs.metacarta.com/cgi-bin/mapserv";
        var map = new OpenLayers.Map('map', {});
        layer = new OpenLayers.Layer.MapServer.Untiled(name, url, params);
        map.addLayer(layer);

        var clone = layer.clone();
        layer.tile = [[1,2],[3,4]];
        
        t.ok( clone.tile != layer.tile, "clone does not copy tile");

        layer.ratio += 1;

        t.eq( clone.ratio, 1.5, "changing layer.ratio does not change clone.ratio -- a fresh copy was made, not just copied reference");

        t.eq( clone.alpha, layer.alpha, "alpha copied correctly");

        layer.tile = null;
        map.destroy();
    }

    function test_Layer_MapServer_Untiled_isBaseLayer(t) {
        t.plan(3);
        
        var url = "http://labs.metacarta.com/cgi-bin/mapserv";
        layer = new OpenLayers.Layer.MapServer.Untiled(name, url, params);
        t.ok( layer.isBaseLayer, "baselayer is true by default");

        var newParams = OpenLayers.Util.extend({}, params);
        newParams.transparent = "true";
        layer = new OpenLayers.Layer.MapServer.Untiled(name, url, newParams);
        t.ok( !layer.isBaseLayer, "baselayer is false when transparent is set to true");

        layer = new OpenLayers.Layer.MapServer.Untiled(name, url, params, {isBaseLayer: false});
        t.ok( !layer.isBaseLayer, "baselayer is false when option is set to false" );
    }

    function test_Layer_MapServer_Untiled_mergeNewParams (t) {
        t.plan( 5 );

        var map = new OpenLayers.Map("map", {tileManager: null});
        var url = "http://labs.metacarta.com/cgi-bin/mapserv";
        layer = new OpenLayers.Layer.MapServer.Untiled(name, url, params);
        
        var newParams = { layers: 'sooper', 
                          chickpeas: 'image/png'};

        map.addLayer(layer);
        map.zoomToMaxExtent();
        t.ok( !layer.grid[0][0].url.match("chickpeas"), "chickpeas is not in URL of first tile in grid" );

        layer.mergeNewParams(newParams);
        
        t.eq( layer.params.layers, "sooper", "mergeNewParams() overwrites well");
        t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() adds well");
        t.ok( layer.grid[0][0].url.match("chickpeas"), "chickpeas is in URL of first tile in grid" );

        newParams.chickpeas = 151;

        t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() makes clean copy of hashtable");
        map.destroy();
    }

    function test_Layer_MapServer_Untiled_getFullRequestString (t) {

        
        t.plan( 1 );
        var map = new OpenLayers.Map('map');
        tUrl = "http://labs.metacarta.com/cgi-bin/mapserv";
        tParams = { layers: 'basic', 
                    format: 'png'};
        var tLayer = new OpenLayers.Layer.MapServer.Untiled(name, tUrl, tParams);
        map.addLayer(tLayer);
        str = tLayer.getFullRequestString();
        var tParams = {
             layers: 'basic', 
             format: 'png',
             mode: 'map',
             map_imagetype: 'png'
        };

        var sStr = tUrl + "?" + OpenLayers.Util.getParameterString(tParams);
        sStr = sStr.replace(/,/g, "+");
        
        t.eq(str, sStr , "getFullRequestString() works");
        map.destroy();

    }

    // DEPRECATED -- REMOVE IN 3.0
    function test_Layer_Untiled_MapServer(t) { 
        t.plan(1);
        
        var layer = new OpenLayers.Layer.MapServer.Untiled();
        
        var clone = layer.clone();
        
        t.ok(clone.singleTile, "regression test: clone works. this is for #1013");
    }
    
    function test_Layer_MapServer_Untiled_destroy (t) {

        t.plan( 1 );

        var map = new OpenLayers.Map('map');
        layer = new OpenLayers.Layer.MapServer.Untiled(name, url, params);
        map.addLayer(layer);

        map.setCenter(new OpenLayers.LonLat(0,0), 5);

        //grab a reference to one of the tiles
        var tile = layer.tile;        

        layer.destroy();
        
    // checks to make sure superclass (grid) destroy() was called    
        
        t.ok( layer.tile == null, "tile set to null");
        map.destroy();
    }
    
  </script>
</head>
<body>
<div id="map" style="width:500px;height:550px"></div>
</body>
</html>