summaryrefslogtreecommitdiff
path: root/misc/openlayers/tests/Layer/Text.html
blob: 3bffe4c1b47c92213cdf86164060501514ff515c (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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<html>
<head>
  <script src="../OLLoader.js"></script>
  <script type="text/javascript">
    var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
    var isMSIE = (navigator.userAgent.indexOf("MSIE") > -1);
    var layer; 

    var datafile  = "./data_Layer_Text_textfile.txt";
    var datafile2 = "./data_Layer_Text_textfile_2.txt";
    var datafile_overflow = "./data_Layer_Text_textfile_overflow.txt";

    // if this test is running in IE, different rules apply
    if (isMSIE) {
        datafile = "." + datafile;
        datafile2 = "." + datafile2;
        datafile_overflow = "." + datafile_overflow;
    }

    function test_Layer_Text_constructor (t) {
        t.plan( 5 );
        
        layer = new OpenLayers.Layer.Text('Test Layer', { location: datafile });
        layer.loadText();
        t.ok( layer instanceof OpenLayers.Layer.Text, "new OpenLayers.Layer.Text returns object" );
        t.eq( layer.location, datafile, "layer.location is correct" );
        var markers;
        t.delay_call( 1, function() {  
            t.eq( layer.markers.length, 2, "marker length is correct" );
            var ll = new OpenLayers.LonLat(20, 10);
            t.ok( layer.markers[0].lonlat.equals(ll), "first marker is correct" );
            t.eq( layer.markers[0].icon.url, 'http://boston.openguides.org/markers/ORANGE.png', "icon" );
        } );
    }
    function test_Layer_Text_draw (t) { 
//        t.plan(5);
        t.plan( 2 );
        layer = new OpenLayers.Layer.Text('Test Layer', { location: datafile });
        t.ok( layer instanceof OpenLayers.Layer.Text, "new OpenLayers.Layer.Text returns object" );
        var map = new OpenLayers.Map('map');
        var baseLayer = new OpenLayers.Layer.WMS("Test Layer", 
            "http://octo.metacarta.com/cgi-bin/mapserv?",
            {map: "/mapdata/vmap_wms.map", layers: "basic"});
        map.addLayer(baseLayer);
        map.addLayer(layer);
        t.eq( map.layers[1].name, layer.name, "Layer added to map okay" );
        t.delay_call( 1, function() { 
          map.setCenter(new OpenLayers.LonLat(0,0),0);

/*
            if (!isMozilla)
                t.ok( true, "skipping element test outside of Mozilla");
            else
              t.ok( map.layers[0].div.firstChild instanceof HTMLImageElement, "Marker added to div" )

          t.eq( map.layers[0].div.firstChild.style.top, "219px", "Marker top set correctly" )
          t.eq( map.layers[0].div.firstChild.style.left, "273px", "Marker left set correctly" )
*/
        });;
    }

    function test_Layer_Text_moveTo(t) {
        t.plan(16);
        
        temp = OpenLayers.Layer.Markers.prototype.moveTo;

        g_Bounds = {};
        g_ZoomChanged = {};
        g_Minor = {};
        var args = [g_Bounds, g_ZoomChanged, g_Minor];

        OpenLayers.Layer.Markers.prototype.moveTo = 
            function(bounds, zoomChanged, minor) {
                t.ok(bounds == g_Bounds, "correct bounds passed to Markers superclass");
                t.ok(zoomChanged == g_ZoomChanged, "correct zoomChanged passed to Markers superclass");
                t.ok(minor == g_Minor, "correct minor passed to Markers superclass");
            }

        var layer = {
            'loadText': function() { g_TextLoaded = true; }
        };

        //visibility true, loaded true
        layer.visibility = true;
        layer.loaded = true;
        g_TextLoaded = false;
        OpenLayers.Layer.Text.prototype.moveTo.apply(layer, args);
        t.ok(g_TextLoaded == false, "text not loaded when visibility true, loaded true");

        //visibility true, loaded false
        layer.visibility = true;
        layer.loaded = false;
        g_TextLoaded = false;
        OpenLayers.Layer.Text.prototype.moveTo.apply(layer, args);
        t.ok(g_TextLoaded == true, "text is loaded when visibility true, loaded false");

        //visibility false, loaded true
        layer.visibility = false;
        layer.loaded = true;
        g_TextLoaded = false;
        OpenLayers.Layer.Text.prototype.moveTo.apply(layer, args);
        t.ok(g_TextLoaded == false, "text not loaded when visibility false, loaded true");

        //visibility false, loaded false
        layer.visibility = false;
        layer.loaded = false;
        g_TextLoaded = false;
        OpenLayers.Layer.Text.prototype.moveTo.apply(layer, args);
        t.ok(g_TextLoaded == false, "text not loaded when visibility false, loaded false");

        OpenLayers.Layer.Markers.prototype.moveTo = temp;
    }



    function test_Layer_Text_events (t) {
        t.plan( 5 );    
        layer = new OpenLayers.Layer.Text('Test Layer', { location: datafile2 });
        var map = new OpenLayers.Map('map');
        var baseLayer = new OpenLayers.Layer.WMS("Test Layer", 
            "http://octo.metacarta.com/cgi-bin/mapserv?",
            {map: "/mapdata/vmap_wms.map", layers: "basic"});
        map.addLayer(baseLayer);
        map.addLayer(layer);
        map.setCenter(new OpenLayers.LonLat(0,0),0);
        var event = {};
        t.delay_call( 1, function() {  
          t.ok(layer.markers[0].events, "First marker has an events object");
          t.eq(layer.markers[0].events.listeners['click'].length, 1, "Marker events has one object");
          layer.markers[0].events.triggerEvent('click', event);
          t.eq(map.popups.length, 1, "Popup opened correctly");
          layer.markers[1].events.triggerEvent('click', event);
          t.eq(map.popups.length, 1, "1st popup gone, 2nd Popup opened correctly");
          //Safari 3 separates style overflow into overflow-x and overflow-y
          var prop = (OpenLayers.BROWSER_NAME == 'safari') ? 'overflowX' : 'overflow';
          t.eq(map.popups[0].contentDiv.style[prop],"auto", "default Popup overflow correct");
        });
    }
    function test_Layer_Text_overflow (t) {
        t.plan( 4 );    
        layer = new OpenLayers.Layer.Text('Test Layer', { location: datafile_overflow });
        var map = new OpenLayers.Map('map');
        var baseLayer = new OpenLayers.Layer.WMS("Test Layer", 
            "http://octo.metacarta.com/cgi-bin/mapserv?",
            {map: "/mapdata/vmap_wms.map", layers: "basic"});
        map.addLayer(baseLayer);
        map.addLayer(layer);
        map.setCenter(new OpenLayers.LonLat(0,0),0);
        var event = {};
        t.delay_call( 1, function() {  
          layer.markers[0].events.triggerEvent('click', event);
          t.eq(map.popups.length, 1, "Popup opened correctly");
          //Safari 3 separates style overflow into overflow-x and overflow-y
          var prop = (OpenLayers.BROWSER_NAME == 'safari') ? 'overflowX' : 'overflow';
          t.eq(map.popups[0].contentDiv.style[prop],"auto", "Popup overflow read from file");
          layer.markers[1].events.triggerEvent('click', event);
          t.eq(map.popups.length, 1, "1st popup gone, 2nd Popup opened correctly");
          //Safari 3 separates style overflow into overflow-x and overflow-y
          var prop = (OpenLayers.BROWSER_NAME == 'safari') ? 'overflowX' : 'overflow';
          t.eq(map.popups[0].contentDiv.style[prop],"hidden", "Popup overflow read from file");
        });
    }
    function test_Layer_Text_events_nopopups (t) {
        t.plan( 4 );    
        layer = new OpenLayers.Layer.Text('Test Layer', { location: datafile });
        var map = new OpenLayers.Map('map');
        var baseLayer = new OpenLayers.Layer.WMS("Test Layer", 
            "http://octo.metacarta.com/cgi-bin/mapserv?",
            {map: "/mapdata/vmap_wms.map", layers: "basic"});
        map.addLayer(baseLayer);
        map.addLayer(layer);
        map.setCenter(new OpenLayers.LonLat(0,0),0);
        var event = {};
        t.delay_call( 1, function() {  
          t.ok(layer.markers[0].events, "First marker has an events object");
          t.eq(layer.markers[0].events.listeners['click'], undefined, "Marker events has no object");
          layer.markers[0].events.triggerEvent('click', event);
          t.eq(map.popups.length, 0, "no popup on first marker");
          layer.markers[1].events.triggerEvent('click', event);
          t.eq(map.popups.length, 0, "no popup on second marker");
        });
    }
    function test_Layer_Text_loadend_Event(t) {
        t.plan(2);
        layer = new OpenLayers.Layer.Text('Test Layer', {location:datafile});
        t.delay_call(2, function() { 
            layer.events.register('loadend', layer, function() { 
                t.ok(true, "Loadend event fired"); 
            });
            layer.parseData({
                'responseText':''
            });
            t.ok(true, "Parsing data didn't fail"); 
        });
    }

    function test_Layer_Text_destroy (t) {
        t.plan( 1 );    
        layer = new OpenLayers.Layer.Text('Test Layer');
        var map = new OpenLayers.Map('map');
        map.addLayer(layer);
        layer.destroy();
        t.eq( layer.map, null, "layer.map is null after destroy" );
    }

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