summaryrefslogtreecommitdiff
path: root/misc/openlayers/tests/Control/TransformFeature.html
blob: 3279867876f746f48a6cebdea5cddf510569489c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<html>
<head>
    <script src="../OLLoader.js"></script>
    <script type="text/javascript">

    function test_initialize(t) {
        t.plan(6);
        var layer = "foo";
        var control = new OpenLayers.Control.TransformFeature(layer);
        
        t.ok(control.layer == layer,
             "constructor sets layer correctly");
        t.ok(control.dragControl instanceof OpenLayers.Control.DragFeature,
             "constructor sets the drag control correctly");
        t.ok(control.box instanceof OpenLayers.Feature.Vector,
             "box feature created");
        t.eq(control.handles.length, 8, "8 handles created");
        t.eq(control.rotationHandles.length, 4, "4 rotation handles created")
        t.eq(typeof control.rotationHandleSymbolizer, "object",
            "rotationHandleSymbolizer initialized");
        control.destroy();
    }

    function test_destroy(t) {
        t.plan(1);
        var map = new OpenLayers.Map("map");
        var layer = new OpenLayers.Layer.Vector();
        map.addLayer(layer);
        var control = new OpenLayers.Control.TransformFeature(layer);
        control.dragControl.destroy = function() {
            t.ok(true,
                 "control.destroy calls destroy on drag control");
        };
        control.destroy();
        map.destroy();
    }
    
    function test_activate(t) {
        t.plan(3);
        var map = new OpenLayers.Map("map");
        var layer = new OpenLayers.Layer.Vector();
        map.addLayer(layer);
        var control = new OpenLayers.Control.TransformFeature(layer);
        map.addControl(control);
        
        t.ok(!control.dragControl.active,
             "drag control is not active prior to activating control");
        control.activate();
        t.ok(control.dragControl.active,
             "drag control is active after activating control");
        t.ok(control.box.layer === layer, "box added to layer");

        map.destroy();
    }
    
    function test_setFeature(t) {
        t.plan(6);
        var map = new OpenLayers.Map("map", {allOverlays: true});
        var layer = new OpenLayers.Layer.Vector();
        var feature = new OpenLayers.Feature.Vector(
            OpenLayers.Geometry.fromWKT("POLYGON((-1 -1, 1 -1, 1 1, -1 1))"));
        layer.addFeatures([feature]);
        map.addLayer(layer);
        map.setCenter(new OpenLayers.LonLat(0, 0), 18);
        var control = new OpenLayers.Control.TransformFeature(layer);
        map.addControl(control);
        var log = [];
        control.events.on({
            "beforesetfeature": function(e) { log.push(e); },
            "setfeature": function(e) { log.push(e); }
        });
        control.setFeature(feature);
        
        t.eq(log[0].type, "beforesetfeature", "beforesetfeature event fired with correct event type");
        t.eq(log[1].type, "setfeature", "setfeature event fired with correct event type");
        
        t.ok(control.active, "control activated on setFeature");
        t.ok(feature.geometry.getBounds().equals(control.box.geometry.getBounds()), "box positioned correctly");
        t.geom_eq(control.handles[0].geometry, control.box.geometry.components[0], "handle positioned with box");
        
        var center = new OpenLayers.LonLat(1, 1);
        control.box.move(center);
        t.geom_eq(control.handles[0].geometry, control.box.geometry.components[0], "handle moved with box");
    }
    
    function test_handleMove(t) {
        t.plan(16);
        var map = new OpenLayers.Map("map", {allOverlays: true});
        var layer = new OpenLayers.Layer.Vector();
        var feature = new OpenLayers.Feature.Vector(
            OpenLayers.Geometry.fromWKT("POLYGON((-1 -1, 1 -1, 1 1, -1 1))"));
        layer.addFeatures([feature]);
        map.addLayer(layer);
        map.setCenter(new OpenLayers.LonLat(0, 0), 18);
        var control = new OpenLayers.Control.TransformFeature(layer);
        map.addControl(control);
        control.setFeature(feature);
        
        var bottomLeft = new OpenLayers.LonLat(-2, -2);
        control.handles[0].move(bottomLeft);
        t.geom_eq(control.handles[0].geometry, new OpenLayers.Geometry.Point(-2, -2), "bottom left handle at -2,-2");
        t.geom_eq(control.handles[1].geometry, new OpenLayers.Geometry.Point(0, -2), "bottom handle at 0,-2");
        t.geom_eq(control.handles[2].geometry, new OpenLayers.Geometry.Point(2, -2), "bottom right handle at 2,-2");
        t.geom_eq(control.handles[3].geometry, new OpenLayers.Geometry.Point(2, 0), "right handle at 2,0");
        t.geom_eq(control.handles[4].geometry, new OpenLayers.Geometry.Point(2, 2), "top right handle at 2,2");
        t.geom_eq(control.handles[5].geometry, new OpenLayers.Geometry.Point(0, 2), "top handle at 0,2");
        t.geom_eq(control.handles[6].geometry, new OpenLayers.Geometry.Point(-2, 2), "top left handle at -2,2");
        t.geom_eq(control.handles[7].geometry, new OpenLayers.Geometry.Point(-2, 0), "left handle at -2,0");
        
        control.irregular = true;
        
        var bottomLeft = new OpenLayers.LonLat(-3, -3);
        control.handles[0].move(bottomLeft);
        t.geom_eq(control.handles[0].geometry, new OpenLayers.Geometry.Point(-3, -3), "bottom left handle at -3,-3");
        t.geom_eq(control.handles[1].geometry, new OpenLayers.Geometry.Point(-0.5, -3), "bottom handle at 0,-3");
        t.geom_eq(control.handles[2].geometry, new OpenLayers.Geometry.Point(2, -3), "bottom right handle at 2,-3");
        t.geom_eq(control.handles[3].geometry, new OpenLayers.Geometry.Point(2, -0.5), "right handle at 2,0");
        t.geom_eq(control.handles[4].geometry, new OpenLayers.Geometry.Point(2, 2), "top right handle at 2,2");
        t.geom_eq(control.handles[5].geometry, new OpenLayers.Geometry.Point(-0.5, 2), "top handle at 0,2");
        t.geom_eq(control.handles[6].geometry, new OpenLayers.Geometry.Point(-3, 2), "top left handle at -3,2");
        t.geom_eq(control.handles[7].geometry, new OpenLayers.Geometry.Point(-3, -0.5), "left handle at -3,0");
    }

    </script>
</head>
<body>
    <div id="map" style="width: 400px; height: 250px;"/>
</body>
</html>