3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
8 function test_Feature_Vector_constructor(t) {
11 var geometry = new OpenLayers.Geometry();
12 geometry.id = Math.random();
13 var style = {foo: "bar"};
14 var attributes = {bar: "foo"};
16 feature = new OpenLayers.Feature.Vector(geometry, attributes, style);
18 t.ok(feature instanceof OpenLayers.Feature.Vector,
19 "new OpenLayers.Feature.Vector returns Feature.Vector object" );
20 t.eq(feature.attributes, attributes,
21 "attributes property set properly" );
22 t.eq(feature.geometry.id, geometry.id,
23 "geometry.property set properly" );
26 function test_Feature_onScreen(t) {
28 var line = new OpenLayers.Geometry.LineString([
29 new OpenLayers.Geometry.Point(0, 0),
30 new OpenLayers.Geometry.Point(10, 20)
32 var feature = new OpenLayers.Feature.Vector(line);
35 getExtent: function() {
36 return new OpenLayers.Bounds(5, 5, 10, 10);
40 t.eq(feature.onScreen(), true,
41 "intersecting feature returns true for intersection");
42 t.eq(feature.onScreen(true), true,
43 "intersecting feature returns true for bounds only");
45 // move the line so only the bounds intersects
47 t.eq(feature.onScreen(), false,
48 "bounds-only feature returns false for intersection");
49 t.eq(feature.onScreen(true), true,
50 "bounds-only feature returns true for bounds only");
52 // move the line so bounds does not intersect
54 t.eq(feature.onScreen(), false,
55 "off-screen feature returns false for intersection");
56 t.eq(feature.onScreen(true), false,
57 "off-screen feature returns false for bounds only");
61 function test_Feature_Vector_clone(t) {
64 var geometry = new OpenLayers.Geometry.Point(Math.random(),
66 var style = {foo: "bar"};
67 var attributes = {bar: "foo"};
69 feature = new OpenLayers.Feature.Vector(geometry, attributes, style);
70 var clone = feature.clone();
72 t.ok(clone instanceof OpenLayers.Feature.Vector,
73 "new OpenLayers.Feature.Vector returns Feature.Vector object");
74 t.eq(clone.attributes, attributes,
75 "attributes property set properly");
76 t.eq(clone.style, style,
77 "style property set properly");
78 t.eq(clone.geometry.x, geometry.x,
79 "geometry.x property set properly");
80 t.eq(clone.geometry.y, geometry.y,
81 "geometry.y property set properly");
83 feature = new OpenLayers.Feature.Vector();
84 clone = feature.clone();
85 t.ok(clone instanceof OpenLayers.Feature.Vector,
86 "clone can clone geometry-less features");
89 function test_Feature_Vector_move(t) {
98 var geometry = new OpenLayers.Geometry.Point(oldx,
103 feature = new OpenLayers.Feature.Vector(geometry);
106 getViewPortPxFromLonLat : function(lonlat){
107 return new OpenLayers.Pixel(lonlat.lon,lonlat.lat);
110 getResolution: function(){
114 drawFeature: function(){
119 var pixel = new OpenLayers.Pixel(newx,newy)
123 geometry = feature.geometry;
125 t.ok(drawn, "The feature is redrawn after the move");
126 t.eq(geometry.x, res * (newx - oldx) + oldx, "New geometry has proper x coordinate");
127 t.eq(geometry.y, res * (oldy - newy) + oldy, "New geometry has proper y coordinate");
134 <div id="map" style="width: 500px; height: 300px;"></div>