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
130
131
132
133
134
|
<html>
<head>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
function test_constructor(t) {
t.plan(2);
var control = new OpenLayers.Control.PinchZoom();
t.ok(control instanceof OpenLayers.Control.PinchZoom, "got an instance");
t.ok(control.handler instanceof OpenLayers.Handler.Pinch, "control has pinch handler");
control.destroy();
}
function test_destroy(t) {
t.plan(1);
var control = new OpenLayers.Control.PinchZoom();
control.destroy();
t.ok(!control.handler, "handler destroyed");
}
function test_activate(t) {
t.plan(3);
var control = new OpenLayers.Control.PinchZoom();
t.ok(!control.active, "control not activated after construction");
var map = new OpenLayers.Map({
div: "map",
controls: [control]
});
t.ok(control.active, "control activated after being added to the map");
control.deactivate();
t.ok(!control.active, "control deactivated");
map.destroy();
}
function test_pinchMove(t) {
var control = new OpenLayers.Control.PinchZoom();
var map = new OpenLayers.Map({
div: "map",
controls: [control]
});
var log = [];
map.applyTransform = function(x, y, scale) {
log.push([x, y, scale]);
}
map.layerContainerOriginPx = {
x: -50, y: -50
};
control.pinchOrigin = {
x: 100, y: 50
};
var cases = [
{x: 100, y: 60, scale: 1, transform: [-50, -40, 1]},
{x: 150, y: 60, scale: 1, transform: [0, -40, 1]},
{x: 150, y: 60, scale: 2, transform: [-150, -140, 2]},
{x: 50, y: 20, scale: 2.5, transform: [-325, -230, 2.5]},
{x: 150, y: 60, scale: 2, transform: [-150, -140, 2]},
{x: 50, y: 20, scale: 0.25, transform: [13, -5, 0.25]}
];
var len = cases.length;
t.plan(len*2);
var c;
for (var i=0; i<len; ++i) {
c = cases[i];
control.pinchMove({xy: {x: c.x, y: c.y}}, {scale: c.scale});
t.eq(log.length, i+1, i + " called once");
t.eq(log[i], c.transform, i + " correct transform");
}
}
function test_pinchMove_preservecenter(t) {
var control = new OpenLayers.Control.PinchZoom({
preserveCenter: true
});
var map = new OpenLayers.Map({
div: "map",
controls: [control],
layers: [new OpenLayers.Layer('fake', {isBaseLayer: true})]
});
map.zoomToMaxExtent();
var centerPx = map.getPixelFromLonLat(map.getCenter());
control.pinchStart = function(evt, pinchData) {
t.eq(map.layerContainerOriginPx, {x: 0, y: 0}, "center preserved");
t.eq(map.getPixelFromLonLat(map.getCenter()), centerPx, "center preserved");
}
control.pinchStart(null);
var log = [];
map.applyTransform = function(x, y, scale) {
log.push([x, y, scale]);
}
control.pinchOrigin = map.getPixelFromLonLat(map.getCenter());
var cases = [
{scale: 1, transform: [0, 0, 1]},
{scale: 2, transform: [-128, -128, 2]},
{scale: 2.5, transform: [-192, -192, 2.5]},
{scale: 0.25, transform: [96, 96, 0.25]}
];
var len = cases.length;
t.plan(2 + len*2);
var c;
for (var i=0; i<len; ++i) {
c = cases[i];
control.pinchMove(null, {scale: c.scale});
t.eq(log.length, i+1, i + " called once");
t.eq(log[i], c.transform, i + " correct transform");
}
}
</script>
</head>
<body>
<div id="map" style="width: 256px; height: 256px;"></div>
</body>
</html>
|