3 <script src="../../lib/OpenLayers.js"></script>
4 <script type="text/javascript">
5 var map, control, layer;
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",
14 map.zoomToMaxExtent();
17 return [map, control];
19 function test_Control_DragPan_constructor (t) {
22 control = new OpenLayers.Control.DragPan();
23 t.ok( control instanceof OpenLayers.Control.DragPan, "new OpenLayers.Control returns object" );
25 function test_Control_DragPan_drag (t) {
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});
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");
39 function test_Control_DragPan_click(t) {
41 var control = new OpenLayers.Control.DragPan();
42 var map = new OpenLayers.Map("map", {controls:[control]});
43 var layer = new OpenLayers.Layer.WMS("OpenLayers WMS",
44 "http://labs.metacarta.com/wms/vmap0",
47 map.zoomToMaxExtent();
50 map.setCenter = function() {
51 t.ok(false, "map.setCenter should not be called here");
53 var xy = new OpenLayers.Pixel(0, 0);
69 map.events.triggerEvent('mousedown', down);
70 map.events.triggerEvent('mousemove', move);
71 map.events.triggerEvent('mouseup', up);
72 t.ok(true, "clicking without moving the mouse does not call setCenter");
79 <a id="scale" href="">DragPan</a> <br />
80 <div id="map" style="width: 1024px; height: 512px;"/>