1 | <html> |
---|
2 | <head> |
---|
3 | <script src="../OLLoader.js"></script> |
---|
4 | <script type="text/javascript"> |
---|
5 | var map, control, layer; |
---|
6 | |
---|
7 | function init_map() { |
---|
8 | control = new OpenLayers.Control.DragPan(); |
---|
9 | map = new OpenLayers.Map("map", {controls:[control]}); |
---|
10 | layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", |
---|
11 | "http://labs.metacarta.com/wms/vmap0", |
---|
12 | {layers: 'basic'} ); |
---|
13 | map.addLayer(layer); |
---|
14 | map.zoomToMaxExtent(); |
---|
15 | map.zoomIn(); |
---|
16 | control.activate(); |
---|
17 | return [map, control]; |
---|
18 | } |
---|
19 | function test_Control_DragPan_constructor (t) { |
---|
20 | t.plan( 1 ); |
---|
21 | |
---|
22 | control = new OpenLayers.Control.DragPan(); |
---|
23 | t.ok( control instanceof OpenLayers.Control.DragPan, "new OpenLayers.Control returns object" ); |
---|
24 | } |
---|
25 | function test_Control_DragPan_drag (t) { |
---|
26 | t.plan(4); |
---|
27 | var data = init_map(); |
---|
28 | map = data[0]; control = data[1]; |
---|
29 | res = map.baseLayer.resolutions[map.getZoom()]; |
---|
30 | t.eq(map.center.lat, 0, "Lat is 0 before drag"); |
---|
31 | t.eq(map.center.lon, 0, "Lon is 0 before drag"); |
---|
32 | map.events.triggerEvent('mousedown', {'type':'mousedown', 'xy':new OpenLayers.Pixel(0,0), 'which':1}); |
---|
33 | map.events.triggerEvent('mousemove', {'type':'mousemove', 'xy':new OpenLayers.Pixel(5,5), 'which':1}); |
---|
34 | map.events.triggerEvent('mouseup', {'type':'mouseup', 'xy':new OpenLayers.Pixel(5,5), 'which':1}); |
---|
35 | |
---|
36 | t.eq(map.getCenter().lat, res * 5, "Lat is " + (res * 5) + " after drag"); |
---|
37 | t.eq(map.getCenter().lon, res * -5, "Lon is " + (res * -5) + " after drag"); |
---|
38 | } |
---|
39 | function test_Control_DragPan_drag_documentDrag (t) { |
---|
40 | t.plan(4); |
---|
41 | control = new OpenLayers.Control.DragPan({documentDrag: true}); |
---|
42 | map = new OpenLayers.Map("map", {controls:[control]}); |
---|
43 | layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", |
---|
44 | "http://labs.metacarta.com/wms/vmap0", |
---|
45 | {layers: 'basic'} ); |
---|
46 | map.addLayer(layer); |
---|
47 | map.zoomToMaxExtent(); |
---|
48 | map.zoomIn(); |
---|
49 | control.activate(); |
---|
50 | |
---|
51 | res = map.baseLayer.resolutions[map.getZoom()]; |
---|
52 | t.eq(map.center.lat, 0, "Lat is 0 before drag"); |
---|
53 | t.eq(map.center.lon, 0, "Lon is 0 before drag"); |
---|
54 | map.events.triggerEvent('mousedown', {'type':'mousedown', 'xy':new OpenLayers.Pixel(0,0), 'which':1}); |
---|
55 | map.events.triggerEvent('mousemove', {'type':'mousemove', 'xy':new OpenLayers.Pixel(5,5), 'which':1}); |
---|
56 | map.events.triggerEvent('mouseup', {'type':'mouseup', 'xy':new OpenLayers.Pixel(5,5), 'which':1}); |
---|
57 | |
---|
58 | t.eq(map.getCenter().lat, res * 5, "Lat is " + (res * 5) + " after drag"); |
---|
59 | t.eq(map.getCenter().lon, res * -5, "Lon is " + (res * -5) + " after drag"); |
---|
60 | } |
---|
61 | function test_Control_DragPan_click(t) { |
---|
62 | t.plan(1); |
---|
63 | var control = new OpenLayers.Control.DragPan(); |
---|
64 | var map = new OpenLayers.Map("map", {controls:[control]}); |
---|
65 | var layer = new OpenLayers.Layer.WMS("OpenLayers WMS", |
---|
66 | "http://labs.metacarta.com/wms/vmap0", |
---|
67 | {layers: 'basic'}); |
---|
68 | map.addLayer(layer); |
---|
69 | map.zoomToMaxExtent(); |
---|
70 | map.zoomIn(); |
---|
71 | control.activate(); |
---|
72 | map.setCenter = function() { |
---|
73 | t.ok(false, "map.setCenter should not be called here"); |
---|
74 | }; |
---|
75 | var xy = new OpenLayers.Pixel(0, 0); |
---|
76 | var down = { |
---|
77 | 'type': 'mousedown', |
---|
78 | 'xy': xy, |
---|
79 | 'which': 1 |
---|
80 | }; |
---|
81 | var move = { |
---|
82 | 'type': 'mousemove', |
---|
83 | 'xy': xy, |
---|
84 | 'which': 1 |
---|
85 | }; |
---|
86 | var up = { |
---|
87 | 'type': 'mouseup', |
---|
88 | 'xy': xy, |
---|
89 | 'which': 1 |
---|
90 | }; |
---|
91 | map.events.triggerEvent('mousedown', down); |
---|
92 | map.events.triggerEvent('mousemove', move); |
---|
93 | map.events.triggerEvent('mouseup', up); |
---|
94 | t.ok(true, "clicking without moving the mouse does not call setCenter"); |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | </script> |
---|
99 | </head> |
---|
100 | <body> |
---|
101 | <a id="scale" href="">DragPan</a> <br /> |
---|
102 | <div id="map" style="width: 1024px; height: 512px;"/> |
---|
103 | </body> |
---|
104 | </html> |
---|