| 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 map; |
|---|
| 7 |
var feature, layer; |
|---|
| 8 |
|
|---|
| 9 |
function test_01_Feature_constructor (t) { |
|---|
| 10 |
t.plan( 7 ); |
|---|
| 11 |
|
|---|
| 12 |
var layer = {}; |
|---|
| 13 |
var lonlat = new OpenLayers.LonLat(2,1); |
|---|
| 14 |
var iconURL = 'http://boston.openguides.org/features/ORANGE.png'; |
|---|
| 15 |
var iconSize = new OpenLayers.Size(12, 17); |
|---|
| 16 |
var data = { iconURL: iconURL, |
|---|
| 17 |
iconSize: iconSize |
|---|
| 18 |
}; |
|---|
| 19 |
|
|---|
| 20 |
feature = new OpenLayers.Feature(layer, lonlat, data); |
|---|
| 21 |
|
|---|
| 22 |
t.ok( feature instanceof OpenLayers.Feature, "new OpenLayers.Feature returns Feature object" ); |
|---|
| 23 |
t.eq( feature.layer, layer, "feature.layer set correctly" ); |
|---|
| 24 |
t.ok(OpenLayers.String.startsWith(feature.id, "OpenLayers.Feature_"), |
|---|
| 25 |
"feature.id set correctly"); |
|---|
| 26 |
t.ok( feature.lonlat.equals(lonlat), "feature.lonlat set correctly" ); |
|---|
| 27 |
t.eq( feature.data.iconURL, iconURL, "feature.data.iconURL set correctly" ); |
|---|
| 28 |
t.ok( feature.data.iconSize.equals(iconSize), "feature.data.iconSize set correctly" ); |
|---|
| 29 |
t.ok( feature.popupClass == OpenLayers.Popup.AnchoredBubble, "default popupClass is AnchoredBubble"); |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
function test_02_Feature_createPopup (t) { |
|---|
| 33 |
t.plan(1); |
|---|
| 34 |
var layer = {}; |
|---|
| 35 |
var lonlat = new OpenLayers.LonLat(2,1); |
|---|
| 36 |
var iconURL = 'http://boston.openguides.org/features/ORANGE.png'; |
|---|
| 37 |
var iconSize = new OpenLayers.Size(12, 17); |
|---|
| 38 |
var data = { iconURL: iconURL, |
|---|
| 39 |
iconSize: iconSize, |
|---|
| 40 |
'overflow':'auto' |
|---|
| 41 |
}; |
|---|
| 42 |
|
|---|
| 43 |
feature = new OpenLayers.Feature(layer, lonlat, data); |
|---|
| 44 |
popup = feature.createPopup(); |
|---|
| 45 |
t.eq(popup.contentDiv.style.overflow, "auto", 'overflow on popup is correct'); |
|---|
| 46 |
} |
|---|
| 47 |
function test_02_Feature_createMarker (t) { |
|---|
| 48 |
t.plan(1); |
|---|
| 49 |
t.ok(true); |
|---|
| 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 |
function test_03_Feature_onScreen(t) { |
|---|
| 98 |
t.plan( 2 ); |
|---|
| 99 |
|
|---|
| 100 |
var map = new OpenLayers.Map("map"); |
|---|
| 101 |
|
|---|
| 102 |
var url = "http://octo.metacarta.com/cgi-bin/mapserv"; |
|---|
| 103 |
var wms = new OpenLayers.Layer.WMS(name, url); |
|---|
| 104 |
|
|---|
| 105 |
map.addLayer(wms); |
|---|
| 106 |
|
|---|
| 107 |
var layer = new OpenLayers.Layer("foo"); |
|---|
| 108 |
map.addLayer(layer); |
|---|
| 109 |
|
|---|
| 110 |
map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50)); |
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
var feature1 = new OpenLayers.Feature(layer, |
|---|
| 114 |
new OpenLayers.LonLat(0,0)); |
|---|
| 115 |
t.ok( feature1.onScreen(), "feature knows it's onscreen" ); |
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 |
var feature2 = new OpenLayers.Feature(layer, |
|---|
| 119 |
new OpenLayers.LonLat(100,100)); |
|---|
| 120 |
t.ok( !feature2.onScreen(), "feature knows it's offscreen" ); |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
function test_04_Feature_createPopup(t) { |
|---|
| 124 |
t.plan(17); |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
var f = { |
|---|
| 128 |
'popup': null |
|---|
| 129 |
}; |
|---|
| 130 |
|
|---|
| 131 |
var ret = OpenLayers.Feature.prototype.createPopup.apply(f, []); |
|---|
| 132 |
t.ok((ret == f.popup) && (f.popup == null), "if no 'lonlat' set on feature, still returns reference to this.popup (though it is null)"); |
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
f.popupClass = OpenLayers.Class({ |
|---|
| 137 |
initialize: function(id, lonlat, size, contentHTML, anchor, closeBox) { |
|---|
| 138 |
t.eq(id, "Campion_popup", "correctly generates new popup id from feature's id"); |
|---|
| 139 |
t.eq(lonlat, f.lonlat, "correctly passes feature's lonlat to popup constructor"); |
|---|
| 140 |
t.eq(size, f.data.popupSize, "correctly passes feature's data.popupSize to popup constructor"); |
|---|
| 141 |
t.eq(contentHTML, f.data.popupContentHTML, "correctly passes feature's data.popupContentHTML to popup constructor"); |
|---|
| 142 |
t.eq(anchor, g_ExpectedAnchor, "passes correct anchor to popup constructor"); |
|---|
| 143 |
t.eq(closeBox, g_CloseBox, "correctly relays closeBox argument to popup constructor"); |
|---|
| 144 |
} |
|---|
| 145 |
}); |
|---|
| 146 |
|
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
f.popup = null; |
|---|
| 150 |
|
|---|
| 151 |
f.id = "Campion"; |
|---|
| 152 |
f.lonlat = {}; |
|---|
| 153 |
f.data = { |
|---|
| 154 |
'popupSize': {}, |
|---|
| 155 |
'popupContentHTML': {} |
|---|
| 156 |
}; |
|---|
| 157 |
g_ExpectedAnchor = null; |
|---|
| 158 |
g_CloseBox = {}; |
|---|
| 159 |
|
|---|
| 160 |
ret = OpenLayers.Feature.prototype.createPopup.apply(f, [g_CloseBox]); |
|---|
| 161 |
|
|---|
| 162 |
t.ok((ret == f.popup) && (f.popup != null), "a valid popup has been set and returned") |
|---|
| 163 |
t.ok( f.popup.feature == f, "popup's 'feature' property correctly set"); |
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
f.marker = { |
|---|
| 169 |
'icon': {} |
|---|
| 170 |
}; |
|---|
| 171 |
g_ExpectedAnchor = f.marker.icon; |
|---|
| 172 |
ret = OpenLayers.Feature.prototype.createPopup.apply(f, [g_CloseBox]); |
|---|
| 173 |
t.ok((ret == f.popup) && (f.popup != null), "a valid popup has been set and returned") |
|---|
| 174 |
t.ok( f.popup.feature == f, "popup's 'feature' property correctly set"); |
|---|
| 175 |
} |
|---|
| 176 |
|
|---|
| 177 |
function test_04_Feature_destroyPopup(t) { |
|---|
| 178 |
t.plan(2); |
|---|
| 179 |
|
|---|
| 180 |
var f = { |
|---|
| 181 |
'popup': { |
|---|
| 182 |
'feature': {}, |
|---|
| 183 |
'destroy': function() { |
|---|
| 184 |
t.ok(true, "default destroyPopup() calls popup.destroy"); |
|---|
| 185 |
} |
|---|
| 186 |
} |
|---|
| 187 |
}; |
|---|
| 188 |
|
|---|
| 189 |
OpenLayers.Feature.prototype.destroyPopup.apply(f, []); |
|---|
| 190 |
t.ok(f.popup.feature == null, "popup's 'feature' property nullified on destroy"); |
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
</script> |
|---|
| 194 |
</head> |
|---|
| 195 |
<body> |
|---|
| 196 |
<div id="map" style="width: 500px; height: 300px;"></div> |
|---|
| 197 |
</body> |
|---|
| 198 |
</html> |
|---|