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
|
<html>
<head>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
var name = "PointTrack Layer";
function test_Layer_PointTrack_constructor(t) {
t.plan(2);
var layer = new OpenLayers.Layer.PointTrack(name);
t.ok(layer instanceof OpenLayers.Layer.PointTrack, "new OpenLayers.Layer.PointTrack returns correct object" );
t.ok(layer.addNodes, "layer has an addNodes method");
}
function test_Layer_PointTrack_addNodes(t) {
t.plan(11);
var layer = new OpenLayers.Layer.PointTrack(name,
{dataFrom: OpenLayers.Layer.PointTrack.dataFrom.TARGET_NODE});
var point1 = new OpenLayers.Geometry.Point(-111.04, 45.68);
var sourceNode = new OpenLayers.Feature.Vector(point1);
var point2 = new OpenLayers.Geometry.Point(-112.34, 45.67);
var targetNode = new OpenLayers.Feature.Vector(point2, {foo: "bar"});
layer.addNodes([sourceNode, targetNode]);
t.eq(layer.features.length, 1, "OpenLayers.Layer.PointTrack.addNodes creates one feature from two vector point features");
t.eq(layer.features[0].geometry.CLASS_NAME, "OpenLayers.Geometry.LineString", "The created feature has a LineString geometry");
var geometry = layer.features[0].geometry;
t.eq(geometry.components[0].x, -111.04, "The x of the first point of the line equals the x of the first point added to the layer");
t.eq(geometry.components[1].y, 45.67, "The y of the second point of the line equals the y of the second point added to the layer");
t.eq(layer.features[0].attributes.foo, "bar", "OpenLayers.Layer.PointTrack.addNodes assigns the attributes of the target node correctly");
layer.dataFrom = OpenLayers.Layer.PointTrack.dataFrom.SOURCE_NODE;
point1 = new OpenLayers.Geometry.Point(-123.54, 45.67);
sourceNode = new OpenLayers.Feature.Vector(point1, {foo: "bar"});
point2 = new OpenLayers.Geometry.Point(-123.21, 45.32);
targetNode = new OpenLayers.Feature.Vector(point2);
layer.addNodes([sourceNode, targetNode]);
t.eq(layer.features.length, 2, "added another two points, so the layer now has two features");
t.eq(layer.features[1].attributes.foo, "bar", "OpenLayers.Layer.PointTrack.addNodes assigns the attributes of the source node correctly");
point1 = new OpenLayers.LonLat(-123.58, 45.69);
sourceNode = new OpenLayers.Feature(null, point1);
point2 = new OpenLayers.LonLat(-123.25, 45.37);
targetNode = new OpenLayers.Feature(null, point2);
sourceNode.data = {foo: "bar"};
layer.addNodes([sourceNode, targetNode]);
t.eq(layer.features.length, 3, "added another two points, this time from features, so the layer now has two features");
t.eq(layer.features[2].geometry.components[0].x, -123.58, "The x of the first point of the line equals the x of the first point added to the layer");
t.eq(layer.features[2].geometry.components[1].y, 45.37, "The y of the second point of the line equals the x of the second point added to the layer");
t.eq(layer.features[2].data, sourceNode.data, "OpenLayers.Layer.PointTrack.addNodes assigns the data of the source node correctly");
}
function test_Layer_PointTrack_destroy (t) {
t.plan(3);
layer = new OpenLayers.Layer.PointTrack(name);
var map = new OpenLayers.Map('map');
map.addLayer(layer);
t.eq(layer.map.layers.length, 1, "layer added to the map successfully");
layer.destroy();
t.eq(layer.map, null, "layer.map is null after destroy");
t.ok(!layer.renderer, "layer.renderer is falsey after destroy");
}
</script>
</head>
<body>
<div id="map" style="width:500px;height:550px"></div>
</body>
</html>
|