]> dev.renevier.net Git - syp.git/blob - openlayers/tests/Control/Measure.html
initial commit
[syp.git] / openlayers / tests / Control / Measure.html
1 <html>
2 <head>
3   <script src="../../lib/OpenLayers.js"></script>
4   <script type="text/javascript">
5
6     function test_initialze(t) {
7         
8         t.plan(1);
9         
10         var map = new OpenLayers.Map("map");
11         var control = new OpenLayers.Control.Measure(
12             OpenLayers.Handler.Path, {persist: true}
13         );
14         map.addControl(control);
15         
16         t.eq(control.persist, true, "passing persist to constructor sets persist on handler");
17         
18         map.destroy();
19         
20     }
21     
22     function test_cancel(t) {
23         
24         t.plan(4);
25         
26         var map = new OpenLayers.Map("map");
27         var layer = new OpenLayers.Layer(null, {
28             isBaseLayer: true
29         });
30         map.addLayer(layer);
31         map.zoomToMaxExtent();
32         
33         var control = new OpenLayers.Control.Measure(
34             OpenLayers.Handler.Path, {persist: true}
35         );
36         map.addControl(control);
37         
38         control.activate();
39         
40         try {
41             control.cancel();
42             t.ok(true, "calling cancel before drawing works");
43         } catch(err) {
44             t.fail("calling cancel before drawing causes trouble: " + err);
45         }
46         t.eq(control.active, true, "control remains active after cancel");
47         
48         // create a simple measurement
49         function trigger(type, x, y) {
50             map.events.triggerEvent(type, {
51                 xy: new OpenLayers.Pixel(x, y)
52             })
53         };
54         trigger("mousedown", 0, 0);
55         trigger("mouseup", 0, 0);
56         trigger("mousemove", 10, 10);
57         trigger("mousedown", 10, 10);
58         trigger("mouseup", 10, 10);
59         
60         // confirm that the sketch persists
61         t.eq(control.handler.layer.features.length, 1, "feature persists");
62         // cancel and see that sketch is gone
63         control.cancel();
64         t.eq(control.handler.layer.features.length, 0, "feature is gone after cancel");
65         
66         map.destroy();
67         
68     }
69
70   </script>
71 </head>
72 <body>
73     <div id="map" style="width: 512px; height: 256px;"></div>
74 </body>
75 </html>