| 1 |
<html> |
|---|
| 2 |
<head> |
|---|
| 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); |
|---|
| 7 |
var layer; |
|---|
| 8 |
|
|---|
| 9 |
var georss_txt = "./georss.txt"; |
|---|
| 10 |
var atom_xml = "./atom-1.0.xml"; |
|---|
| 11 |
|
|---|
| 12 |
// if this test is running online, different rules apply |
|---|
| 13 |
if (isMSIE) { |
|---|
| 14 |
georss_txt = "." + georss_txt; |
|---|
| 15 |
atom_xml = "." + atom_xml; |
|---|
| 16 |
} |
|---|
| 17 |
|
|---|
| 18 |
function test_Layer_GeoRSS_constructor (t) { |
|---|
| 19 |
t.plan( 7 ); |
|---|
| 20 |
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt ); |
|---|
| 21 |
t.ok( layer instanceof OpenLayers.Layer.GeoRSS, "new OpenLayers.Layer.GeoRSS returns object" ); |
|---|
| 22 |
t.eq( layer.location, georss_txt, "layer.location is correct" ); |
|---|
| 23 |
var markers; |
|---|
| 24 |
layer.loadRSS(); |
|---|
| 25 |
t.delay_call( 1, function() { |
|---|
| 26 |
t.eq( layer.markers.length, 40, "marker length is correct" ); |
|---|
| 27 |
var ll = new OpenLayers.LonLat(-71.142197, 42.405696); |
|---|
| 28 |
var theTitle = "Knitting Room"; |
|---|
| 29 |
var theDescription = 'This little shop is jammed full. Yarn, yarn everywhere. They make the most of every possible nook and cranny. I like this place also because they have a lot of different kinds of knitting needles in all different sizes. Also, the people who work here are younger and hipper than in the other stores I go to. I reccomend buying supplies here and then knitting your way through a good documentary at the Capitol Theater across the street.<br/>Address: 2 lake St, Arlington, MA <br/>Tags: knitting, yarn, pins and needles, handspun, hand dyed, novelty yarn, fancy, simple, young, hip, friendly, needles, addy, cute hats<br /><br /><a href="http://platial.com/place/90306">Map this on Platial</a><br /> <a href="http://platial.com/place_grab/90306">Grab this on Platial</a> '; |
|---|
| 30 |
t.ok( layer.markers[0].lonlat.equals(ll), "lonlat on first marker is correct" ); |
|---|
| 31 |
t.eq( layer.name, "Crschmidt's Places At Platial", "Layer name is correct." ); |
|---|
| 32 |
t.eq( layer.features[0].data.title, theTitle); |
|---|
| 33 |
t.eq( layer.features[0].data.description, theDescription); |
|---|
| 34 |
} ); |
|---|
| 35 |
} |
|---|
| 36 |
|
|---|
| 37 |
function test_Layer_GeoRSS_dontUseFeedTitle (t) { |
|---|
| 38 |
t.plan( 1 ); |
|---|
| 39 |
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt, {'useFeedTitle': false} ); |
|---|
| 40 |
t.delay_call( 1, function() { |
|---|
| 41 |
t.eq( layer.name, "Test Layer", "Layer name is correct when not used from feed." ); |
|---|
| 42 |
} ); |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
function test_Layer_GeoRSS_AtomParsing (t) { |
|---|
| 46 |
t.plan( 6 ); |
|---|
| 47 |
layer = new OpenLayers.Layer.GeoRSS('Test Layer', atom_xml ); |
|---|
| 48 |
t.ok( layer instanceof OpenLayers.Layer.GeoRSS, "new OpenLayers.Layer.GeoRSS returns object" ); |
|---|
| 49 |
t.eq( layer.location, atom_xml, "layer.location is correct" ); |
|---|
| 50 |
var markers; |
|---|
| 51 |
layer.loadRSS(); |
|---|
| 52 |
t.delay_call( 1, function() { |
|---|
| 53 |
t.eq( layer.markers.length, 2, "marker length is correct" ); |
|---|
| 54 |
var ll = new OpenLayers.LonLat(29.9805, 36.7702); |
|---|
| 55 |
t.ok( layer.markers[0].lonlat.equals(ll), "lonlat on first marker is correct" ); |
|---|
| 56 |
t.like( layer.features[0].data['popupContentHTML'], '<a class="link" href="http://pleiades.stoa.org/places/638896" target="_blank">Unnamed Tumulus</a>', "Link is correct."); |
|---|
| 57 |
t.eq( layer.name, "tumulus", "Layer name is correct." ); |
|---|
| 58 |
} ); |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
function test_Layer_GeoRSS_draw (t) { |
|---|
| 62 |
// t.plan(5); |
|---|
| 63 |
t.plan( 2 ); |
|---|
| 64 |
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt); |
|---|
| 65 |
t.ok( layer instanceof OpenLayers.Layer.GeoRSS, "new OpenLayers.Layer.GeoRSS returns object" ); |
|---|
| 66 |
var map = new OpenLayers.Map('map'); |
|---|
| 67 |
var baseLayer = new OpenLayers.Layer.WMS("Test Layer", |
|---|
| 68 |
"http://octo.metacarta.com/cgi-bin/mapserv?", |
|---|
| 69 |
{map: "/mapdata/vmap_wms.map", layers: "basic"}); |
|---|
| 70 |
map.addLayer(baseLayer); |
|---|
| 71 |
map.addLayer(layer); |
|---|
| 72 |
t.delay_call( 1, function() { |
|---|
| 73 |
map.setCenter(new OpenLayers.LonLat(0,0),0); |
|---|
| 74 |
t.eq( map.layers[1].name, layer.name, "Layer name is correct" ); |
|---|
| 75 |
|
|---|
| 76 |
});; |
|---|
| 77 |
} |
|---|
| 78 |
function test_Layer_GeoRSS_load_events (t) { |
|---|
| 79 |
t.plan( 1 ); |
|---|
| 80 |
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt); |
|---|
| 81 |
var map = new OpenLayers.Map('map'); |
|---|
| 82 |
var baseLayer = new OpenLayers.Layer.WMS("Test Layer", |
|---|
| 83 |
"http://octo.metacarta.com/cgi-bin/mapserv?", |
|---|
| 84 |
{map: "/mapdata/vmap_wms.map", layers: "basic"}); |
|---|
| 85 |
map.addLayer(baseLayer); |
|---|
| 86 |
map.addLayer(layer); |
|---|
| 87 |
layer.events.register("loadstart", t, function() { this.ok(true, "loadstart event triggered once (#1580)") }); |
|---|
| 88 |
map.setCenter(new OpenLayers.LonLat(0,0),0); |
|---|
| 89 |
} |
|---|
| 90 |
function test_Layer_GeoRSS_events (t) { |
|---|
| 91 |
t.plan( 4 ); |
|---|
| 92 |
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt); |
|---|
| 93 |
var map = new OpenLayers.Map('map'); |
|---|
| 94 |
var baseLayer = new OpenLayers.Layer.WMS("Test Layer", |
|---|
| 95 |
"http://octo.metacarta.com/cgi-bin/mapserv?", |
|---|
| 96 |
{map: "/mapdata/vmap_wms.map", layers: "basic"}); |
|---|
| 97 |
map.addLayer(baseLayer); |
|---|
| 98 |
map.addLayer(layer); |
|---|
| 99 |
map.setCenter(new OpenLayers.LonLat(0,0),0); |
|---|
| 100 |
var event = {}; |
|---|
| 101 |
t.delay_call( 2, function() { |
|---|
| 102 |
t.ok(layer.markers[0].events, "First marker has an events object"); |
|---|
| 103 |
t.eq(layer.markers[0].events.listeners['click'].length, 1, "Marker events has one object"); |
|---|
| 104 |
layer.markers[0].events.triggerEvent('click', event); |
|---|
| 105 |
t.eq(map.popups.length, 1, "Popup opened correctly"); |
|---|
| 106 |
layer.markers[1].events.triggerEvent('click', event); |
|---|
| 107 |
t.eq(map.popups.length, 1, "1st popup gone, 2nd Popup opened correctly"); |
|---|
| 108 |
}); |
|---|
| 109 |
} |
|---|
| 110 |
function test_Layer_GeoRSS_popups (t) { |
|---|
| 111 |
t.plan( 4 ); |
|---|
| 112 |
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt); |
|---|
| 113 |
var map = new OpenLayers.Map('map'); |
|---|
| 114 |
var baseLayer = new OpenLayers.Layer.WMS("Test Layer", |
|---|
| 115 |
"http://octo.metacarta.com/cgi-bin/mapserv?", |
|---|
| 116 |
{map: "/mapdata/vmap_wms.map", layers: "basic"}); |
|---|
| 117 |
map.addLayer(baseLayer); |
|---|
| 118 |
map.addLayer(layer); |
|---|
| 119 |
map.setCenter(new OpenLayers.LonLat(0,0),0); |
|---|
| 120 |
var event = {}; |
|---|
| 121 |
t.delay_call( 1, function() { |
|---|
| 122 |
t.ok(layer.markers[0].events, "First marker has an events object"); |
|---|
| 123 |
t.eq(layer.markers[0].events.listeners['click'].length, 1, "Marker events has one object"); |
|---|
| 124 |
layer.markers[0].events.triggerEvent('click', event); |
|---|
| 125 |
t.eq(map.popups.length, 1, "Popup opened correctly"); |
|---|
| 126 |
layer.markers[1].events.triggerEvent('click', event); |
|---|
| 127 |
t.eq(map.popups.length, 1, "1st popup gone, 2nd Popup opened correctly"); |
|---|
| 128 |
}); |
|---|
| 129 |
|
|---|
| 130 |
} |
|---|
| 131 |
function test_Layer_GeoRSS_resizedPopups(t) { |
|---|
| 132 |
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt, {'popupSize': new OpenLayers.Size(200,100)}); |
|---|
| 133 |
t.plan( 4 ); |
|---|
| 134 |
var map = new OpenLayers.Map('map'); |
|---|
| 135 |
var baseLayer = new OpenLayers.Layer.WMS("Test Layer", |
|---|
| 136 |
"http://octo.metacarta.com/cgi-bin/mapserv?", |
|---|
| 137 |
{map: "/mapdata/vmap_wms.map", layers: "basic"}); |
|---|
| 138 |
map.addLayer(baseLayer); |
|---|
| 139 |
map.addLayer(layer); |
|---|
| 140 |
map.setCenter(new OpenLayers.LonLat(0,0),0); |
|---|
| 141 |
var event = {}; |
|---|
| 142 |
t.delay_call( 1, function() { |
|---|
| 143 |
t.ok(layer.markers[0].events, "First marker has an events object"); |
|---|
| 144 |
t.eq(layer.markers[0].events.listeners['click'].length, 1, "Marker events has one object"); |
|---|
| 145 |
layer.markers[0].events.triggerEvent('click', event); |
|---|
| 146 |
t.eq(map.popups.length, 1, "Popup opened correctly"); |
|---|
| 147 |
map.popups[0].size.w=300; |
|---|
| 148 |
layer.markers[1].events.triggerEvent('click', event); |
|---|
| 149 |
t.eq(map.popups.length, 1, "1st popup gone, 2nd Popup opened correctly"); |
|---|
| 150 |
}); |
|---|
| 151 |
} |
|---|
| 152 |
|
|---|
| 153 |
function test_Layer_GeoRSS_icon(t) { |
|---|
| 154 |
t.plan( 3 ); |
|---|
| 155 |
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt); |
|---|
| 156 |
var the_icon = new OpenLayers.Icon('http://boston.openguides.org/markers/AQUA.png'); |
|---|
| 157 |
var otherLayer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt,{icon:the_icon}); |
|---|
| 158 |
var map = new OpenLayers.Map('map'); |
|---|
| 159 |
var baseLayer = new OpenLayers.Layer.WMS("Test Layer", |
|---|
| 160 |
"http://octo.metacarta.com/cgi-bin/mapserv?", |
|---|
| 161 |
{map: "/mapdata/vmap_wms.map", layers: "basic"}); |
|---|
| 162 |
map.addLayer(baseLayer); |
|---|
| 163 |
map.addLayers([layer,otherLayer]); |
|---|
| 164 |
map.setCenter(new OpenLayers.LonLat(0,0),0); |
|---|
| 165 |
var defaultIcon = OpenLayers.Marker.defaultIcon(); |
|---|
| 166 |
layer.loadRSS(); |
|---|
| 167 |
otherLayer.loadRSS(); |
|---|
| 168 |
t.delay_call( 2, function() { |
|---|
| 169 |
t.ok(layer.markers[0].icon, "The layer has a icon"); |
|---|
| 170 |
t.eq(layer.markers[0].icon.url, defaultIcon.url, "The layer without icon has the default icon."); |
|---|
| 171 |
t.eq(otherLayer.markers[0].icon.url, the_icon.url,"The layer with an icon has that icon."); |
|---|
| 172 |
}); |
|---|
| 173 |
} |
|---|
| 174 |
function test_Layer_GeoRSS_loadend_Event(t) { |
|---|
| 175 |
var browserCode = OpenLayers.Util.getBrowserName(); |
|---|
| 176 |
if (browserCode == "msie") { |
|---|
| 177 |
t.plan(1); |
|---|
| 178 |
t.ok(true, "IE fails the GeoRSS test. This could probably be fixed by someone with enough energy to fix it."); |
|---|
| 179 |
} else { |
|---|
| 180 |
t.plan(2); |
|---|
| 181 |
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt); |
|---|
| 182 |
t.delay_call(2, function() { |
|---|
| 183 |
layer.events.register('loadend', layer, function() { |
|---|
| 184 |
t.ok(true, "Loadend event fired"); |
|---|
| 185 |
}); |
|---|
| 186 |
layer.parseData({ |
|---|
| 187 |
'responseText': '<xml xmlns="http://example.com"><title> </title></xml>' |
|---|
| 188 |
}); |
|---|
| 189 |
t.ok(true, "Parsing data didn't fail"); |
|---|
| 190 |
}); |
|---|
| 191 |
} |
|---|
| 192 |
} |
|---|
| 193 |
|
|---|
| 194 |
function test_Layer_GeoRSS_destroy (t) { |
|---|
| 195 |
t.plan( 1 ); |
|---|
| 196 |
layer = new OpenLayers.Layer.GeoRSS('Test Layer', georss_txt); |
|---|
| 197 |
var map = new OpenLayers.Map('map'); |
|---|
| 198 |
map.addLayer(layer); |
|---|
| 199 |
t.delay_call( 1, function() { |
|---|
| 200 |
layer.destroy(); |
|---|
| 201 |
t.eq( layer.map, null, "layer.map is null after destroy" ); |
|---|
| 202 |
}); |
|---|
| 203 |
} |
|---|
| 204 |
|
|---|
| 205 |
</script> |
|---|
| 206 |
</head> |
|---|
| 207 |
<body> |
|---|
| 208 |
<div id="map" style="width:500px; height:500px"></div> |
|---|
| 209 |
</body> |
|---|
| 210 |
</html> |
|---|