3 <script src="../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
5 var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
9 function test_Feature_constructor (t) {
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,
20 feature = new OpenLayers.Feature(layer, lonlat, data);
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");
32 function test_Feature_createPopup (t) {
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,
43 feature = new OpenLayers.Feature(layer, lonlat, data);
44 popup = feature.createPopup();
45 //Safari 3 separates style overflow into overflow-x and overflow-y
46 var prop = (OpenLayers.Util.getBrowserName() == 'safari') ? 'overflowX' : 'overflow';
47 t.eq(popup.contentDiv.style[prop], "auto", 'overflow on popup is correct');
49 function test_Feature_createMarker (t) {
55 feature = new OpenLayers.Feature("myfeature", new OpenLayers.LonLat(2,1),
57 iconURL:'http://boston.openguides.org/features/ORANGE.png',
61 layer = new OpenLayers.Layer.Markers('Marker Layer');
62 t.ok( feature instanceof OpenLayers.Feature, "new OpenLayers.Feature returns Feature object" );
63 t.ok( layer instanceof OpenLayers.Layer.Markers, "Layer is a marker layer" );
64 feature.createMarker(layer);
66 t.ok( feature.marker instanceof OpenLayers.Marker,
67 "createMarker sets a marker property to a marker" );
68 t.ok( layer.markers[0] === feature.marker,
69 "First marker in layer is the feature marker" );
71 t.ok( feature.marker.lonlat instanceof OpenLayers.LonLat,
72 "createMarker sets a marker lontlat property to a lonlat" );
73 t.ok( layer.markers[0].lonlat === feature.lonlat,
74 "First marker in the layer matches feature lonlat" );
76 t.ok( feature.marker.icon instanceof OpenLayers.Icon,
77 "createMarker sets a marker icon property to an icon" );
79 t.eq( feature.marker.icon.url,
80 "http://boston.openguides.org/features/ORANGE.png",
81 "createMarker sets marker url correctly" );
83 var map = new OpenLayers.Map('map');
85 map.setCenter(new OpenLayers.LonLat(0,0),0);
86 t.ok( map.layers[0] == layer,
87 "Marker layer added to map okay." );
89 t.ok( true, "skipping element test outside of Mozilla");
91 t.ok( map.layers[0].div.firstChild instanceof HTMLImageElement,
92 "layer div firstChild is an image" );
93 t.eq( map.layers[0].div.firstChild.src,
94 "http://boston.openguides.org/features/ORANGE.png",
95 "Layer div img contains correct url" );
99 function test_Feature_onScreen(t) {
102 var map = new OpenLayers.Map("map");
104 var url = "http://octo.metacarta.com/cgi-bin/mapserv";
105 var wms = new OpenLayers.Layer.WMS(name, url);
109 var layer = new OpenLayers.Layer("foo");
112 map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50));
115 var feature1 = new OpenLayers.Feature(layer,
116 new OpenLayers.LonLat(0,0));
117 t.ok( feature1.onScreen(), "feature knows it's onscreen" );
120 var feature2 = new OpenLayers.Feature(layer,
121 new OpenLayers.LonLat(100,100));
122 t.ok( !feature2.onScreen(), "feature knows it's offscreen" );
125 function test_Feature_createPopup(t) {
133 var ret = OpenLayers.Feature.prototype.createPopup.apply(f, []);
134 t.ok((ret == f.popup) && (f.popup == null), "if no 'lonlat' set on feature, still returns reference to this.popup (though it is null)");
138 f.popupClass = OpenLayers.Class({
139 initialize: function(id, lonlat, size, contentHTML, anchor, closeBox) {
140 t.eq(id, "Campion_popup", "correctly generates new popup id from feature's id");
141 t.eq(lonlat, f.lonlat, "correctly passes feature's lonlat to popup constructor");
142 t.eq(size, f.data.popupSize, "correctly passes feature's data.popupSize to popup constructor");
143 t.eq(contentHTML, f.data.popupContentHTML, "correctly passes feature's data.popupContentHTML to popup constructor");
144 t.eq(anchor, g_ExpectedAnchor, "passes correct anchor to popup constructor");
145 t.eq(closeBox, g_CloseBox, "correctly relays closeBox argument to popup constructor");
150 //valid lonlat but no anchor
157 'popupContentHTML': {}
159 g_ExpectedAnchor = null;
162 ret = OpenLayers.Feature.prototype.createPopup.apply(f, [g_CloseBox]);
164 t.ok((ret == f.popup) && (f.popup != null), "a valid popup has been set and returned")
165 t.ok( f.popup.feature == f, "popup's 'feature' property correctly set");
168 //valid lonlat with anchor
173 g_ExpectedAnchor = f.marker.icon;
174 ret = OpenLayers.Feature.prototype.createPopup.apply(f, [g_CloseBox]);
175 t.ok((ret == f.popup) && (f.popup != null), "a valid popup has been set and returned")
176 t.ok( f.popup.feature == f, "popup's 'feature' property correctly set");
179 function test_Feature_destroyPopup(t) {
185 'destroy': function() {
186 t.ok(true, "default destroyPopup() calls popup.destroy");
191 OpenLayers.Feature.prototype.destroyPopup.apply(f, []);
192 t.ok(f.popup == null, "popup property nullified on destroy");
198 <div id="map" style="width: 500px; height: 300px;"></div>