3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
7 function test_initialize(t) {
10 layer = new OpenLayers.Layer.Markers('Test Layer');
11 t.ok( layer instanceof OpenLayers.Layer.Markers, "new OpenLayers.Layer.Markers returns object" );
12 t.eq( layer.name, "Test Layer", "layer.name is correct" );
14 function test_addlayer (t) {
17 layer = new OpenLayers.Layer.Markers('Test Layer');
18 t.ok( layer instanceof OpenLayers.Layer.Markers, "new OpenLayers.Layer.Markers returns object" );
19 t.eq( layer.name, "Test Layer", "layer.name is correct" );
20 layer.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0),
21 new OpenLayers.Icon())
23 t.eq( layer.markers.length, 1, "addLayer adds marker to layer." );
25 function test_addMarker_removeMarker (t) {
28 var map = new OpenLayers.Map('map');
29 var baseLayer = new OpenLayers.Layer.WMS("Test Layer",
30 "http://octo.metacarta.com/cgi-bin/mapserv?",
31 {map: "/mapdata/vmap_wms.map", layers: "basic"});
32 map.addLayer(baseLayer);
33 map.zoomToMaxExtent();
34 layer = new OpenLayers.Layer.Markers('Test Layer');
36 var marker = new OpenLayers.Marker(new OpenLayers.LonLat(5,40));
37 layer.addMarker(marker);
38 t.ok( marker.icon.imageDiv.parentNode == layer.div, "addMarker adds marker image node into layer node." );
39 layer.removeMarker(marker);
40 t.ok( marker.icon.imageDiv.parentNode != layer.div, "removeMarker removes marker image node from layer node." );
41 layer.removeMarker(marker);
42 t.ok(true, "Removing marker twice does not fail.");
43 layer.addMarker(marker);
44 t.ok( marker.icon.imageDiv.parentNode == layer.div, "addMarker adds marker image node into layer node." );
47 layer.removeMarker(marker);
48 t.ok(true, "removing marker when no markers present does not script error");
50 var l = new OpenLayers.Layer.Markers();
51 var marker = new OpenLayers.Marker(new OpenLayers.LonLat(5,40));
53 l.removeMarker(marker);
54 t.ok(true, "Removing marker when layer not added to map does not fail.");
58 function test_markerMovement(t) {
62 var map = new OpenLayers.Map("map");
63 var layer = new OpenLayers.Layer.Markers("Base", {isBaseLayer: true});
65 map.setCenter(new OpenLayers.LonLat(0, 0), 1);
67 var size = new OpenLayers.Size(10, 10);
68 var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
69 var icon = new OpenLayers.Icon("foo", size, offset);
70 var marker = new OpenLayers.Marker(new OpenLayers.LonLat(10, -10), icon)
71 layer.addMarker(marker);
73 t.eq(marker.icon.px.x, 554, "marker icon is placed at 554 px on x-axis");
74 t.eq(marker.icon.px.y, 314, "marker icon is placed at 314 px on y-axis");
78 t.eq(marker.icon.px.x, 568, "marker icon moved to 568 px on x-axis");
79 t.eq(marker.icon.px.y, 328, "marker icon moved to 328 px on y-axis");
83 t.eq(marker.icon.px.x, 554, "marker icon moved back to 554 px on x-axis");
84 t.eq(marker.icon.px.y, 314, "marker icon moved back to 314 px on y-axis");
88 function test_destroy (t) {
90 layer = new OpenLayers.Layer.Markers('Test Layer');
91 var map = new OpenLayers.Map('map');
94 t.eq( layer.map, null, "layer.map is null after destroy" );
97 function test_getDataExtent(t) {
101 var ret = OpenLayers.Layer.Markers.prototype.getDataExtent.apply(layer, []);
102 t.eq(ret, null, "does not crash, returns null on layer with null 'this.markers'");
105 ret = OpenLayers.Layer.Markers.prototype.getDataExtent.apply(layer, []);
106 t.eq(ret, null, "returns null on layer with empty 'this.markers'");
109 'lonlat': new OpenLayers.LonLat(4,5)
111 var expectedBounds = new OpenLayers.Bounds(4,5,4,5);
112 ret = OpenLayers.Layer.Markers.prototype.getDataExtent.apply(layer, []);
113 t.ok(ret.equals(expectedBounds), "returns expected bounds with only one marker");
116 'lonlat': new OpenLayers.LonLat(1,2)
118 var expectedBounds = new OpenLayers.Bounds(1,2,4,5);
119 ret = OpenLayers.Layer.Markers.prototype.getDataExtent.apply(layer, []);
120 t.ok(ret.equals(expectedBounds), "returns expected bounds with multiple markers");
124 function test_setOpacity(t) {
127 layer = new OpenLayers.Layer.Markers('Test Layer');
129 var opacity = 0.1234;
131 for (var i = 0; i < 12; i++) {
132 layer.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0), new OpenLayers.Icon()));
135 layer.setOpacity(opacity);
137 for (var i = 0; i < 4; i++) {
138 layer.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(0,0), new OpenLayers.Icon()));
142 for (var i = 0; i < layer.markers.length; i++) {
143 itWorks = parseFloat(layer.markers[i].icon.imageDiv.style.opacity) == opacity;
148 t.ok(itWorks, "setOpacity change markers opacity");
154 <div id="map" style="width: 1080px; height: 600px;"/>