3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
5 var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
6 var isMSIE = (navigator.userAgent.indexOf("MSIE") > -1);
9 var datafile = "./data_Layer_Text_textfile.txt";
10 var datafile2 = "./data_Layer_Text_textfile_2.txt";
11 var datafile_overflow = "./data_Layer_Text_textfile_overflow.txt";
13 // if this test is running in IE, different rules apply
15 datafile = "." + datafile;
16 datafile2 = "." + datafile2;
17 datafile_overflow = "." + datafile_overflow;
20 function test_Layer_Text_constructor (t) {
23 layer = new OpenLayers.Layer.Text('Test Layer', { location: datafile });
25 t.ok( layer instanceof OpenLayers.Layer.Text, "new OpenLayers.Layer.Text returns object" );
26 t.eq( layer.location, datafile, "layer.location is correct" );
28 t.delay_call( 1, function() {
29 t.eq( layer.markers.length, 2, "marker length is correct" );
30 var ll = new OpenLayers.LonLat(20, 10);
31 t.ok( layer.markers[0].lonlat.equals(ll), "first marker is correct" );
32 t.eq( layer.markers[0].icon.url, 'http://boston.openguides.org/markers/ORANGE.png', "icon" );
35 function test_Layer_Text_draw (t) {
38 layer = new OpenLayers.Layer.Text('Test Layer', { location: datafile });
39 t.ok( layer instanceof OpenLayers.Layer.Text, "new OpenLayers.Layer.Text returns object" );
40 var map = new OpenLayers.Map('map');
41 var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
42 "http://octo.metacarta.com/cgi-bin/mapserv?",
43 {map: "/mapdata/vmap_wms.map", layers: "basic"});
44 map.addLayer(baseLayer);
46 t.eq( map.layers[1].name, layer.name, "Layer added to map okay" );
47 t.delay_call( 1, function() {
48 map.setCenter(new OpenLayers.LonLat(0,0),0);
52 t.ok( true, "skipping element test outside of Mozilla");
54 t.ok( map.layers[0].div.firstChild instanceof HTMLImageElement, "Marker added to div" )
56 t.eq( map.layers[0].div.firstChild.style.top, "219px", "Marker top set correctly" )
57 t.eq( map.layers[0].div.firstChild.style.left, "273px", "Marker left set correctly" )
62 function test_Layer_Text_moveTo(t) {
65 temp = OpenLayers.Layer.Markers.prototype.moveTo;
70 var args = [g_Bounds, g_ZoomChanged, g_Minor];
72 OpenLayers.Layer.Markers.prototype.moveTo =
73 function(bounds, zoomChanged, minor) {
74 t.ok(bounds == g_Bounds, "correct bounds passed to Markers superclass");
75 t.ok(zoomChanged == g_ZoomChanged, "correct zoomChanged passed to Markers superclass");
76 t.ok(minor == g_Minor, "correct minor passed to Markers superclass");
80 'loadText': function() { g_TextLoaded = true; }
83 //visibility true, loaded true
84 layer.visibility = true;
87 OpenLayers.Layer.Text.prototype.moveTo.apply(layer, args);
88 t.ok(g_TextLoaded == false, "text not loaded when visibility true, loaded true");
90 //visibility true, loaded false
91 layer.visibility = true;
94 OpenLayers.Layer.Text.prototype.moveTo.apply(layer, args);
95 t.ok(g_TextLoaded == true, "text is loaded when visibility true, loaded false");
97 //visibility false, loaded true
98 layer.visibility = false;
100 g_TextLoaded = false;
101 OpenLayers.Layer.Text.prototype.moveTo.apply(layer, args);
102 t.ok(g_TextLoaded == false, "text not loaded when visibility false, loaded true");
104 //visibility false, loaded false
105 layer.visibility = false;
106 layer.loaded = false;
107 g_TextLoaded = false;
108 OpenLayers.Layer.Text.prototype.moveTo.apply(layer, args);
109 t.ok(g_TextLoaded == false, "text not loaded when visibility false, loaded false");
111 OpenLayers.Layer.Markers.prototype.moveTo = temp;
116 function test_Layer_Text_events (t) {
118 layer = new OpenLayers.Layer.Text('Test Layer', { location: datafile2 });
119 var map = new OpenLayers.Map('map');
120 var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
121 "http://octo.metacarta.com/cgi-bin/mapserv?",
122 {map: "/mapdata/vmap_wms.map", layers: "basic"});
123 map.addLayer(baseLayer);
125 map.setCenter(new OpenLayers.LonLat(0,0),0);
127 t.delay_call( 1, function() {
128 t.ok(layer.markers[0].events, "First marker has an events object");
129 t.eq(layer.markers[0].events.listeners['click'].length, 1, "Marker events has one object");
130 layer.markers[0].events.triggerEvent('click', event);
131 t.eq(map.popups.length, 1, "Popup opened correctly");
132 layer.markers[1].events.triggerEvent('click', event);
133 t.eq(map.popups.length, 1, "1st popup gone, 2nd Popup opened correctly");
134 //Safari 3 separates style overflow into overflow-x and overflow-y
135 var prop = (OpenLayers.Util.getBrowserName() == 'safari') ? 'overflowX' : 'overflow';
136 t.eq(map.popups[0].contentDiv.style[prop],"auto", "default Popup overflow correct");
139 function test_Layer_Text_overflow (t) {
141 layer = new OpenLayers.Layer.Text('Test Layer', { location: datafile_overflow });
142 var map = new OpenLayers.Map('map');
143 var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
144 "http://octo.metacarta.com/cgi-bin/mapserv?",
145 {map: "/mapdata/vmap_wms.map", layers: "basic"});
146 map.addLayer(baseLayer);
148 map.setCenter(new OpenLayers.LonLat(0,0),0);
150 t.delay_call( 1, function() {
151 layer.markers[0].events.triggerEvent('click', event);
152 t.eq(map.popups.length, 1, "Popup opened correctly");
153 //Safari 3 separates style overflow into overflow-x and overflow-y
154 var prop = (OpenLayers.Util.getBrowserName() == 'safari') ? 'overflowX' : 'overflow';
155 t.eq(map.popups[0].contentDiv.style[prop],"auto", "Popup overflow read from file");
156 layer.markers[1].events.triggerEvent('click', event);
157 t.eq(map.popups.length, 1, "1st popup gone, 2nd Popup opened correctly");
158 //Safari 3 separates style overflow into overflow-x and overflow-y
159 var prop = (OpenLayers.Util.getBrowserName() == 'safari') ? 'overflowX' : 'overflow';
160 t.eq(map.popups[0].contentDiv.style[prop],"hidden", "Popup overflow read from file");
163 function test_Layer_Text_events_nopopups (t) {
165 layer = new OpenLayers.Layer.Text('Test Layer', { location: datafile });
166 var map = new OpenLayers.Map('map');
167 var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
168 "http://octo.metacarta.com/cgi-bin/mapserv?",
169 {map: "/mapdata/vmap_wms.map", layers: "basic"});
170 map.addLayer(baseLayer);
172 map.setCenter(new OpenLayers.LonLat(0,0),0);
174 t.delay_call( 1, function() {
175 t.ok(layer.markers[0].events, "First marker has an events object");
176 t.eq(layer.markers[0].events.listeners['click'].length, 0, "Marker events has one object");
177 layer.markers[0].events.triggerEvent('click', event);
178 t.eq(map.popups.length, 0, "no popup on first marker");
179 layer.markers[1].events.triggerEvent('click', event);
180 t.eq(map.popups.length, 0, "no popup on second marker");
183 function test_Layer_Text_loadend_Event(t) {
185 layer = new OpenLayers.Layer.Text('Test Layer', {location:datafile});
186 t.delay_call(2, function() {
187 layer.events.register('loadend', layer, function() {
188 t.ok(true, "Loadend event fired");
193 t.ok(true, "Parsing data didn't fail");
197 function test_Layer_Text_destroy (t) {
199 layer = new OpenLayers.Layer.Text('Test Layer');
200 var map = new OpenLayers.Map('map');
203 t.eq( layer.map, null, "layer.map is null after destroy" );
209 <div id="map" style="width:500px; height:500px"></div>