1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
<html>
<head>
<script src="OLLoader.js"></script>
<script type="text/javascript">
var marker;
function test_Marker_constructor (t) {
t.plan( 4 );
var ll = new OpenLayers.LonLat(2,1);
marker = new OpenLayers.Marker(ll,new OpenLayers.Icon());
t.ok( marker instanceof OpenLayers.Marker, "new OpenLayers.Marker returns Marker object" );
t.ok( marker.icon instanceof OpenLayers.Icon, "new marker.Icon returns Icon object" );
t.ok( marker.lonlat instanceof OpenLayers.LonLat, "new marker.lonlat returns LonLat object" );
t.ok( marker.lonlat.equals(ll), "marker.lonlat returns correct" );
}
function test_Marker_onScreen(t) {
t.plan( 2 );
var map = new OpenLayers.Map("map");
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
layer = new OpenLayers.Layer.WMS(name, url);
map.addLayer(layer);
mlayer = new OpenLayers.Layer.Markers('Test Layer');
map.addLayer(mlayer);
map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50));
//onscreen marker
var ll = new OpenLayers.LonLat(0,0);
var marker = new OpenLayers.Marker(ll);
mlayer.addMarker(marker);
t.ok( marker.onScreen(), "marker knows it's onscreen" );
//offscreen marker
var ll = new OpenLayers.LonLat(100,100);
var marker2 = new OpenLayers.Marker(ll);
mlayer.addMarker(marker2);
t.ok( !marker2.onScreen(), "marker knows it's offscreen" );
map.destroy();
}
function test_Marker_setOpacity(t) {
t.plan( 2 );
var map = new OpenLayers.Map("map");
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
layer = new OpenLayers.Layer.WMS(name, url);
map.addLayer(layer);
mlayer = new OpenLayers.Layer.Markers('Test Layer');
map.addLayer(mlayer);
map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50));
//onscreen marker
var ll = new OpenLayers.LonLat(0,0);
var marker = new OpenLayers.Marker(ll);
mlayer.addMarker(marker);
t.ok(!marker.icon.imageDiv.style.opacity, "default marker has no opacity");
marker.setOpacity(0.5);
t.eq(parseFloat(marker.icon.imageDiv.style.opacity), 0.5, "marker.setOpacity() works");
map.destroy();
}
function test_Marker_setUrl(t) {
t.plan( 2 );
var map = new OpenLayers.Map("map");
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
layer = new OpenLayers.Layer.WMS(name, url);
map.addLayer(layer);
mlayer = new OpenLayers.Layer.Markers('Test Layer');
map.addLayer(mlayer);
map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50));
//onscreen marker
var ll = new OpenLayers.LonLat(0,0);
var marker = new OpenLayers.Marker(ll);
mlayer.addMarker(marker);
t.ok(OpenLayers.String.contains(marker.icon.imageDiv.firstChild.src, "img/marker.png"), "Marker.png is default URL");
marker.setUrl("http://example.com/broken.png");
t.eq(marker.icon.imageDiv.firstChild.src, "http://example.com/broken.png", "image source changes correctly.");
map.destroy();
}
function test_Marker_moveTo(t) {
t.plan( 6 );
var map = new OpenLayers.Map("map");
var url = "http://octo.metacarta.com/cgi-bin/mapserv";
layer = new OpenLayers.Layer.WMS(name, url);
map.addLayer(layer);
mlayer = new OpenLayers.Layer.Markers('Test Layer');
map.addLayer(mlayer);
map.zoomToExtent(new OpenLayers.Bounds(-50,-50,50,50));
//onscreen marker
var ll = new OpenLayers.LonLat(0,0);
var marker = new OpenLayers.Marker(ll);
mlayer.addMarker(marker);
t.eq(marker.lonlat.lon, 0, "marker lon okay");
t.eq(marker.lonlat.lat, 0, "marker lat okay");
marker.moveTo(new OpenLayers.Pixel(250,275));
t.eq(marker.lonlat.lon, 0, "marker lon no change");
t.eq(marker.lonlat.lat, 0, "marker lat no change");
marker.moveTo(new OpenLayers.Pixel(0,0));
t.eq(marker.lonlat.lon, map.getExtent().left, "on left edge of map");
t.eq(marker.lonlat.lat, map.getExtent().top, "on top edge of map");
map.destroy();
}
function test_Marker_isDrawn(t) {
t.plan(3);
var marker = {};
//no icon
var drawn = OpenLayers.Marker.prototype.isDrawn.apply(marker, []);
t.ok(!drawn, "marker with no icon not drawn");
//not drawn icon
marker.icon = { isDrawn: function() { return false; } };
drawn = OpenLayers.Marker.prototype.isDrawn.apply(marker, []);
t.ok(!drawn, "marker with not drawn icon not drawn");
//drawn icon
marker.icon.isDrawn = function() { return true; };
drawn = OpenLayers.Marker.prototype.isDrawn.apply(marker, []);
t.ok(drawn, "marker with drawn icon drawn");
}
</script>
</head>
<body>
<div id="map" style="width:500px;height:550px"></div>
</body>
</html>
|