3 <script src="../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
8 function test_Marker_constructor (t) {
10 var ll = new OpenLayers.LonLat(2,1);
11 marker = new OpenLayers.Marker(ll,new OpenLayers.Icon());
12 t.ok( marker instanceof OpenLayers.Marker, "new OpenLayers.Marker returns Marker object" );
13 t.ok( marker.icon instanceof OpenLayers.Icon, "new marker.Icon returns Icon object" );
14 t.ok( marker.lonlat instanceof OpenLayers.LonLat, "new marker.lonlat returns LonLat object" );
15 t.ok( marker.lonlat.equals(ll), "marker.lonlat returns correct" );
18 function test_Marker_onScreen(t) {
21 var map = new OpenLayers.Map("map");
23 var url = "http://octo.metacarta.com/cgi-bin/mapserv";
24 layer = new OpenLayers.Layer.WMS(name, url);
28 mlayer = new OpenLayers.Layer.Markers('Test Layer');
31 map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50));
34 var ll = new OpenLayers.LonLat(0,0);
35 var marker = new OpenLayers.Marker(ll);
36 mlayer.addMarker(marker);
38 t.ok( marker.onScreen(), "marker knows it's onscreen" );
41 var ll = new OpenLayers.LonLat(100,100);
42 var marker2 = new OpenLayers.Marker(ll);
43 mlayer.addMarker(marker2);
45 t.ok( !marker2.onScreen(), "marker knows it's offscreen" );
49 function test_Marker_setOpacity(t) {
52 var map = new OpenLayers.Map("map");
54 var url = "http://octo.metacarta.com/cgi-bin/mapserv";
55 layer = new OpenLayers.Layer.WMS(name, url);
59 mlayer = new OpenLayers.Layer.Markers('Test Layer');
62 map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50));
65 var ll = new OpenLayers.LonLat(0,0);
66 var marker = new OpenLayers.Marker(ll);
67 mlayer.addMarker(marker);
69 t.ok(!marker.icon.imageDiv.style.opacity, "default marker has no opacity");
71 marker.setOpacity(0.5);
73 t.eq(parseFloat(marker.icon.imageDiv.style.opacity), 0.5, "marker.setOpacity() works");
77 function test_Marker_setUrl(t) {
80 var map = new OpenLayers.Map("map");
82 var url = "http://octo.metacarta.com/cgi-bin/mapserv";
83 layer = new OpenLayers.Layer.WMS(name, url);
87 mlayer = new OpenLayers.Layer.Markers('Test Layer');
90 map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50));
93 var ll = new OpenLayers.LonLat(0,0);
94 var marker = new OpenLayers.Marker(ll);
95 mlayer.addMarker(marker);
97 t.ok(marker.icon.imageDiv.firstChild.src.contains("img/marker.png"), "Marker.png is default URL");
99 marker.setUrl("http://example.com/broken.png");
100 t.eq(marker.icon.imageDiv.firstChild.src, "http://example.com/broken.png", "image source changes correctly.");
105 function test_Marker_moveTo(t) {
108 var map = new OpenLayers.Map("map");
110 var url = "http://octo.metacarta.com/cgi-bin/mapserv";
111 layer = new OpenLayers.Layer.WMS(name, url);
115 mlayer = new OpenLayers.Layer.Markers('Test Layer');
116 map.addLayer(mlayer);
118 map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50));
121 var ll = new OpenLayers.LonLat(0,0);
122 var marker = new OpenLayers.Marker(ll);
123 mlayer.addMarker(marker);
125 t.eq(marker.lonlat.lon, 0, "marker lon okay");
126 t.eq(marker.lonlat.lat, 0, "marker lat okay");
128 marker.moveTo(new OpenLayers.Pixel(250,275));
129 t.eq(marker.lonlat.lon, 0, "marker lon no change");
130 t.eq(marker.lonlat.lat, 0, "marker lat no change");
132 marker.moveTo(new OpenLayers.Pixel(0,0));
133 t.eq(marker.lonlat.lon, map.getExtent().left, "on left edge of map");
134 t.eq(marker.lonlat.lat, map.getExtent().top, "on top edge of map");
138 function test_Marker_isDrawn(t) {
144 var drawn = OpenLayers.Marker.prototype.isDrawn.apply(marker, []);
145 t.ok(!drawn, "marker with no icon not drawn");
148 marker.icon = { isDrawn: function() { return false; } };
149 drawn = OpenLayers.Marker.prototype.isDrawn.apply(marker, []);
150 t.ok(!drawn, "marker with not drawn icon not drawn");
153 marker.icon.isDrawn = function() { return true; };
154 drawn = OpenLayers.Marker.prototype.isDrawn.apply(marker, []);
155 t.ok(drawn, "marker with drawn icon drawn");
161 <div id="map" style="width:500px;height:550px"></div>