New layer type PointTrack: connects point features to lines. r=crschmidt,elemoine. (closes #1167)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@5733 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
79
tests/Layer/test_PointTrack.html
Normal file
79
tests/Layer/test_PointTrack.html
Normal file
@@ -0,0 +1,79 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="../../lib/OpenLayers.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var name = "PointTrack Layer";
|
||||
|
||||
function test_01_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_02_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_99_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.eq(layer.getFeatureFromEvent({'target':'map'}), null, "getFeatureIdFromEvent doesn't cause an error when called on layer which has been destroyed.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map" style="width:500px;height:550px"></div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user