summaryrefslogtreecommitdiff
path: root/misc/openlayers/tests/Layer/MapGuide.html
blob: b1eb386c273c4e638e4153a75d989a68cf2efb51 (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
<html>
<head>
    <script type="text/javascript">var oldAlert = window.alert, gMess; window.alert = function(message) {gMess = message; return true;};</script>
    <script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>
    <script type="text/javascript">window.alert = oldAlert;</script>
<script src="../OLLoader.js"></script>
  <script type="text/javascript">
    var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
    var layer; 

    var name = 'MapGuide Test Layer';
    var url = "http://data.mapguide.com/mapguide/mapagent/mapagent.fcgi?USERNAME=Anonymous&";
    var paramsTiled = {
      mapdefinition: 'Library://Samples/Sheboygan/MapsTiled/Sheboygan.MapDefinition',
      basemaplayergroupname: "Base Layer Group"
    }
    var paramsUntiled = {
      mapdefinition: 'Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition'
    };

    function test_Layer_MapGuide_untiled_constructor (t) {
        t.plan( 8 );

        var trans_format = "image/png";
        var options = {singleTile:true};
        if (OpenLayers.Util.alphaHack()) { trans_format = "image/gif"; } 
        
        layer = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled, options);
        t.ok( layer instanceof OpenLayers.Layer.MapGuide, "new OpenLayers.Layer.MapGuide returns object" );
        t.eq( layer.url, "http://data.mapguide.com/mapguide/mapagent/mapagent.fcgi?USERNAME=Anonymous&", "layer.url is correct (HTTPRequest inited)" );
        t.eq( layer.params.mapdefinition, "Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition", "params passed in correctly" );

        t.eq( layer.params.operation, "GETMAPIMAGE", "default params set correctly and copied");

        t.eq(layer.isBaseLayer, true, "no transparency setting, layer is baselayer");

        options.transparent = "true";
        var layer2 = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled, options);
        t.eq(layer2.isBaseLayer, false, "transparency == 'true', layer is not baselayer");

        options.transparent = true;
        var layer5 = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled, options);
        t.eq(layer5.isBaseLayer, false, "transparency == true, layer is not baselayer");

        options.transparent = false;
        var layer6 = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled, options);
        t.eq(layer6.isBaseLayer, true, "transparency == false, layer is baselayer");
    }
    
    function test_Layer_MapGuide_tiled_constructor (t) {
        t.plan( 5 );

        var trans_format = "image/png";
        var options = {singleTile:false};
        if (OpenLayers.Util.alphaHack()) { trans_format = "image/gif"; } 
        
        layer = new OpenLayers.Layer.MapGuide(name, url, paramsTiled, options);
        t.ok( layer instanceof OpenLayers.Layer.MapGuide, "new OpenLayers.Layer.MapGuide returns object" );
        t.eq( layer.url, "http://data.mapguide.com/mapguide/mapagent/mapagent.fcgi?USERNAME=Anonymous&", "layer.url is correct (HTTPRequest inited)" );
        t.eq( layer.params.basemaplayergroupname, "Base Layer Group", "params passed in correctly" );

        t.eq( layer.params.operation, "GETTILEIMAGE", "default params correctly uppercased and copied");
        t.eq( layer.params.version, "1.2.0", "version params set correctly set");
    }
    
    function test_Layer_MapGuide_inittiles (t) {
        t.plan( 1 );
        var map = new OpenLayers.Map('map');
        layer = new OpenLayers.Layer.MapGuide(name, url, paramsTiled);
        map.addLayer(layer);
        map.setCenter(new OpenLayers.LonLat(0,400000),5);
        t.eq( layer.grid.length, 3, "Grid rows is correct." );
        // t.eq( layer.grid[0].length, 6, "Grid cols is correct." );
        map.destroy();
    }


    function test_Layer_MapGuide_clone (t) {
        t.plan(4);
        
        var options = {tileSize: new OpenLayers.Size(500,50)};
        var map = new OpenLayers.Map('map', options);
        layer = new OpenLayers.Layer.MapGuide(name, url, paramsTiled);
        map.addLayer(layer);

        layer.grid = [ [6, 7], 
                       [8, 9]];

        var clone = layer.clone();

        t.eq( layer.tileSize.w, 300, "layer.tileSize fixed to 300x300");
        t.ok( clone.grid != layer.grid, "clone does not copy grid");

        t.ok( clone.tileSize.equals(layer.tileSize), "tileSize correctly cloned");

        layer.tileSize.w += 40;

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

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

    function test_Layer_MapGuide_isBaseLayer(t) {
        t.plan(3);
        
        var options = {singleTile:true};
        layer = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled, options);
        t.ok( layer.isBaseLayer, "baselayer is true by default");

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

        newParams = OpenLayers.Util.extend({}, paramsUntiled);
        options.isBaseLayer = false;
        layer = new OpenLayers.Layer.MapGuide(name, url, newParams, options);
        t.ok( !layer.isBaseLayer, "baselayer is false when option is set to false" );
    }

    function test_Layer_MapGuide_mergeNewParams (t) {
        t.plan( 4 );

        var options = {singleTile:true};
        var map = new OpenLayers.Map("map");
        layer = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled, options);
        
        var newParams = { mapDefinition: 'Library://Samples/Gmap/Maps/gmap.MapDefinition',
                          chickpeas: 'image/png'};

        map.addLayer(layer);
        map.zoomToMaxExtent();

        layer.redraw = function() {
            t.ok(true, "layer is redrawn after new params merged");
        }

        layer.mergeNewParams(newParams);
        
        t.eq( layer.params.mapDefinition, "Library://Samples/Gmap/Maps/gmap.MapDefinition", "mergeNewParams() overwrites well");
        t.eq( layer.params.chickpeas, "image/png", "mergeNewParams() adds well");
    
        newParams.chickpeas = 151;

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

    function test_Layer_MapGuide_destroy (t) {

        t.plan( 1 );

        var options = {singleTile:true};
        var map = new OpenLayers.Map('map');
        layer = new OpenLayers.Layer.MapGuide(name, url, paramsUntiled, options);
        map.addLayer(layer);

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

        //grab a reference to one of the tiles
        var tile = layer.grid[0][0];        

        layer.destroy();
        
    // checks to make sure superclass (grid) destroy() was called    
        
        t.ok( layer.grid == null, "grid set to null");
    }
    

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