]> dev.renevier.net Git - syp.git/blob - openlayers/tests/Control/DrawFeature.html
err_lonlat_invalid exceptions not thrown correctly
[syp.git] / openlayers / tests / Control / DrawFeature.html
1 <html>
2 <head>
3     <script src="../../lib/OpenLayers.js"></script>
4     <script type="text/javascript">
5
6     function test_initialize(t) {
7         t.plan(2);
8         var control = new OpenLayers.Control.DrawFeature("foo", function() {});
9         t.ok(control instanceof OpenLayers.Control.DrawFeature,
10              "constructor returns an instance");
11         t.ok(OpenLayers.Util.indexOf(control.EVENT_TYPES, "featureadded") > -1,
12              "featureadded event in EVENT_TYPES");
13     }
14     
15     function test_drawFeature(t) {
16         t.plan(3);
17         var layer = new OpenLayers.Layer.Vector();
18         var control = new OpenLayers.Control.DrawFeature(layer, function() {});
19         var geom = {};
20         
21         layer.addFeatures = function(features) {
22             t.ok(features[0].geometry == geom, "layer.addFeatures called");
23             t.eq(features[0].state, OpenLayers.State.INSERT, "layer state set");
24         };
25         function handlefeatureadded(event) {
26             t.ok(event.feature.geometry == geom, "featureadded triggered");
27         }
28         control.events.on({"featureadded": handlefeatureadded});
29         control.drawFeature(geom);
30         control.events.un({"featureadded": handlefeatureadded});
31         
32     }
33     
34     function test_sketch_events(t) {
35         t.plan(6);
36         var map = new OpenLayers.Map("map", {
37             resolutions: [1]
38         });
39         var layer = new OpenLayers.Layer.Vector("foo", {
40             maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
41             isBaseLayer: true
42         });
43         var control = new OpenLayers.Control.DrawFeature(
44             layer, OpenLayers.Handler.Point
45         );
46         map.addLayer(layer);
47         map.addControl(control);
48         map.zoomToMaxExtent();
49         control.activate();
50         
51         var log = {};
52         layer.events.on({
53             sketchstarted: function(event) {
54                 log.event = event;
55             },
56             sketchmodified: function(event) {
57                 log.event = event;
58             },
59             sketchcomplete: function(event) {
60                 log.event = event;
61             }
62         });
63         
64         // mock up draw/modify of a point
65         map.events.triggerEvent("mousedown", {xy: new OpenLayers.Pixel(0, 0)});
66         t.eq(log.event.type, "sketchstarted", "[mousedown] sketchstarted triggered");
67         t.geom_eq(log.event.vertex, new OpenLayers.Geometry.Point(-200, 125), "[mousedown] correct vertex");
68         map.events.triggerEvent("mousemove", {xy: new OpenLayers.Pixel(10, 10)});
69         t.eq(log.event.type, "sketchmodified", "[mousemove] sketchmodified triggered");
70         t.geom_eq(log.event.vertex, new OpenLayers.Geometry.Point(-190, 115), "[mousemove] correct vertex");
71         map.events.triggerEvent("mouseup", {xy: new OpenLayers.Pixel(10, 10)});
72         t.eq(log.event.type, "sketchcomplete", "[mouseup] sketchcomplete triggered");
73         t.geom_eq(log.event.feature.geometry, new OpenLayers.Geometry.Point(-190, 115), "[mouseup] correct geometry");
74         
75         map.destroy();
76     }
77
78     </script>
79 </head>
80 <body>
81     <div id="map" style="width: 400px; height: 250px;"/>
82 </body>
83 </html>