Ticket #666: handler_bounds.patch
| File handler_bounds.patch, 7.6 kB (added by crschmidt, 1 year ago) |
|---|
-
tests/Handler/test_Point.html
old new 1 <html> 2 <head> 3 <script src="../../lib/OpenLayers.js"></script> 4 <script type="text/javascript"><!-- 5 function test_Handler_Point_constructor(t) { 6 t.plan(3); 7 var control = new OpenLayers.Control(); 8 control.id = Math.random(); 9 var callbacks = {foo: "bar"}; 10 var options = {bar: "foo"}; 11 12 var oldInit = OpenLayers.Handler.prototype.initialize; 13 14 OpenLayers.Handler.prototype.initialize = function(con, call, opt) { 15 t.eq(con.id, control.id, 16 "constructor calls parent with the correct control"); 17 t.eq(call, callbacks, 18 "constructor calls parent with the correct callbacks"); 19 t.eq(opt, options, 20 "constructor calls parent with the correct options"); 21 } 22 var handler = new OpenLayers.Handler.Point(control, callbacks, options); 23 24 OpenLayers.Handler.prototype.initialize = oldInit; 25 } 26 27 function test_Handler_Point_activation(t) { 28 t.plan(3); 29 var map = new OpenLayers.Map('map'); 30 var control = new OpenLayers.Control(); 31 map.addControl(control); 32 var handler = new OpenLayers.Handler.Point(control); 33 handler.active = true; 34 var activated = handler.activate(); 35 t.ok(!activated, 36 "activate returns false if the handler was already active"); 37 handler.active = false; 38 activated = handler.activate(); 39 t.ok(activated, 40 "activate returns true if the handler was not already active"); 41 activated = handler.deactivate(); 42 t.ok(activated, 43 "deactivate returns true if the handler was active already"); 44 } 45 46 function test_Handler_Point_bounds(t) { 47 var map = new OpenLayers.Map('map'); 48 map.addLayer(new OpenLayers.Layer.WMS("", "", {})); 49 map.zoomToMaxExtent(); 50 var control = new OpenLayers.Control(); 51 map.addControl(control); 52 var handler = new OpenLayers.Handler.Point(control); 53 var activated = handler.activate(); 54 var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1}; 55 handler.mousedown(evt); 56 console.log(handler.point); 57 t.eq(handler.point.geometry.x, 0, "X is correct"); 58 t.eq(handler.point.geometry.y, 0, "Y is correct"); 59 t.ok(handler.point.geometry.getBounds().equals(new OpenLayers.Bounds(0,0,0,0)), "Correct bounds"); 60 var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1}; 61 handler.mousemove(evt); 62 t.ok(!handler.point.geometry.getBounds().equals(new OpenLayers.Bounds(0,0,0,0)), "Bounds changed after moving mouse"); 63 } 64 65 66 67 // --> 68 </script> 69 </head> 70 <body> 71 <div id="map" style="width: 300px; height: 150px;"/> 72 </body> 73 </html> -
tests/Handler/test_Path.html
old new 1 <html> 2 <head> 3 <script src="../../lib/OpenLayers.js"></script> 4 <script type="text/javascript"><!-- 5 function test_Handler_Path_constructor(t) { 6 t.plan(3); 7 var control = new OpenLayers.Control(); 8 control.id = Math.random(); 9 var callbacks = {foo: "bar"}; 10 var options = {bar: "foo"}; 11 12 var oldInit = OpenLayers.Handler.prototype.initialize; 13 14 OpenLayers.Handler.prototype.initialize = function(con, call, opt) { 15 t.eq(con.id, control.id, 16 "constructor calls parent with the correct control"); 17 t.eq(call, callbacks, 18 "constructor calls parent with the correct callbacks"); 19 t.eq(opt, options, 20 "constructor calls parent with the correct options"); 21 } 22 var handler = new OpenLayers.Handler.Path(control, callbacks, options); 23 24 OpenLayers.Handler.prototype.initialize = oldInit; 25 } 26 27 function test_Handler_Path_activation(t) { 28 t.plan(3); 29 var map = new OpenLayers.Map('map'); 30 var control = new OpenLayers.Control(); 31 map.addControl(control); 32 var handler = new OpenLayers.Handler.Path(control); 33 handler.active = true; 34 var activated = handler.activate(); 35 t.ok(!activated, 36 "activate returns false if the handler was already active"); 37 handler.active = false; 38 activated = handler.activate(); 39 t.ok(activated, 40 "activate returns true if the handler was not already active"); 41 activated = handler.deactivate(); 42 t.ok(activated, 43 "deactivate returns true if the handler was active already"); 44 } 45 46 function test_Handler_Path_bounds(t) { 47 var map = new OpenLayers.Map('map'); 48 map.addLayer(new OpenLayers.Layer.WMS("", "", {})); 49 map.zoomToMaxExtent(); 50 var control = new OpenLayers.Control(); 51 map.addControl(control); 52 var handler = new OpenLayers.Handler.Path(control, {}); 53 var activated = handler.activate(); 54 var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1}; 55 handler.mousedown(evt); 56 handler.mouseup(evt); 57 var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1}; 58 handler.mousedown(evt); 59 handler.mouseup(evt); 60 t.ok(handler.line.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)), "Correct bounds"); 61 var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1}; 62 handler.mousedown(evt); 63 var evt = {xy: new OpenLayers.Pixel(125, 100), which: 1}; 64 handler.mousemove(evt); 65 t.ok(!handler.line.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)), "Correct bounds after dragging without letting go. (Came out as "+handler.line.geometry.getBounds().toBBOX() + ".)"); 66 } 67 68 69 70 // --> 71 </script> 72 </head> 73 <body> 74 <div id="map" style="width: 300px; height: 150px;"/> 75 </body> 76 </html> -
tests/list-tests.html
old new 73 73 <li>Control/test_Scale.html</li> 74 74 <li>test_Handler.html</li> 75 75 <li>Handler/test_Drag.html</li> 76 <li>Handler/test_Point.html</li> 77 <li>Handler/test_Path.html</li> 76 78 <li>test_Map.html</li> 77 79 </ul> -
lib/OpenLayers/Handler/Point.js
old new 236 236 var lonlat = this.map.getLonLatFromPixel(evt.xy); 237 237 this.point.geometry.x = lonlat.lon; 238 238 this.point.geometry.y = lonlat.lat; 239 this.point.geometry.clearBounds(); 239 240 this.drawFeature(); 240 241 } 241 242 return true; -
lib/OpenLayers/Handler/Path.js
old new 112 112 var index = this.line.geometry.components.length - 1; 113 113 this.line.geometry.components[index].x = this.point.geometry.x; 114 114 this.line.geometry.components[index].y = this.point.geometry.y; 115 this.line.geometry.components[index].clearBounds(); 115 116 }, 116 117 117 118 /**
