3
<script src="../../lib/OpenLayers.js"></script>
4
<script type="text/javascript">
5
function test_Handler_Polygon_constructor(t) {
7
var control = new OpenLayers.Control();
8
control.id = Math.random();
9
var callbacks = {foo: "bar"};
10
var options = {bar: "foo"};
12
var oldInit = OpenLayers.Handler.prototype.initialize;
14
OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
15
t.eq(con.id, control.id,
16
"constructor calls parent with the correct control");
18
"constructor calls parent with the correct callbacks");
20
"constructor calls parent with the correct options");
22
var handler = new OpenLayers.Handler.Polygon(control, callbacks, options);
24
OpenLayers.Handler.prototype.initialize = oldInit;
27
function test_Handler_Polygon_activation(t) {
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();
36
"activate returns false if the handler was already active");
37
handler.active = false;
38
activated = handler.activate();
40
"activate returns true if the handler was not already active");
41
activated = handler.deactivate();
43
"deactivate returns true if the handler was active already");
47
function test_Handler_Polygon_bounds(t) {
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();
57
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
58
handler.mousedown(evt);
60
var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
61
handler.mousemove(evt);
62
handler.mousedown(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() + ".)");
74
function test_Handler_Polygon_destroy(t) {
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'});
84
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
85
handler.mousedown(evt);
88
"handler has a layer prior to destroy");
90
"handler has a point prior to destroy");
92
"handler has a line prior to destroy");
94
"handler has a polygon prior to 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");
112
<div id="map" style="width: 300px; height: 150px;"/>