~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/tests/Handler/Polygon.html

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
<head>
 
3
  <script src="../../lib/OpenLayers.js"></script>
 
4
  <script type="text/javascript">
 
5
    function test_Handler_Polygon_constructor(t) {
 
6
        t.plan(3);
 
7
        var control = new OpenLayers.Control();
 
8
        control.id = Math.random();
 
9
        var callbacks = {foo: "bar"};
 
10
        var options = {bar: "foo"};
 
11
 
 
12
        var oldInit = OpenLayers.Handler.prototype.initialize;
 
13
 
 
14
        OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
 
15
            t.eq(con.id, control.id,
 
16
                 "constructor calls parent with the correct control");
 
17
            t.eq(call, callbacks,
 
18
                 "constructor calls parent with the correct callbacks");
 
19
            t.eq(opt, options,
 
20
                 "constructor calls parent with the correct options");
 
21
        }
 
22
        var handler = new OpenLayers.Handler.Polygon(control, callbacks, options);
 
23
 
 
24
        OpenLayers.Handler.prototype.initialize = oldInit;
 
25
    }
 
26
 
 
27
    function test_Handler_Polygon_activation(t) {
 
28
        t.plan(3);
 
29
        var map = new OpenLayers.Map('map');
 
30
        var control = new OpenLayers.Control();
 
31
        map.addControl(control);
 
32
        var handler = new OpenLayers.Handler.Polygon(control);
 
33
        handler.active = true;
 
34
        var activated = handler.activate();
 
35
        t.ok(!activated,
 
36
             "activate returns false if the handler was already active");
 
37
        handler.active = false;
 
38
        activated = handler.activate();
 
39
        t.ok(activated,
 
40
             "activate returns true if the handler was not already active");
 
41
        activated = handler.deactivate();
 
42
        t.ok(activated,
 
43
             "deactivate returns true if the handler was active already");
 
44
        map.destroy();     
 
45
    }
 
46
 
 
47
    function test_Handler_Polygon_bounds(t) {
 
48
        t.plan(2);
 
49
        var map = new OpenLayers.Map('map');
 
50
        map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
 
51
        map.zoomToMaxExtent();
 
52
        var control = new OpenLayers.Control();
 
53
        map.addControl(control);
 
54
        var handler = new OpenLayers.Handler.Polygon(control, {});
 
55
        var activated = handler.activate();
 
56
 
 
57
        var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
 
58
        handler.mousedown(evt);
 
59
        handler.mouseup(evt);
 
60
        var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
 
61
        handler.mousemove(evt);
 
62
        handler.mousedown(evt);
 
63
        handler.mouseup(evt);
 
64
        t.ok(handler.line.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)), "Correct bounds");
 
65
        var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
 
66
        handler.mousedown(evt);
 
67
        var evt = {xy: new OpenLayers.Pixel(125, 100), which: 1};
 
68
        handler.mousemove(evt);
 
69
        t.ok(!handler.polygon.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)),
 
70
             "Correct bounds after dragging without letting go. (Came out as "+handler.line.geometry.getBounds().toBBOX() + ".)");
 
71
        map.destroy();     
 
72
    }
 
73
 
 
74
    function test_Handler_Polygon_destroy(t) {
 
75
        t.plan(8);
 
76
        var map = new OpenLayers.Map('map');
 
77
        map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
 
78
        map.zoomToMaxExtent();
 
79
        var control = new OpenLayers.Control();
 
80
        map.addControl(control);
 
81
        var handler = new OpenLayers.Handler.Polygon(control, {foo: 'bar'});
 
82
 
 
83
        handler.activate();
 
84
        var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
 
85
        handler.mousedown(evt);
 
86
 
 
87
        t.ok(handler.layer,
 
88
             "handler has a layer prior to destroy");
 
89
        t.ok(handler.point,
 
90
             "handler has a point prior to destroy");
 
91
        t.ok(handler.line,
 
92
             "handler has a line prior to destroy");
 
93
        t.ok(handler.polygon,
 
94
             "handler has a polygon prior to destroy");
 
95
        handler.destroy();
 
96
        t.eq(handler.layer, null,
 
97
             "handler.layer is null after destroy");
 
98
        t.eq(handler.point, null,
 
99
             "handler.point is null after destroy");
 
100
        t.eq(handler.line, null,
 
101
             "handler.line is null after destroy");
 
102
        t.eq(handler.polygon, null,
 
103
             "handler.polygon is null after destroy");
 
104
        map.destroy();     
 
105
    }
 
106
 
 
107
 
 
108
 
 
109
  </script>
 
110
</head>
 
111
<body>
 
112
    <div id="map" style="width: 300px; height: 150px;"/>
 
113
</body>
 
114
</html>