]> dev.renevier.net Git - syp.git/blob - openlayers/tests/Layer/PointTrack.html
initial commit
[syp.git] / openlayers / tests / Layer / PointTrack.html
1 <html>
2 <head>
3 <script src="../../lib/OpenLayers.js"></script>
4   <script type="text/javascript">
5   
6     var name = "PointTrack Layer";
7
8     function test_Layer_PointTrack_constructor(t) {
9         t.plan(2);
10
11         var layer = new OpenLayers.Layer.PointTrack(name);
12         t.ok(layer instanceof OpenLayers.Layer.PointTrack, "new OpenLayers.Layer.PointTrack returns correct object" );
13         t.ok(layer.addNodes, "layer has an addNodes method");
14
15     }
16     
17     function test_Layer_PointTrack_addNodes(t) {
18         t.plan(11);
19     
20         var layer = new OpenLayers.Layer.PointTrack(name,
21                 {dataFrom: OpenLayers.Layer.PointTrack.dataFrom.TARGET_NODE});
22
23         var point1 = new OpenLayers.Geometry.Point(-111.04, 45.68);
24         var sourceNode = new OpenLayers.Feature.Vector(point1);
25         var point2 = new OpenLayers.Geometry.Point(-112.34, 45.67);
26         var targetNode = new OpenLayers.Feature.Vector(point2, {foo: "bar"});
27         layer.addNodes([sourceNode, targetNode]);
28         
29         t.eq(layer.features.length, 1, "OpenLayers.Layer.PointTrack.addNodes creates one feature from two vector point features");
30         t.eq(layer.features[0].geometry.CLASS_NAME, "OpenLayers.Geometry.LineString", "The created feature has a LineString geometry");
31         var geometry = layer.features[0].geometry;
32         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");
33         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");
34         t.eq(layer.features[0].attributes.foo, "bar", "OpenLayers.Layer.PointTrack.addNodes assigns the attributes of the target node correctly");
35         
36         layer.dataFrom = OpenLayers.Layer.PointTrack.dataFrom.SOURCE_NODE;
37
38         point1 = new OpenLayers.Geometry.Point(-123.54, 45.67);
39         sourceNode = new OpenLayers.Feature.Vector(point1, {foo: "bar"});
40         point2 = new OpenLayers.Geometry.Point(-123.21, 45.32);
41         targetNode = new OpenLayers.Feature.Vector(point2);
42         layer.addNodes([sourceNode, targetNode]);
43
44         t.eq(layer.features.length, 2, "added another two points, so the layer now has two features");
45         t.eq(layer.features[1].attributes.foo, "bar", "OpenLayers.Layer.PointTrack.addNodes assigns the attributes of the source node correctly");
46
47         point1 = new OpenLayers.LonLat(-123.58, 45.69);
48         sourceNode = new OpenLayers.Feature(null, point1);
49         point2 = new OpenLayers.LonLat(-123.25, 45.37);
50         targetNode = new OpenLayers.Feature(null, point2);
51         sourceNode.data = {foo: "bar"};
52         layer.addNodes([sourceNode, targetNode]);
53
54         t.eq(layer.features.length, 3, "added another two points, this time from features, so the layer now has two features");
55         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");
56         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");
57         t.eq(layer.features[2].data, sourceNode.data, "OpenLayers.Layer.PointTrack.addNodes assigns the data of the source node correctly");
58
59     }
60
61     function test_Layer_PointTrack_destroy (t) {
62         t.plan(3);    
63         layer = new OpenLayers.Layer.PointTrack(name);
64         var map = new OpenLayers.Map('map');
65         map.addLayer(layer);
66         t.eq(layer.map.layers.length, 1, "layer added to the map successfully");
67         layer.destroy();
68         t.eq(layer.map, null, "layer.map is null after destroy");
69         t.eq(layer.getFeatureFromEvent({'target':'map'}), null, "getFeatureIdFromEvent doesn't cause an error when called on layer which has been destroyed.");
70     }
71
72
73
74   </script>
75 </head>
76 <body>
77 <div id="map" style="width:500px;height:550px"></div>
78 </body>
79 </html>