3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
7 function test_Box_constructor (t) {
10 OpenLayers.Marker.Box.prototype._setBorder =
11 OpenLayers.Marker.Box.prototype.setBorder;
12 OpenLayers.Marker.Box.prototype.setBorder = function (x,y) {
17 var bounds = new OpenLayers.Bounds(1,2,3,4);
18 var borderColor = "blue";
22 g_Color = g_Width = null;
23 box = new OpenLayers.Marker.Box(bounds, borderColor, borderWidth);
25 t.ok( box instanceof OpenLayers.Marker.Box, "new OpenLayers.Marker.Box returns Box object" );
26 t.ok( box.bounds.equals(bounds), "bounds object correctly set");
27 t.ok( box.div != null, "div created");
28 //Safari 3 separates style overflow into overflow-x and overflow-y
29 var prop = (OpenLayers.Util.getBrowserName() == 'safari') ? 'overflowX' : 'overflow';
30 t.eq( box.div.style[prop], "hidden", "div style overflow hidden");
31 t.ok( box.events != null, "events object created");
32 t.eq( g_Color, borderColor, "setBorder called with correct border color");
33 t.eq( g_Width, borderWidth, "setBorder called with correct border width");
36 OpenLayers.Marker.Box.prototype.setBorder =
37 OpenLayers.Marker.Box.prototype._setBorder;
41 function test_Box_setBorder(t) {
52 OpenLayers.Marker.Box.prototype.setBorder.apply(box, args);
53 t.eq(box.div.style.border, "2px solid red", "style correctly set with no good values (defaults work)");
56 var borderColor = "blue";
59 args = [borderColor, borderWidth];
60 OpenLayers.Marker.Box.prototype.setBorder.apply(box, args);
61 t.eq(box.div.style.border, borderWidth + "px solid " + borderColor, "style correctly set with both good values");
64 function test_Box_draw(t) {
67 OpenLayers.Util._modifyDOMElement =
68 OpenLayers.Util.modifyDOMElement;
69 OpenLayers.Util.modifyDOMElement =
70 function (element, id, px, sz) {
86 g_Element = g_Id = g_Px = g_Sz = null;
87 var retVal = OpenLayers.Marker.Box.prototype.draw.apply(box, args);
89 t.eq(g_Element, box.div, "modifyDOMElement passes box's div for element");
90 t.eq(g_Id, null, "modifyDOMElement passes null for id");
91 t.eq(g_Px, px, "modifyDOMElement passes new px value for px");
92 t.eq(g_Sz, sz, "modifyDOMElement passes new sz value for sz");
93 t.ok(retVal == box.div, "draw returns box's div");
95 OpenLayers.Util.modifyDOMElement =
96 OpenLayers.Util._modifyDOMElement;
100 function test_Box_onScreen(t) {
103 var map = new OpenLayers.Map("map");
105 var url = "http://octo.metacarta.com/cgi-bin/mapserv";
106 layer = new OpenLayers.Layer.WMS("WMS Layer", url);
110 mlayer = new OpenLayers.Layer.Boxes('Test Layer');
111 map.addLayer(mlayer);
113 map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50));
116 var bounds = new OpenLayers.Bounds(-1,-1,1,1);
117 var box = new OpenLayers.Marker.Box(bounds);
118 mlayer.addMarker(box);
120 t.ok( box.onScreen(), "box knows it's onscreen" );
123 var bounds = new OpenLayers.Bounds(100,100,150,150);
124 var box2 = new OpenLayers.Marker.Box(bounds);
125 mlayer.addMarker(box2);
127 t.ok( !box2.onScreen(), "box knows it's offscreen" );
131 function test_Box_display(t) {
142 OpenLayers.Marker.Box.prototype.display.apply(box, args);
143 t.eq(box.div.style.display, "", "style.display correctly set to '' when display(true)");
147 OpenLayers.Marker.Box.prototype.display.apply(box, args);
148 t.eq(box.div.style.display, "none", "style.display correctly set to 'none' when display(false)");
151 function test_Box_destroy(t) {
154 OpenLayers.Marker.prototype._destroy =
155 OpenLayers.Marker.prototype.destroy;
156 OpenLayers.Marker.prototype.destroy = function() {
160 var bounds = new OpenLayers.Bounds(1,2,3,4);
161 var borderColor = "blue";
162 var borderWidth = 55;
165 box = new OpenLayers.Marker.Box(bounds, borderColor, borderWidth);
168 t.eq(box.bounds, null, "bounds nullified");
169 t.eq(box.div, null, "div nullified");
170 t.ok(g_Destroy == true, "OpenLayers.Marker.destroy() called");
173 OpenLayers.Marker.prototype.destroy =
174 OpenLayers.Marker.prototype._destroy;
181 <div id="map" style="width:500px;height:550px"></div>